Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
YStrano
GitHub Repository: YStrano/DataScience_GA
Path: blob/master/april_18/lessons/lesson-14/code/starter-code/capture-tweets.py
1905 views
1
from __future__ import print_function
2
import sys
3
4
import twitter
5
6
if __name__ == '__main__':
7
results = twitter.retrieve_tweets(topic=sys.args[1])
8
out = open('captured-tweets.txt', 'ab')
9
# The tweet is stored with key 'text',
10
i = 0
11
for result in results:
12
# Filter to english tweets
13
if result['lang'] == 'en':
14
out.write((result['text'] + "\n").encode('utf-8'))
15
i += 1
16
# Defaulting to capturing 5000, this takes a long time...
17
if i == 5000:
18
exit()
19