Skip to content

Commit 9b752ee

Browse files
author
Max
committed
Bug fixes post-webcast
1 parent 4544141 commit 9b752ee

File tree

2 files changed

+14
-34
lines changed

2 files changed

+14
-34
lines changed

webcast1/collect.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def connect():
2323
if api and api.verity_credentials():
2424
return api
2525
else:
26-
raise "Login failed."
26+
print("Login failed.")
27+
28+
2729

2830
query = '"someScreenName" OR "#sometag"' # a valid Twitter search query
2931

webcast1/webcast.py

+11-33
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ def add_or_inc_edge(g,f,t):
2929
g[f][t]['weight']+=1
3030
else:
3131
g.add_edge(f,t,weight=1)
32+
33+
def trim_edges(g, weight=1):
34+
"""
35+
Remove edges with weights less then a threshold parameter ("weight")
36+
"""
37+
g2=net.Graph()
38+
for f, to, edata in g.edges(data=True):
39+
if edata['weight'] > weight:
40+
g2.add_edge(f,to,edata)
41+
return g2
3242

3343
file="data.json"
3444
i = open(file,'rb')
@@ -50,7 +60,7 @@ def add_or_inc_edge(g,f,t):
5060
alter=rt['screen_name']
5161
retweets.add_edge(author,alter)
5262

53-
tags=[str.lower(tag['text']) for tag in hashtags]
63+
tags=[tag['text'].lower() for tag in hashtags]
5464
for t1 in tags:
5565
for t2 in tags:
5666
if t1 is not t2:
@@ -60,35 +70,3 @@ def add_or_inc_edge(g,f,t):
6070
continue
6171

6272

63-
place=''
64-
try:
65-
place=js['coordinates']
66-
except KeyError:
67-
pass
68-
try:
69-
if place is None: place=js['geo']
70-
except KeyError:
71-
pass
72-
try:
73-
if place is None: place=js['place']
74-
except KeyError:
75-
pass
76-
77-
if place is not None:
78-
print place
79-
if 'bounding_box' in place:
80-
if place['bounding_box'] is not None:
81-
for p in place['bounding_box']['coordinates']:
82-
for point in p:
83-
points.append(point)
84-
85-
if 'coordinates' in place:
86-
points.append(place['coordinates'])
87-
88-
89-
90-
hm = heatmap.Heatmap()
91-
hm.heatmap(points, "hm.png", dotsize=10)
92-
hm.saveKML("geo.kml")
93-
94-
points =[]

0 commit comments

Comments
 (0)