-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathweb.py
executable file
·56 lines (40 loc) · 1.06 KB
/
web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys, flask, os, codecs
app = flask.Flask(__name__)
#write a file(s) for this page to the filesystem
#return the location of the page
def generate_page(term):
#generate html
path = generate_html(term)
#generate css
return path
import gen_html
def generate_html(term):
html = gen_html.generate(term);
filename = "page.html"
path = filename
f = codecs.open("templates/"+path, 'w', 'utf-8')
#html pages go in templates/
f.write(html)
f.close()
return path
@app.route("/")
def main():
return flask.render_template("index.html");
@app.route("/favicon.ico")
def favicon():
return "";
@app.route("/<term>")
def term(term):
page = generate_page(term);
return flask.render_template(page);
if __name__ == "__main__":
app.debug = True
host="127.0.0.1"
port=8080 #run on 80 by default
if sys.argv[1]: #run on port given from heroku
host = sys.argv[1]
if sys.argv[2]: #run on host given from heroku
port = sys.argv[2]
app.run(host=host, port=int(port))