Ejemplo n.º 1
0
def create_or_getCity(cityName, state, lat,lon):
    try:
        c = City.objects.get(name=cityName)
    except City.DoesNotExist:        
            r = requests.get("http://photon.komoot.de/api/?q={},{}&limit=1&lat={}&lon={}".format(cityName, state.name, lat,lon)).json()
            
            lastCity = City.objects.latest('created_on')
            c = City()
            c.id = lastCity.id +1
            c.name=cityName        
            c.stateID=state.id
            c.lat= r['features'][0]['geometry']['coordinates'][1]
            c.lon= r['features'][0]['geometry']['coordinates'][0]
            c.live="true"
            c.save()
    return c