-
Notifications
You must be signed in to change notification settings - Fork 1
/
code.py
executable file
·66 lines (58 loc) · 1.83 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import web
web.config.debug = False
db = web.database(dbn='sqlite', db='verycd.sqlite3.db')
urls = (
'/', 'index',
)
render = web.template.render('templates/')
app = web.application(urls, globals())
class index:
def GET(self):
i = web.input(id=None,page='1',q=None,download=None)
if i.id:
myvar = dict(id=i.id)
rec = db.select('verycd',vars=myvar,where="verycdid=$id")
for r in rec:
fl = None
if i.download:
links = r['ed2k'].split('`')
links = [ x for x in links if 'ed2k:' in x ]
fl = '<br>\n'.join(links)
return render.id([r,fl,str(r['verycdid'])])
return render.error(404)
else:
if not i.q:
vc = db.select('verycd',order='updtime DESC',limit=20,offset=20*(int(i.page)-1))
num = db.select('verycd',what="count(*) as count")[0].count
arg = '/?page'
else:
qs = i.q.split(' ')
qs = [ 'title like \'%'+x+'%\'' for x in qs ]
where = ' and '.join(qs)
vc = db.select('verycd',order='updtime DESC',limit=20,\
offset=20*(int(i.page)-1),where=where)
num = db.select('verycd',what="count(*) as count",where=where)[0].count
arg = '/?q='+i.q+'&page'
prev = int(i.page)-1 == 0 and '1' or str(int(i.page)-1)
next = int(i.page)+1 <= (num-1)/20+1 and str(int(i.page)+1) or i.page
end = str((num-1)/20+1)
pages = [prev,next,end]
left = min(4,int(i.page)-1)
right = min(4,int(end)-int(i.page))
if left < 4:
right = min(8-left,int(end)-int(i.page))
if right < 4:
left = min(8-right,int(i.page)-1)
while left > 0:
pages.append(str(int(i.page)-left))
left -= 1
j = 0
while j <= right:
pages.append(str(int(i.page)+j))
j += 1
return render.index([vc,pages,arg,i.q,num])
if __name__ == "__main__":
web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
app.run()