Created
February 4, 2013 13:26
-
-
Save reiki4040/4706734 to your computer and use it in GitHub Desktop.
get temperture and send growthforecast.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
import json | |
import urllib3 | |
def get_temperature(http): | |
# city=400040 Kurume city in Fukuoka. | |
resp = http.request('GET', 'http://weather.livedoor.com/forecast/webservice/json/v1?city=400040') | |
json_data = json.loads(resp.data.decode('utf-8')) | |
max_temp = json_data['forecasts'][1]['temperature']['max']['celsius'] | |
min_temp = json_data['forecasts'][1]['temperature']['min']['celsius'] | |
return max_temp, min_temp | |
def send_growthforecast(http, graph_name, num): | |
send_url = 'http://localhost:5125/api/fukuoka/kurume/' + graph_name | |
params = {'number': num} | |
resp = http.request('POST', send_url, params) | |
def main(): | |
http = urllib3.PoolManager() | |
max_temp, min_temp = get_temperature(http) | |
send_growthforecast(http, 'tomorrow_max_temperature', max_temp) | |
send_growthforecast(http, 'tomorrow_min_temperature', min_temp) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment