-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrap.py
39 lines (32 loc) · 1.12 KB
/
strap.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
"""
@Author: Hizaoui Mohamed Abdelkader
@Email-1: hizaoui.ma@gmail.com
"""
import sys
from tweepy import OAuthHandler
from tweepy import Stream
from utils.config import conf
from utils.get_twitter_stream import CustomStreamListener
from utils.print_parsed_stream import PrintParsedStream
if __name__ == '__main__':
try:
keywords = sys.argv[1]
keywords = [keyword.strip() for keyword in keywords.split(",")]
print("Listening on twitter for: %r" % keywords)
except IndexError:
print("ERROR:\nUSAGE: python strap.py \"keyword1, keyword2, keyword3, keyword4\" [path/to/config.yml]")
exit(1)
l = CustomStreamListener()
consumer_key = conf['consumer_key']
consumer_secret = conf['consumer_secret']
access_token = conf['access_token']
access_token_secret = conf['access_token_secret']
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
printer = PrintParsedStream()
try:
printer.run()
stream.filter(track=keywords)
except KeyboardInterrupt:
exit(0)