paulo@112: import collections paulo@112: paulo@112: import flask paulo@112: import markupsafe paulo@112: paulo@112: from html3.html3 import HTML paulo@112: paulo@112: paulo@112: app = flask.Flask(__name__) paulo@112: paulo@112: paulo@112: REDIRECTS = collections.OrderedDict({ paulo@112: "desktop": "http://forecast.weather.gov/MapClick.php?lat=37.63048605200049&lon=-122.41107706299971", paulo@112: "mobile": "http://mobile.weather.gov/index.php?lat=37.61961&lon=-122.36558", paulo@127: "radar": "https://radar.weather.gov/ridge/lite/KMUX_loop.gif", paulo@128: "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: "goes": "https://www.star.nesdis.noaa.gov/GOES/sector.php?sat=G17§or=psw", paulo@112: }) paulo@112: paulo@112: paulo@112: @app.route("/") paulo@112: def index(): paulo@112: root = HTML("html") paulo@112: paulo@112: header = root.head paulo@112: header.title("myw") paulo@112: header.link(rel="stylesheet", type="text/css", paulo@112: href=flask.url_for("static", filename="index.css")) paulo@112: paulo@112: body = root.body(klass="body") paulo@112: paulo@112: for i in REDIRECTS: paulo@112: div = body.div() paulo@112: div.a(i.capitalize(), href=flask.url_for("show_target", target=i)) paulo@112: paulo@112: return str(root).encode("utf-8") paulo@112: paulo@112: paulo@112: @app.route("/") paulo@112: def show_target(target): paulo@112: safe_target = markupsafe.escape(target) paulo@112: if safe_target in REDIRECTS: paulo@112: return flask.redirect(REDIRECTS[safe_target], code=301) paulo@112: else: paulo@112: flask.abort(404)