Sumin Byeon avatar Sumin Byeon committed b1996df

Added process.py

Comments (0)

Files changed (1)

+import sys
+import csv
+import urllib2, json
+from urllib import urlencode
+
+def get_geolocation(address):
+    u = urllib2.urlopen('http://maps.googleapis.com/maps/api/geocode/json?' + urlencode({'sensor':'false', 'address':address}))
+    s = json.loads(u.read())
+    
+    if s['status'] == 'OK':
+        return s['results'][0]['geometry']['location']
+    else:
+        return None
+
+def process_row(row):
+    geo = get_geolocation(row[5])
+    return {'category':row[2], 'amount':row[3], 'lat':geo['lat'], 'lng':geo['lng']}
+
+rows = csv.reader(sys.stdin)
+#filtered = filter(lambda r: len(r) > 5 and r[5] != None, rows)
+#address_pairs = map(lambda r: (r, get_geolocation(r[5])), filtered)
+#filtered_pairs = filter(lambda p: p[1] != None, address_pairs)
+#data = map(lambda p: dict(p[0], **p[1]), filtered_pairs)
+
+data = []
+for row in rows:
+    if len(row) > 5 and row[5] != None:
+        print 'Looking up %s...' % row[5]
+        location = get_geolocation(row[5])
+        if location != None:
+            d = {'category':row[2], 'amount':float(row[3].replace(',','')), 'lat':location['lat'], 'lng':location['lng']}
+            data.append(d)
+
+print 'var data = ['
+for d in data:
+    print '    %s,' % d
+print '];'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.