-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
74 lines (61 loc) · 1.92 KB
/
app.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/env python
# -*- coding:utf-8 -*-
from bottle import run,\
route,\
Bottle,\
debug,\
jinja2_template,\
static_file,\
error,\
request
import sys
import codecs
import markdown
import settings
import os
import ip
import article
from paste import httpserver
import handleSta
application = Bottle()
debug(True)
@application.route('/')
def index():
art = os.listdir('./article')
give = []
instance = handleSta.handleSta()
instance.read()
for item in art:
path = './article/' + item
read = article.article(path)
instance.setValue(item, instance.getValue(item, 0) )
give.append([item, read.read_title() + ' (' + read.read_time() + u'浏览 ' + str(instance.getValue(item, 0)) + ')'])
give = sorted(give)[::-1]
getIp = ip.ip().getIpInfo()
instance.setValue('pv', instance.getValue('pv', 0) + 1)
instance.write()
return jinja2_template('templates/home.html', domain = settings.domain, users = give, ipInfo = getIp, pv = instance.getValue('pv', 0))
@application.route('/test')
def test():
return jinja2_template('templates/test.html', domain = settings.domain)
@application.route('/article/<artname>')
def func_article(artname):
instance = handleSta.handleSta()
instance.read()
instance.setValue(artname, instance.getValue(artname, 0) + 1)
instance.setValue('pv', instance.getValue('pv', 0) + 1)
instance.write()
read = article.article('./article/' + artname)
return read.read()
@application.route('/static/<filename:path>')
def static(filename):
return static_file(filename, root = './static')
@application.route('/aboutme')
def aboutme():
read = article.article('./special/aboutme.md')
return read.read()
@application.error(404)
def error404(error):
return'Nothing here, sorry'
if __name__ == '__main__':
httpserver.serve(application, host = settings.host, port = settings.port)