aboutsummaryrefslogtreecommitdiffstats
path: root/app.py
diff options
context:
space:
mode:
authorMitsuo Tokumori <[email protected]>2025-03-06 11:24:57 +0900
committerMitsuo Tokumori <[email protected]>2025-03-06 11:24:57 +0900
commit304d0a2c3e0e1eea58d6db1762c1b96e450b5843 (patch)
tree70976dfdec1b65f92849125a47b7ff7ff18740f7 /app.py
downloadmasu-304d0a2c3e0e1eea58d6db1762c1b96e450b5843.tar.gz
masu-304d0a2c3e0e1eea58d6db1762c1b96e450b5843.tar.bz2
masu-304d0a2c3e0e1eea58d6db1762c1b96e450b5843.zip
Initial commit
Only 2 blocks: time and weather. Currently data is passed in formatted strings made server-side (python) just for testing, later the formatting should be client-side (html). Also the "time" API might be redundant, ideally it should pass the city names, and offsets (time zone), and then just use the system time (otherwise DST jumps would need to be taken into account).
Diffstat (limited to 'app.py')
-rw-r--r--app.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/app.py b/app.py
new file mode 100644
index 0000000..e7a6075
--- /dev/null
+++ b/app.py
@@ -0,0 +1,40 @@
+import flask
+import requests
+import datetime
+import zoneinfo
+import locale
+
+import block_weather
+
+locale.setlocale(locale.LC_ALL, '')
+app = flask.Flask(__name__)
+
+def index():
+ return flask.render_template("index.html")
+
+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)})
+
[email protected]("/weather")
+def get_weather():
+ city = flask.request.args.get("city", "Kofu, JP")
+ data = block_weather.get_current_weather(city)
+ return flask.jsonify(data)