Mercurial > hg > index.fcgi > www > www-1
comparison myw2/myw_flask_app.py @ 115:2b5d93c5628a
merge heads
author | paulo |
---|---|
date | Mon, 03 Aug 2020 02:02:02 -0600 |
parents | |
children | 86e71857d99e |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:5d2b55f6f5bf |
---|---|
1 import collections | |
2 | |
3 import flask | |
4 import markupsafe | |
5 | |
6 from html3.html3 import HTML | |
7 | |
8 | |
9 app = flask.Flask(__name__) | |
10 | |
11 | |
12 REDIRECTS = collections.OrderedDict({ | |
13 "desktop": "http://forecast.weather.gov/MapClick.php?lat=37.63048605200049&lon=-122.41107706299971", | |
14 "mobile": "http://mobile.weather.gov/index.php?lat=37.61961&lon=-122.36558", | |
15 "radar": "https://radar.weather.gov/lite/N0R/MUX_loop.gif", | |
16 "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", | |
17 "goes": "https://www.star.nesdis.noaa.gov/GOES/sector.php?sat=G17§or=psw", | |
18 }) | |
19 | |
20 | |
21 @app.route("/") | |
22 def index(): | |
23 root = HTML("html") | |
24 | |
25 header = root.head | |
26 header.title("myw") | |
27 header.link(rel="stylesheet", type="text/css", | |
28 href=flask.url_for("static", filename="index.css")) | |
29 | |
30 body = root.body(klass="body") | |
31 | |
32 for i in REDIRECTS: | |
33 div = body.div() | |
34 div.a(i.capitalize(), href=flask.url_for("show_target", target=i)) | |
35 | |
36 return str(root).encode("utf-8") | |
37 | |
38 | |
39 @app.route("/<target>") | |
40 def show_target(target): | |
41 safe_target = markupsafe.escape(target) | |
42 if safe_target in REDIRECTS: | |
43 return flask.redirect(REDIRECTS[safe_target], code=301) | |
44 else: | |
45 flask.abort(404) |