Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.

Commit e0f9e6d

Browse files
Added example of filtering by language in this example
1 parent 7b752a6 commit e0f9e6d

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

examples/streaming/track_users.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
# ----------------------------------------------------------------------
1818

19-
# This file demonstrates how to track mentions of a specific set of users and
20-
# archive those mentions to a local file. The output file will contain one
21-
# JSON string per line per Tweet.
19+
# This file demonstrates how to track mentions of a specific set of users in
20+
# english language and archive those mentions to a local file. The output
21+
# file will contain one JSON string per line per Tweet.
2222

2323
# To use this example, replace the W/X/Y/Zs with your keys obtained from
2424
# Twitter, or uncomment the lines for getting an environment variable. If you
@@ -52,6 +52,10 @@
5252
'@twitterapi',
5353
'@support']
5454

55+
# Languages to filter tweets by is a list. This will be joined by Twitter
56+
# to return data mentioning tweets only in the english language.
57+
LANGUAGES = ['en']
58+
5559
# Since we're going to be using a streaming endpoint, there is no need to worry
5660
# about rate limits.
5761
api = Api(CONSUMER_KEY,
@@ -64,7 +68,7 @@ def main():
6468
with open('output.txt', 'a') as f:
6569
# api.GetStreamFilter will return a generator that yields one status
6670
# message (i.e., Tweet) at a time as a JSON dictionary.
67-
for line in api.GetStreamFilter(track=USERS):
71+
for line in api.GetStreamFilter(track=USERS, languages=LANGUAGES):
6872
f.write(json.dumps(line))
6973
f.write('\n')
7074

0 commit comments

Comments
 (0)