/
code.py
51 lines (42 loc) · 1.24 KB
/
code.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
import web
import os
#resolve absolute directory path
root_dir = os.path.abspath(os.path.dirname(__file__))
#render templates from folder
template_dir = root_dir + '/templates'
render = web.template.render(template_dir, base='layout')
#absolute path to sqlite db
db_dir = root_dir + '/news.db'
#debugging purposes
#web.config.debug = True
urls = (
'/', 'index',
'/news', 'news',
'/discography','discography',
'/about', 'about'
)
class index:
def GET(self):
return render.index()
class news:
def GET(self):
db = web.database(dbn='sqlite', db=db_dir)
#retrieve only the twenty most recent articles
articles = db.select('articles', order='epochtime DESC', limit = 20)
update_time = db.select('articles', what='dbtime',
limit = 1, order = 'dbtime DESC')[0].dbtime
return render.news(articles,update_time)
class discography:
def GET(self):
return render.discography()
class about:
def GET(self):
return render.about()
if __name__ == "__main__":
#development
app = web.application(urls, globals())
app.run()
else:
#mod_wsgi
app = web.application(urls, globals(), autoreload=False)
application = app.wsgifunc()