# HG changeset patch # User paulo # Date 1491543723 25200 # Node ID 6a45e46f0c058a9efac9006b8a27a686e8c102f9 # Parent 302eebbf025f19f93c434232c08c63a8d21e1601 myw: use new redirect_app diff -r 302eebbf025f -r 6a45e46f0c05 myw/.htaccess --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/myw/.htaccess Thu Apr 06 22:42:03 2017 -0700 @@ -0,0 +1,4 @@ +Redirect permanent "/myw/desktop" "http://forecast.weather.gov/MapClick.php?lat=37.63048605200049&lon=-122.41107706299971" +Redirect permanent "/myw/mobile" "http://mobile.weather.gov/index.php?lat=37.61961&lon=-122.36558" +Redirect permanent "/myw/radar" "https://radar.weather.gov/lite/N0R/MUX_loop.gif" +Redirect permanent "/myw/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" \ No newline at end of file diff -r 302eebbf025f -r 6a45e46f0c05 myw/index.fcgi --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/myw/index.fcgi Thu Apr 06 22:42:03 2017 -0700 @@ -0,0 +1,8 @@ +#!/usr/bin/env python + +from flup.server.fcgi import WSGIServer + +from redirect_app import app + + +WSGIServer(app).run() diff -r 302eebbf025f -r 6a45e46f0c05 myw/index.html --- a/myw/index.html Fri Feb 24 00:30:54 2017 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ - - -myw - - - - - - - - - - diff -r 302eebbf025f -r 6a45e46f0c05 myw/redirect_app.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/myw/redirect_app.py Thu Apr 06 22:42:03 2017 -0700 @@ -0,0 +1,45 @@ +import os + +import html + + +TITLE = "myw" +REDIRECT_FILE = ".htaccess" + + +def main(environ): + links = [] + + with open(REDIRECT_FILE) as f: + for l in f: + l = l.lstrip() + if l.startswith("Redirect"): + ls = l.split() + if len(ls) == 4: + path = ls[2].strip('"') + links.append(os.path.basename(path)) + + root = html.HTML("html") + + header = root.header + header.title(TITLE) + header.link(rel="stylesheet", type="text/css", href="index.css") + + body = root.body(klass="body") + + for i in links: + div = body.div() + div.a(i.capitalize(), href=i) + + return unicode(root).encode("utf-8") + + +def app(environ, start_response): + response_body = main(environ) + response_headers = [ + ("Content-Type", "text/html; charset=UTF-8"), + ("Content-Length", str(len(response_body))), + ] + start_response("200 OK", response_headers) + + return [response_body] diff -r 302eebbf025f -r 6a45e46f0c05 myw/redirect_test_server.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/myw/redirect_test_server.py Thu Apr 06 22:42:03 2017 -0700 @@ -0,0 +1,38 @@ +import os +import sys +import signal + +import cherrypy +from cherrypy import wsgiserver + +import redirect_app + + +def sighandler(signum, frame): + sys.stderr.write("Caught signal: %s \n" % signum) + server.stop() + + +class FileServerRoot: + def default(self, *args): + if len(args) == 0: + raise cherrypy.HTTPError(404) + + filepath = os.path.abspath(os.path.join(*args)) + return cherrypy.lib.static.serve_file(filepath) + + default.exposed = True + + +if __name__ == "__main__": + fileServerApp = cherrypy.Application(FileServerRoot()) + dispatcher = wsgiserver.WSGIPathInfoDispatcher({ + "/index.fcgi": redirect_app.app, + "": fileServerApp, + }) + server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8000), dispatcher) + + signal.signal(signal.SIGINT, sighandler) + signal.signal(signal.SIGTERM, sighandler) + + server.start()