-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
59 lines (45 loc) · 1.53 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from tweepy import OAuthHandler
from tweepy import Stream
import sys
# Import twitter keys and tokens
from my_config import consumer_key
from my_config import consumer_secret
from my_config import access_token
from my_config import access_token_secret
from tools.tweet_listener import TweetStreamListener
def main():
"""Pipelines"""
topics = []
if len(sys.argv) == 1:
# Default topics
topics = ['#covid', '#corona', '#SARS','#vaccination','#Pfizer',
'covid', 'corona', 'SARS','vaccination','Pfizer']
else:
for topic in sys.argv[1:]:
topics.append(topic)
#user input can be replaced with file input
index = "covid-analysis-elk"
doc_type = "new-tweet"
print("==> Topics", topics)
print("==> Index: {}, doc type: {}".format(index, doc_type))
print("==> Start retrieving tweets...")
# Create instance of the tweepy tweet stream listener
listener = TweetStreamListener(
index,
doc_type)
# Set twitter keys/tokens
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
# Set the program to restart automatically in case of errors
while True:
try:
stream = Stream(auth, listener)
stream.filter(track=topics)
except KeyboardInterrupt:
stream.disconnect()
print("==> Stop")
break
except:
continue
if __name__ == '__main__':
main()