view myw2/myw_flask_app.py @ 146:bd31bc82164a

myw2: Remove mobile page
author paulo
date Fri, 06 Jun 2025 07:19:39 +0000
parents 93ad5ecd149d
children
line source
1 import collections
3 import flask
4 import markupsafe
6 from html3.html3 import HTML
9 app = flask.Flask(__name__)
12 REDIRECTS = collections.OrderedDict({
13 "desktop": "http://forecast.weather.gov/MapClick.php?lat=37.63048605200049&lon=-122.41107706299971",
14 "radar": "https://radar.weather.gov/ridge/standard/KMUX_loop.gif",
15 "hourly": "https://forecast.weather.gov/MapClick.php?w0=t&w1=td&w2=wc&w3=sfcwind&w4=sky&w5=pop&w6=rh&w7=rain&w8=thunder&w12=fog&AheadHour=0&Submit=Submit&&FcstType=graphical&textField1=37.6305&textField2=-122.4111&site=all",
16 "goes": "https://www.star.nesdis.noaa.gov/GOES/sector.php?sat=G17&sector=psw",
17 })
20 @app.route("/")
21 def index():
22 root = HTML("html")
24 header = root.head
25 header.title("myw")
26 header.link(rel="stylesheet", type="text/css",
27 href=flask.url_for("static", filename="index.css"))
29 body = root.body(klass="body")
31 for i in REDIRECTS:
32 div = body.div()
33 div.a(i.capitalize(), href=flask.url_for("show_target", target=i))
35 return str(root).encode("utf-8")
38 @app.route("/<target>")
39 def show_target(target):
40 safe_target = markupsafe.escape(target)
41 if safe_target in REDIRECTS:
42 return flask.redirect(REDIRECTS[safe_target], code=301)
43 else:
44 flask.abort(404)