/
scripts.py
43 lines (34 loc) · 1.28 KB
/
scripts.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
import csv
from models import Store, Image
import json
from google.appengine.ext import db
import re
def upload():
with open('data.csv') as f:
reader = csv.DictReader(f)
for row in reader:
try:
s = Store()
print row['name'], row['images'], row['types']
if re.search("\[.*\]", row['reference']):
row['place_id'] = row['scope']
row['scope'] = row['latlng']
row['latlng'] = row['address']
row['address'] = row['photos']
row['photos'] = row['reference']
print row['name'], row['images'], row['types']
s.tags = json.loads(row['types'])
s.point = db.GeoPt(*eval(row['latlng']))
s.reference = row['reference'] and row['reference'][0] or ""
s.address = row['address']
s.name = row['name']
for img in eval(row['images']):
image = Image()
image.image = img
image.put()
s.imgs.append(image)
except Exception as e:
pass
finally:
s.put()
upload()