-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetweets.py
89 lines (84 loc) · 3.51 KB
/
getweets.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import csv
import twitter
api = twitter.Api(
consumer_key='',
consumer_secret='',
access_token_key='',
access_token_secret='')
hashtags_to_track = [
"@jimmyjairala",
"@cedeno_marth",
"@jorgevillacrese",
"@CynthiaViteri6",
"@GinoCornejoM",
"@BermudezBronson",
"@balerioestacio",
"@cgcassanello",
"@inca_jose",
"@EduardoArgudoG",
"@fcojimenez21",
"@patobuendia23",
"@jaimelomas74",
"@Simon_BolivarEC",
"@edgarsalazar_51",
"@jaimenebotsaadi"
]
stream = api.GetStreamFilter(track=hashtags_to_track)
with open('tweets.csv', 'a+') as csv_file:
csv_writer = csv.writer(csv_file)
for line in stream:
# Signal that the line represents a tweet
tweet = twitter.Status.NewFromJsonDict(line)
print(tweet.id)
jimmyjairala = cedeno_marth = jorgevillacrese = CynthiaViteri6 = GinoCornejoM = BermudezBronson = balerioestacio = inca_jose = EduardoArgudoG = fcojimenez21 = patobuendia23 = jaimelomas74 = Simon_BolivarEC = edgarsalazar_51 = jaimenebotsaadi = False
for user in tweet.user_mentions:
if user.screen_name.lower() == 'jimmyjairala':
jimmyjairala = True
if user.screen_name.lower() == 'cedeno_marth':
cedeno_marth = True
if user.screen_name.lower() == 'jorgevillacrese':
jorgevillacrese = True
if user.screen_name.lower() == 'cynthiaviteri6':
CynthiaViteri6 = True
if user.screen_name.lower() == 'ginocornejom':
GinoCornejoM = True
if user.screen_name.lower() == 'bermudezbronson':
BermudezBronson = True
if user.screen_name.lower() == 'balerioestacio':
balerioestacio = True
if user.screen_name.lower() == 'inca_jose':
inca_jose = True
if user.screen_name.lower() == 'eduardoargudog':
EduardoArgudoG = True
if user.screen_name.lower() == 'fcojimenez21':
fcojimenez21 = True
if user.screen_name.lower() == 'patobuendia23':
patobuendia23 = True
if user.screen_name.lower() == 'jaimelomas74':
jaimelomas74 = True
if user.screen_name.lower() == 'simon_bolivarec':
Simon_BolivarEC = True
if user.screen_name.lower() == 'edgarsalazar_51':
edgarsalazar_51 = True
if user.screen_name.lower() == 'jaimenebotsaadi':
jaimenebotsaadi = True
if(tweet.hashtags):
hashtags = ' '.join(list(map(lambda x: x.text, tweet.hashtags)))
else:
hashtags = ''
if(tweet.truncated):
text = tweet.full_text
else:
text = tweet.text
if(tweet.in_reply_to_status_id):
replay = True
else:
replay = False
row = [tweet.id, tweet.created_at, tweet.user.screen_name, tweet.user.name,
tweet.user.created_at, tweet.user.followers_count, tweet.user.friends_count, tweet.user.statuses_count,
tweet.user.geo_enabled, tweet.user.lang,
tweet.source, tweet.lang,
text, hashtags, replay,
jimmyjairala, cedeno_marth, jorgevillacrese, CynthiaViteri6, GinoCornejoM, BermudezBronson, balerioestacio, inca_jose, EduardoArgudoG, fcojimenez21, patobuendia23, jaimelomas74, Simon_BolivarEC, edgarsalazar_51, jaimenebotsaadi
]
csv_writer.writerow(row)