Improve Stream.filter order and formatting
authorHarmon <Harmon758@gmail.com>
Sat, 23 Jan 2021 20:10:39 +0000 (14:10 -0600)
committerHarmon <Harmon758@gmail.com>
Sat, 23 Jan 2021 20:10:39 +0000 (14:10 -0600)
tweepy/streaming.py

index b35aa39c69edd042dea5d62b0f7098dbd0b48478..4274794c07c6e5917fa0dcd39c8bdd82bd7e8b33 100644 (file)
@@ -231,13 +231,15 @@ class Stream:
                              args=args, kwargs=kwargs, daemon=self.daemon)
         self.thread.start()
 
-    def filter(self, *, follow=None, track=None, threaded=False,
-               locations=None, stall_warnings=False, languages=None,
-               filter_level=None):
-        body = {}
+    def filter(self, *, follow=None, track=None, locations=None,
+               filter_level=None, languages=None, stall_warnings=False,
+               threaded=False):
         if self.running:
             raise TweepError('Stream object already connected!')
+
         endpoint = 'statuses/filter'
+
+        body = {}
         if follow:
             body['follow'] = ','.join(follow)
         if track:
@@ -247,12 +249,12 @@ class Stream:
                 raise TweepError("Wrong number of locations points, "
                                  "it has to be a multiple of 4")
             body['locations'] = ','.join([f'{l:.4f}' for l in locations])
-        if stall_warnings:
-            body['stall_warnings'] = stall_warnings
-        if languages:
-            body['language'] = ','.join(map(str, languages))
         if filter_level:
             body['filter_level'] = filter_level
+        if languages:
+            body['language'] = ','.join(map(str, languages))
+        if stall_warnings:
+            body['stall_warnings'] = stall_warnings
 
         if threaded:
             self._threaded_connect(endpoint, body=body)