annotate myw2/myw_flask_app.py @ 124:9b57b90aea31

initial add for pics3
author paulo
date Thu, 25 Mar 2021 00:33:42 -0700
parents 17454b47b15f
children 3192e40f5eaf
rev   line source
paulo@112 1 import collections
paulo@112 2
paulo@112 3 import flask
paulo@112 4 import markupsafe
paulo@112 5
paulo@112 6 from html3.html3 import HTML
paulo@112 7
paulo@112 8
paulo@112 9 app = flask.Flask(__name__)
paulo@112 10
paulo@112 11
paulo@112 12 REDIRECTS = collections.OrderedDict({
paulo@112 13 "desktop": "http://forecast.weather.gov/MapClick.php?lat=37.63048605200049&lon=-122.41107706299971",
paulo@112 14 "mobile": "http://mobile.weather.gov/index.php?lat=37.61961&lon=-122.36558",
paulo@120 15 #"radar": "https://radar.weather.gov/lite/N0R/MUX_loop.gif",
paulo@120 16 "radar": "https://radar.weather.gov/?settings=v1_eyJhZ2VuZGEiOnsiaWQiOiJ3ZWF0aGVyIiwiY2VudGVyIjpbLTEyMi40MiwzNy43NzddLCJ6b29tIjo3LCJsb2NhdGlvbiI6Wy0xMjIuNDIsMzcuNzc3XX0sImJhc2UiOiJzdGFuZGFyZCIsImNvdW50eSI6ZmFsc2UsImN3YSI6ZmFsc2UsInN0YXRlIjpmYWxzZSwibWVudSI6dHJ1ZSwic2hvcnRGdXNlZE9ubHkiOmZhbHNlfQ%3D%3D#/",
paulo@112 17 "hourly": "http://forecast.weather.gov/meteograms/Plotter.php?lat=37.6305&lon=-122.4111&wfo=MTR&zcode=CAZ508&gset=18&gdiff=3&unit=0&tinfo=PY8&ahour=0&pcmd=11011111111110000000000000000000000000000000000000000000000&lg=en&indu=1!1!1!&dd=&bw=&hrspan=48&pqpfhr=6&psnwhr=6",
paulo@112 18 "goes": "https://www.star.nesdis.noaa.gov/GOES/sector.php?sat=G17&sector=psw",
paulo@112 19 })
paulo@112 20
paulo@112 21
paulo@112 22 @app.route("/")
paulo@112 23 def index():
paulo@112 24 root = HTML("html")
paulo@112 25
paulo@112 26 header = root.head
paulo@112 27 header.title("myw")
paulo@112 28 header.link(rel="stylesheet", type="text/css",
paulo@112 29 href=flask.url_for("static", filename="index.css"))
paulo@112 30
paulo@112 31 body = root.body(klass="body")
paulo@112 32
paulo@112 33 for i in REDIRECTS:
paulo@112 34 div = body.div()
paulo@112 35 div.a(i.capitalize(), href=flask.url_for("show_target", target=i))
paulo@112 36
paulo@112 37 return str(root).encode("utf-8")
paulo@112 38
paulo@112 39
paulo@112 40 @app.route("/<target>")
paulo@112 41 def show_target(target):
paulo@112 42 safe_target = markupsafe.escape(target)
paulo@112 43 if safe_target in REDIRECTS:
paulo@112 44 return flask.redirect(REDIRECTS[safe_target], code=301)
paulo@112 45 else:
paulo@112 46 flask.abort(404)