You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
from flask import Flask, render_template, request, json
|
|
import requests
|
|
# import urllib.request
|
|
# from urllib.request import urlopen
|
|
|
|
app = Flask(__name__)
|
|
@app.route("/")
|
|
def index():
|
|
# return ['data', 'AAA']
|
|
return render_template("weather-form.html")
|
|
|
|
|
|
@app.route("/datasTaipei", methods=['GET', 'POST'])
|
|
def datas():
|
|
if request.method == 'POST':
|
|
|
|
r = requests.get("http://opendata.cwb.gov.tw/api/v1/rest/datastore/F-D0047-061?Authorization=CWB-6B764FB3-BD6E-4198-96C0-43FB4EBA1375&limit=10&offset=0&format=JSON&elementName=T&sort=time")
|
|
list_of_dicts = r.json()
|
|
list_of_dicts2 = list_of_dicts["records"]["locations"][0]
|
|
list_of_dicts3 = list_of_dicts2["location"]
|
|
for i in list_of_dicts3:
|
|
print(i["locationName"])
|
|
|
|
return list_of_dicts3
|
|
|
|
|
|
|
|
@app.route("/datasChiayi", methods=['GET', 'POST'])
|
|
def datasTaichung():
|
|
r = requests.get("http://opendata.cwb.gov.tw/api/v1/rest/datastore/F-D0047-061?Authorization=CWB-6B764FB3-BD6E-4198-96C0-43FB4EBA1375&limit=10&offset=0&format=JSON&elementName=T&sort=time")
|
|
list_of_dicts = r.json()
|
|
list_of_dicts2 = list_of_dicts["records"]
|
|
|
|
return list_of_dicts2
|
|
|
|
|
|
@app.route("/datasKaohsiung", methods=['GET', 'POST'])
|
|
def datasKaohsiung():
|
|
r = requests.get("http://opendata.cwb.gov.tw/api/v1/rest/datastore/F-D0047-061?Authorization=CWB-6B764FB3-BD6E-4198-96C0-43FB4EBA1375&limit=10&offset=0&format=JSON&elementName=T&sort=time")
|
|
list_of_dicts = r.json()
|
|
list_of_dicts2 = list_of_dicts["records"]
|
|
|
|
return list_of_dicts2
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(debug=True)
|