File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ # -*- coding: utf-8 -*-
3+
4+ __author__ = 'Michael Liao'
5+
6+ '''
7+ A WSGI application entry.
8+ '''
9+
10+ import logging ; logging .basicConfig (level = logging .INFO )
11+
12+ import os , time
13+ from datetime import datetime
14+
15+ from transwarp import db
16+ from transwarp .web import WSGIApplication , Jinja2TemplateEngine
17+
18+ from config import configs
19+
20+ def datetime_filter (t ):
21+ delta = int (time .time () - t )
22+ if delta < 60 :
23+ return u'1分钟前'
24+ if delta < 3600 :
25+ return u'%s分钟前' % (delta // 60 )
26+ if delta < 86400 :
27+ return u'%s小时前' % (delta // 3600 )
28+ if delta < 604800 :
29+ return u'%s天前' % (delta // 86400 )
30+ dt = datetime .fromtimestamp (t )
31+ return u'%s年%s月%s日' % (dt .year , dt .month , dt .day )
32+
33+ # init db:
34+ db .create_engine (** configs .db )
35+
36+ # init wsgi app:
37+ wsgi = WSGIApplication (os .path .dirname (os .path .abspath (__file__ )))
38+
39+ template_engine = Jinja2TemplateEngine (os .path .join (os .path .dirname (os .path .abspath (__file__ )), 'templates' ))
40+ template_engine .add_filter ('datetime' , datetime_filter )
41+
42+ wsgi .template_engine = template_engine
43+
44+ import urls
45+
46+ wsgi .add_interceptor (urls .user_interceptor )
47+ wsgi .add_interceptor (urls .manage_interceptor )
48+ wsgi .add_module (urls )
49+
50+ if __name__ == '__main__' :
51+ wsgi .run (9000 , host = '0.0.0.0' )
You can’t perform that action at this time.
0 commit comments