def find_timezones(range=None): cities = City.objects.all() if (range is not None): cities=cities[range[0]:range[1]] resp = "" for c in cities: o = city_timezone(c.id) if(o is None): resp += "%d,127\n" % (c.id) else: c.timezone = int(o['offset']) c.save() resp += "%d,%s\n" % (c.id,o['offset']) return resp
def add_new_city(name, country): # we need a name and a country at first! std_error_obj = {'error': 2, 'city': None} if(country is None): return std_error_obj # by name coords = gmaplocal_coordinates(name,country.name) if(coords is None): return std_error_obj # let's see if this city already exists new_city = None try: new_city = City.objects.get(name__iexact=coords['city']) if(new_city is None): new_city = City.objects.get(local_name__iexact=coords['city']) except ObjectDoesNotExist: new_city = None if new_city is not None: return {'id': new_city.id, 'slug': new_city.slug, 'error': 1} new_city = City() new_city.name = coords['city'] new_city.coordinates = Point((float(coords['latitude']),float(coords['longitude']))) new_city.latitude = Decimal(coords['latitude']) new_city.longitude = Decimal(coords['longitude']) new_city.country = country new_city.save() # now it has an ID new_city_id = new_city.id # take timezone info timezone = city_timezone(new_city_id) new_city.timezone = timezone['offset'] # wikipedia tentative article name & rankings wname = _wikipedia_article(new_city_id) if (wname is not None): new_city.wikiname = wname['wikiname'] new_city.save() # rank, and it's done rank_city(new_city) return {'id': new_city_id, 'slug': new_city.slug, 'error': 0}