@@ -29,6 +29,16 @@ def add_or_inc_edge(g,f,t):
29
29
g [f ][t ]['weight' ]+= 1
30
30
else :
31
31
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
32
42
33
43
file = "data.json"
34
44
i = open (file ,'rb' )
@@ -50,7 +60,7 @@ def add_or_inc_edge(g,f,t):
50
60
alter = rt ['screen_name' ]
51
61
retweets .add_edge (author ,alter )
52
62
53
- tags = [str . lower ( tag ['text' ]) for tag in hashtags ]
63
+ tags = [tag ['text' ]. lower ( ) for tag in hashtags ]
54
64
for t1 in tags :
55
65
for t2 in tags :
56
66
if t1 is not t2 :
@@ -60,35 +70,3 @@ def add_or_inc_edge(g,f,t):
60
70
continue
61
71
62
72
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