#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask, render_template, redirect
# third-party HTTP client library
# sudo pip install requests
import requests
import json
app = Flask(__name__)
@app.route("/")
def index():
url =
"http://weather.livedoor.com/forecast/webservice/json/v1?city=400040"
Uresponse = requests.get(url)
print("Uresponse={}".format(Uresponse))
Jresponse = Uresponse.text
#print("Jresponse={}".format(Jresponse))
data = json.loads(Jresponse)
print("data={}".format(data))
#print(json.dumps(data, indent=2))
print()
print()
print(data['location'])
print(data['location']['city'])
city=data['location']['city']
print(data['location']['prefecture'])
prefecture=data['location']['prefecture']
print(data['location']['area'])
area=data['location']['area']
print(data['publicTime'])
publicTime=data['publicTime']
dateTime=publicTime.split('T')
print("dateTime={}".format(dateTime))
date=dateTime[0]
time=dateTime[1]
time=time.split('+')
print("time={}".format(time))
print(data['description']['text'])
text=data['description']['text']
templateData = {
'city' : city,
'prefecture' :
prefecture,
'area' : area,
'name' : text,
'ampm' : 1,
'date': date,
'time': time[0]
}
#./templates/sample.html
return render_template('weather.html',
**templateData)
if __name__ == "__main__":
print("app.url_map={}".format(app.url_map))
app.run(host='0.0.0.0', port=8080,
debug=True)
|