def generate_all_rankings(whatever=None,skip_if_set=True,range=(0,0)): cities = City.objects.all()[range[0]:range[1]] resp = "" for c in cities: wname = None if c.wikiname is None: name = _wikipedia_article(c.name) if (name is not None): wname = name['wikiname'] else: if(skip_if_set is True): wname = None else: wname = c.wikiname if wname is not None: r1 = (wikipedia_ranking(wname)) r2 = (panoramio_ranking(c.name)) r3 = decimal.Decimal("0.0") c.wikiname = wname c.setRating(r1['content'],r2,r3) c.save() resp += "%s (%s) [%d,%d]\n" % (c.name,wname,r1['content'],r2) resp += "Done\n" 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}