blob: e7a607516f5f852eb7b2870bcce56c06d2ad5350 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
import flask
import requests
import datetime
import zoneinfo
import locale
import block_weather
locale.setlocale(locale.LC_ALL, '')
app = flask.Flask(__name__)
@app.route("/")
def index():
return flask.render_template("index.html")
@app.route("/time")
def get_time():
# TODO: date should be passed as JSON
date = datetime.datetime.now(zoneinfo.ZoneInfo("Asia/Tokyo"))
quarter = (date.month - 1) // 3 + 1
week = date.isocalendar().week
lines = [
"Tokyo: " + date.strftime("%x (%a)") + f" (Q{quarter}W{week})",
"Tokyo: " + date.astimezone(zoneinfo.ZoneInfo("Asia/Tokyo")).strftime("%H:%M (%Z) (UTC%:z)"),
"Berlin: " + date.astimezone(zoneinfo.ZoneInfo("Europe/Berlin")).strftime("%H:%M (%Z) (UTC%:z)"),
"Lima: " + date.astimezone(zoneinfo.ZoneInfo("America/Lima")).strftime("%H:%M (%Z) (UTC%:z)"),
"New York: " + date.astimezone(zoneinfo.ZoneInfo("America/New_York")).strftime("%H:%M (%Z) (UTC%:z)"),
"Chicago: " + date.astimezone(zoneinfo.ZoneInfo("America/Chicago")).strftime("%H:%M (%Z) (UTC%:z)"),
"Denver: " + date.astimezone(zoneinfo.ZoneInfo("America/Denver")).strftime("%H:%M (%Z) (UTC%:z)"),
"Los Angeles: " + date.astimezone(zoneinfo.ZoneInfo("America/Los_Angeles")).strftime("%H:%M (%Z) (UTC%:z)"),
"Anchorage: " + date.astimezone(zoneinfo.ZoneInfo("America/Anchorage")).strftime("%H:%M (%Z) (UTC%:z)"),
"Honolulu: " + date.astimezone(zoneinfo.ZoneInfo("Pacific/Honolulu")).strftime("%H:%M (%Z) (UTC%:z)"),
]
return flask.jsonify({"time": "\n".join(lines)})
@app.route("/weather")
def get_weather():
city = flask.request.args.get("city", "Kofu, JP")
data = block_weather.get_current_weather(city)
return flask.jsonify(data)
|