Mercurial > hg > index.fcgi > www > www-1
view myw2/myw_flask_app.py @ 143:627316f64e79
myrss2: FEEDS: Add wolfstreet.com
author | paulo |
---|---|
date | Wed, 15 May 2024 00:29:19 -0700 |
parents | a26c4388749b |
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 "mobile": "http://mobile.weather.gov/index.php?lat=37.61961&lon=-122.36558",
15 "radar": "https://radar.weather.gov/ridge/standard/KMUX_loop.gif",
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",
17 "goes": "https://www.star.nesdis.noaa.gov/GOES/sector.php?sat=G17§or=psw",
18 })
21 @app.route("/")
22 def index():
23 root = HTML("html")
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"))
30 body = root.body(klass="body")
32 for i in REDIRECTS:
33 div = body.div()
34 div.a(i.capitalize(), href=flask.url_for("show_target", target=i))
36 return str(root).encode("utf-8")
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)