annotate myw2/myw_flask_app.py @ 140:ae6b4032a912

myrss2: FEEDS: Add jabberwocking.com, remove danielmiessler.com
author paulo
date Mon, 03 Jul 2023 04:40:23 +0000
parents a26c4388749b
children
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@136 15 "radar": "https://radar.weather.gov/ridge/standard/KMUX_loop.gif",
paulo@128 16 "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",
paulo@112 17 "goes": "https://www.star.nesdis.noaa.gov/GOES/sector.php?sat=G17&sector=psw",
paulo@112 18 })
paulo@112 19
paulo@112 20
paulo@112 21 @app.route("/")
paulo@112 22 def index():
paulo@112 23 root = HTML("html")
paulo@112 24
paulo@112 25 header = root.head
paulo@112 26 header.title("myw")
paulo@112 27 header.link(rel="stylesheet", type="text/css",
paulo@112 28 href=flask.url_for("static", filename="index.css"))
paulo@112 29
paulo@112 30 body = root.body(klass="body")
paulo@112 31
paulo@112 32 for i in REDIRECTS:
paulo@112 33 div = body.div()
paulo@112 34 div.a(i.capitalize(), href=flask.url_for("show_target", target=i))
paulo@112 35
paulo@112 36 return str(root).encode("utf-8")
paulo@112 37
paulo@112 38
paulo@112 39 @app.route("/<target>")
paulo@112 40 def show_target(target):
paulo@112 41 safe_target = markupsafe.escape(target)
paulo@112 42 if safe_target in REDIRECTS:
paulo@112 43 return flask.redirect(REDIRECTS[safe_target], code=301)
paulo@112 44 else:
paulo@112 45 flask.abort(404)