diff myw2/myw_flask_app.py @ 112:17454b47b15f

add myw2
author paulo
date Sun, 28 Jun 2020 20:53:33 -0700
parents
children 86e71857d99e
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/myw2/myw_flask_app.py	Sun Jun 28 20:53:33 2020 -0700
     1.3 @@ -0,0 +1,45 @@
     1.4 +import collections
     1.5 +
     1.6 +import flask
     1.7 +import markupsafe
     1.8 +
     1.9 +from html3.html3 import HTML
    1.10 +
    1.11 +
    1.12 +app = flask.Flask(__name__)
    1.13 +
    1.14 +
    1.15 +REDIRECTS = collections.OrderedDict({
    1.16 +  "desktop": "http://forecast.weather.gov/MapClick.php?lat=37.63048605200049&lon=-122.41107706299971",
    1.17 +  "mobile": "http://mobile.weather.gov/index.php?lat=37.61961&lon=-122.36558",
    1.18 +  "radar": "https://radar.weather.gov/lite/N0R/MUX_loop.gif",
    1.19 +  "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",
    1.20 +  "goes": "https://www.star.nesdis.noaa.gov/GOES/sector.php?sat=G17&sector=psw",
    1.21 +})
    1.22 +
    1.23 +
    1.24 +@app.route("/")
    1.25 +def index():
    1.26 +  root = HTML("html")
    1.27 +
    1.28 +  header = root.head
    1.29 +  header.title("myw")
    1.30 +  header.link(rel="stylesheet", type="text/css",
    1.31 +              href=flask.url_for("static", filename="index.css"))
    1.32 +	
    1.33 +  body = root.body(klass="body")
    1.34 +
    1.35 +  for i in REDIRECTS:
    1.36 +    div = body.div()
    1.37 +    div.a(i.capitalize(), href=flask.url_for("show_target", target=i))
    1.38 +	
    1.39 +  return str(root).encode("utf-8")
    1.40 +
    1.41 +
    1.42 +@app.route("/<target>")
    1.43 +def show_target(target):
    1.44 +  safe_target = markupsafe.escape(target)
    1.45 +  if safe_target in REDIRECTS:
    1.46 +    return flask.redirect(REDIRECTS[safe_target], code=301)
    1.47 +  else:
    1.48 +    flask.abort(404)