diff options
| author | Mitsuo Tokumori <[email protected]> | 2025-03-08 16:03:30 +0900 |
|---|---|---|
| committer | Mitsuo Tokumori <[email protected]> | 2025-03-08 16:03:30 +0900 |
| commit | 51163b167cce01af6101438e5e61145ad798f213 (patch) | |
| tree | 9c8e75266cedfb205db175b0b2bc41b49df75cea /app/routes/main.py | |
| parent | d9af103b9a8aed86d6ac834f1240edfb2173ffa0 (diff) | |
| download | masu-51163b167cce01af6101438e5e61145ad798f213.tar.gz masu-51163b167cce01af6101438e5e61145ad798f213.tar.bz2 masu-51163b167cce01af6101438e5e61145ad798f213.zip | |
Restructure python code to be modular
The python code is now a package named app.
app/models: db models
app/routes: flask blueprints
app/static: css, js
app/templates: jinja html templates
Diffstat (limited to 'app/routes/main.py')
| -rw-r--r-- | app/routes/main.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/app/routes/main.py b/app/routes/main.py new file mode 100644 index 0000000..842a09b --- /dev/null +++ b/app/routes/main.py @@ -0,0 +1,43 @@ +import flask +import requests +import datetime +import zoneinfo +import locale + +from ..utils import block_weather + +locale.setlocale(locale.LC_ALL, '') +bp = flask.Blueprint('main', __name__) + + [email protected]("/") +def index(): + return flask.render_template("index.html") + + [email protected]("/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)}) + + [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) |
