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()
def post(self): def geocode(vicinity): latlng = None params = urllib.urlencode({'address': vicinity}) url="https://maps.googleapis.com/maps/api/geocode/json?%s" % params response = urllib2.urlopen(url) jsongeocode = response.read() # I abhore having to decode _the entire response body_, but no other method # seemed to work, not FormData, not a GET parameter...so here you go. data = json.loads(jsongeocode) if data['status'] == 'OK' and data['results']: location = data['results'][0]['geometry']['location'] latlng = "%d,%d" % (location['lat'], location['lng']) return db.GeoPt(latlng) data = json.loads(self.request.body) data['client_latlng'] = db.GeoPt(data.get('latlng')) data['latlng'] = geocode(data['vicinity']) store = Store(**data) store.put()