def show_home(request): ip = get_ip(request) city = get_city(str(ip)) time = datetime.datetime.now()-datetime.timedelta(hours=1) current_city_aqi = get_current_city_aqi(city) aqi = current_city_aqi.aqi return render_to_response("home.html", {'location':city, 'aqi':aqi}, context_instance=RequestContext(request))
def show_aqi(request): ip = get_ip(request) city = get_city(str(ip)) cities_info = City.objects.all() cities = [] for city_name in cities_info: cities.append(city_name.name) #cities = sorted(cities_nosort, cmp=locale.strcoll) time = datetime.datetime.now()-datetime.timedelta(hours=1) current_city_aqi = get_current_city_aqi(city) if current_city_aqi: city_aqi_per = int(current_city_aqi.aqi)*100/500 else: city_aqi_per = 0 current_position_aqi = get_current_position_aqi(city) first_pn = current_position_aqi[0].position_name pn = [] for aqi in current_position_aqi: pn.append(aqi.position_name) return render_to_response("aqi.html", {'location':city, 'cities':cities, 'aqi_per':city_aqi_per, 'pub_time':time.strftime("%Y-%m-%d %H:00:00"), 'pn_num':len(current_position_aqi), 'first_position_name':first_pn, 'city_aqis':current_city_aqi, 'position_aqis':current_position_aqi}, context_instance=RequestContext(request))