view myw/redirect_app.py @ 100:00ef8e28ab4c

deer_crash: add picutre of bent forks
author paulo
date Wed, 29 Aug 2018 23:21:55 -0700
parents 6a45e46f0c05
children
line source
1 import os
3 import html
6 TITLE = "myw"
7 REDIRECT_FILE = ".htaccess"
10 def main(environ):
11 links = []
13 with open(REDIRECT_FILE) as f:
14 for l in f:
15 l = l.lstrip()
16 if l.startswith("Redirect"):
17 ls = l.split()
18 if len(ls) == 4:
19 path = ls[2].strip('"')
20 links.append(os.path.basename(path))
22 root = html.HTML("html")
24 header = root.head
25 header.title(TITLE)
26 header.link(rel="stylesheet", type="text/css", href="index.css")
28 body = root.body(klass="body")
30 for i in links:
31 div = body.div()
32 div.a(i.capitalize(), href=i)
34 return unicode(root).encode("utf-8")
37 def app(environ, start_response):
38 response_body = main(environ)
39 response_headers = [
40 ("Content-Type", "text/html; charset=UTF-8"),
41 ("Content-Length", str(len(response_body))),
42 ]
43 start_response("200 OK", response_headers)
45 return [response_body]