Repository navigation
Expand file tree
/
Copy pathrequest.py
More file actions
47 lines (37 loc) · 1.56 KB
/
Copy pathrequest.py
File metadata and controls
47 lines (37 loc) · 1.56 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
43
44
45
46
47
import tweepy,csv,time
ACCESS_TOKEN = '938493239853813762-tlImlRTGU6RraqmBQQQQ3K5klFmHwvG'
ACCESS_SECRET = 'Ga79wDf0YK9YtYc21XEfBH10L0wAttnDL5wQXVT7oNj1J'
CONSUMER_KEY = 'zHK9haWtcpGWHUq12fEMn3Fyw'
CONSUMER_SECRET = 'jIZj1D7jPfXPGSIQTTEGMPgXhIR7lEqyBXRUnudcgpvPDc2wzm'
auth = tweepy.OAuthHandler(CONSUMER_KEY,CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN,ACCESS_SECRET)
api = tweepy.API(auth)
public_tweets = api.home_timeline()
def unlabeled_datasets():
# Open/create a file to append data to
csvFile = open('tweets.csv', 'a')
#Use csv writer
csvWriter = csv.writer(csvFile)
for member in tweepy.Cursor(api.list_members, 'cspan', 'members-of-congress').items():
tweets = api.user_timeline(member.id,count=100)
time.sleep(0.1)
for tweet in tweets:
csvWriter.writerow([tweet.id_str,tweet.user.id, tweet.text.encode('utf-8')])
csvFile.close()
def labeled_datasets():
csvFile = open('tweets3.csv', 'a')
csvWriter = csv.writer(csvFile)
for member in tweepy.Cursor(api.list_members, 'thedemocrats', 'house-democrats').items():
tweets = api.user_timeline(member.id,count=100)
time.sleep(0.1)
for tweet in tweets:
if ('RT @' not in tweet.text):
csvWriter.writerow([tweet.id_str,tweet.user.id, tweet.text.encode('utf-8'),1])
for member in tweepy.Cursor(api.list_members, 'housegop', 'house-republicans').items():
tweets = api.user_timeline(member.id,count=100)
time.sleep(0.1)
for tweet in tweets:
if ('RT @' not in tweet.text):
csvWriter.writerow([tweet.id_str,tweet.user.id, tweet.text.encode('utf-8'),-1])
csvFile.close()
labeled_datasets()