-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrello_geojson.py
102 lines (87 loc) · 3.47 KB
/
trello_geojson.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
#!/usr/bin/python
import sys
import json
import re
sys.path.append('../py-trello')
from trello import TrelloClient
sys.path.append('../python-geojson')
#import cartodb
import secrets
client = TrelloClient(
api_key=secrets.trello_key,
api_secret=secrets.trello_secret,
token=secrets.trello_oauth_token,
token_secret= secrets.trello_oauth_token_secret,
)
# https://github.com/opencagedata/python-opencage-geocoder
import pprint
import geojson
import geojson
#crs = geojson.crs.Named("urn:ogc:def:crs:OGC:1.3:CRS84")
points = []
for b in client.list_boards():
#print b
for l in b.all_lists():
for c in l.list_cards():
comments = c.get_comments()
done = False
done2 = False
c.fetch()
desc = c.description
url = c.short_url
for cmt in comments :
#pprint.pprint(cmt)
txt = cmt['data']['text']
if txt.startswith('GeoCode: '):
j = txt[9:]
if j == 'Failed':
#continue
pass
else:
#print ("gc:"+j)
d = eval(j)
good = False
for l in d:
if 'geometry' in l:
if 'components' in l:
if 'city' in l['components']:
city = l['components']['city']
if city != 'Trenton':
print ("Skipping"+ city)
else:
#pprint.pprint(l)
good = True
else:
pass
#print ('no city')
#pprint.pprint(l['components'])
else:
#print ('no components')
#pprint.pprint(l)
pass
lat = l[u'geometry']['lat']
lng = l[u'geometry']['lng']
#print ()
p = geojson.Point((lng,lat))
f = geojson.Feature(
geometry=p,
properties={
"short_url": "<a href=" + url + ">"+url+"</a>",
"description": desc
}
)
#print p
if good:
points.append(f)
break
#print ("To carto", c)
else:
#pprint.pprint(l)
pass
else:
#print ("skip:"+txt)
pass
c = str(geojson.FeatureCollection(points))
o = open('snow.geojson','w')
o.write(c)
o.close()