-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMartinsCode.py
More file actions
42 lines (29 loc) · 1.11 KB
/
MartinsCode.py
File metadata and controls
42 lines (29 loc) · 1.11 KB
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
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import time
import io
import os
import json
# twitter OAuth
ckey = 'szIul7ZRYlIoYB3Vp5kyyj42u'
consumer_secret = 'MG18KBN61TY5adittIJRweMzsjxnhspXSKmhMZuMGweYqlheUR'
access_token_key = '867428375383728129-cmzkW7Y66ioJcWhOt420O1MBiyWygVU'
access_token_secret = 'tAdBBmW16j2nTwBMMPT8ZlgqGUmgzR9SRtwbDRkUDiXZL'
#Listener Class Override
class listener(StreamListener):
def on_data(self, data):
print(data)
tweet_data.append(data)
def on_error(self, status):
print (status)
def on_disconnect(self, notice):
print ('bye')
#Beginning of the specific code
keyword_list = ['Theresa'] #track list
auth = OAuthHandler(ckey, consumer_secret) #OAuth object
auth.set_access_token(access_token_key, access_token_secret)
saveFile = io.open('raw_tweets.json', 'w', encoding='utf-8')
tweet_data = []
twitterStream = Stream(auth, listener()) #initialize Stream object with a time out limit
twitterStream.filter(track=keyword_list, languages=['en']) #call the filter method to run the Stream Listener