-
Notifications
You must be signed in to change notification settings - Fork 3
/
environment-tweet-charts.py
127 lines (116 loc) · 2.73 KB
/
environment-tweet-charts.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# pip install psycopg2
import json
import psycopg2
# postgresql
conn = psycopg2.connect("dbname='tweetreplies'")
cur = conn.cursor()
envirowords = [
'temperature',
'cooling',
'disasters',
'weather',
'natural',
'warming',
'flooding',
'nasa',
'extinction',
'greenhouse',
'emissions',
'snow',
'catastrophic',
'paris accord',
'climate',
'climatechange',
'floods',
'disaster',
'rain',
'predictions',
'sun',
'scientific',
'flood',
'epidemic',
'burning',
'atmosphere',
'worldwide',
'hurricanes',
'methane',
'cycle',
'fires',
'melting',
'sea',
'winter',
'oceans',
'effects',
'pollution',
'science',
'carbon',
'green new deal',
'gnd'
]
badwords = [
'clown',
'bigot',
'asshole',
'loser',
'phony',
'villain',
'commie',
'narcissist',
'actor',
'crook',
'moron',
'hypocrite',
'liar',
'spoiled',
'actress',
'dictator',
'traitor',
'disgrace',
'annoying',
'jerk',
'lunatic',
'dumbass',
'puppet',
'embarrassment',
'fascist',
'elitist'
]
tstamps = []
cur.execute('SELECT timestamp FROM combined WHERE LOWER(body) LIKE \'%'
+ '%\' OR LOWER(body) LIKE \'%'.join(envirowords)
+ '%\' ORDER BY timestamp')
for row in cur.fetchall():
tstamps.append(int(row[0]))
#print(tstamps)
opt = open('visualize-green/all-environment.json', 'w')
opt.write(json.dumps(tstamps))
tstamps2 = []
bysource = {}
badbysource = {}
cur.execute('SELECT origintime, originid FROM origins \
WHERE originsn = \'AOC\' AND LOWER(originbody) LIKE \'%'
+ '%\' OR LOWER(originbody) LIKE \'%'.join(envirowords)
+ '%\' ORDER BY originid')
for row in cur.fetchall():
tstamps2.append(row[0])
bysource[int(row[1])] = []
badbysource[int(row[1])] = []
opt = open('visualize-green/origin-environment.json', 'w')
opt.write(json.dumps(tstamps2))
for sourceTweet in bysource.keys():
cur.execute('SELECT timestamp FROM combined \
WHERE originid = \'' + str(sourceTweet) + '\' \
AND (LOWER(body) LIKE \'%'
+ '%\' OR LOWER(body) LIKE \'%'.join(envirowords)
+ '%\') ORDER BY timestamp')
for row in cur.fetchall():
bysource[sourceTweet].append(int(row[0]))
cur.execute('SELECT timestamp FROM combined \
WHERE originid = \'' + str(sourceTweet) + '\' \
AND (LOWER(body) LIKE \'%'
+ '%\' OR LOWER(body) LIKE \'%'.join(badwords)
+ '%\') ORDER BY timestamp')
for row in cur.fetchall():
badbysource[sourceTweet].append(int(row[0]))
opt = open('visualize-green/replies-by-tstamp.json', 'w')
opt.write(json.dumps({ "green": bysource, "bad": badbysource }))