Ejemplo n.º 1
0
def get_aqi_from_json():
    file = open("/data1/www/htdocs/371/timeroute/1/all_cities.json")
    content = file.read()
    if(content):
        cities = json.loads(content)
        for city in cities:
            current_aqi = Aqi_Position_Name()
            current_aqi.aqi = city['aqi']
            current_pn = Position_Name()
            current_pn = Position_Name.objects.filter(city=city['area']).get(position_name=city['position_name'])
            current_aqi.position_name_id = current_pn.id
            current_aqi.so2 = city['so2']
            current_aqi.so2_24h = city['so2_24h']
            current_aqi.co = city['co']
            current_aqi.co_24h = city['co_24h']
            current_aqi.no2 = city['no2']
            current_aqi.no2_24h = city['no2_24h']
            current_aqi.o3 = city['o3']
            current_aqi.o3_8h = city['o3_8h']
            current_aqi.o3_24h = city['o3_24h']
            current_aqi.o3_8h_24h = city['o3_8h_24h']
            current_aqi.pm10 = city['pm10']
            current_aqi.pm10_24h = city['pm10_24h']
            current_aqi.pm2_5 = city['pm2_5']
            current_aqi.pm2_5_24h = city['pm2_5_24h']
            if city['primary_pollutant']:
                current_aqi.primary_pollutant = city['primary_pollutant']
            else:
                current_aqi.primary_pollutant = "——"
            if city['quality']:
            	current_aqi.quality = city['quality']
            else:
                current_aqi.quality = "——"
            current_aqi.time_point = city['time_point']
            current_aqi.save()
Ejemplo n.º 2
0
def get_position_aqi():
    url = "http://www.pm25.in/api/querys/all_cities.json?token=YpQx4AByXgTMxEa1YL1k"
    resp = urllib2.urlopen(url)
    content = resp.read()
    if(content):
        cities = json.loads(content)
        for city in cities:
            current_aqi = Aqi_Position_Name()
            current_aqi.aqi = city['aqi']
            current_pn = Position_Name()
            current_pn = Position_Name.objects.filter(city=city['area']).get(position_name=city['position_name'])
            current_aqi.position_name_id = current_pn.id
            current_aqi.so2 = city['so2']
            current_aqi.so2_24h = city['so2_24h']
            current_aqi.co = city['co']
            current_aqi.co_24h = city['co_24h']
            current_aqi.no2 = city['no2']
            current_aqi.no2_24h = city['no2_24h']
            current_aqi.o3 = city['o3']
            current_aqi.o3_8h = city['o3_8h']
            current_aqi.o3_24h = city['o3_24h']
            current_aqi.o3_8h_24h = city['o3_8h_24h']
            current_aqi.pm10 = city['pm10']
            current_aqi.pm10_24h = city['pm10_24h']
            current_aqi.pm2_5 = city['pm2_5']
            current_aqi.pm2_5_24h = city['pm2_5_24h']
            if city['primary_pollutant']:
                current_aqi.primary_pollutant = city['primary_pollutant']
            else:
                current_aqi.primary_pollutant = "——"
            if city['quality']:
            	current_aqi.quality = city['quality']
            else:
                current_aqi.quality = "——"
            current_aqi.time_point = city['time_point']
            current_aqi.save()