forked from JIMhackKING/LOL-Live
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsgi.py
77 lines (64 loc) · 1.65 KB
/
wsgi.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
75
76
77
from bottle import (route, static_file, default_app, error, request,
redirect)
import leancloud
import storage
from jinja2 import Environment, FileSystemLoader
from leancloud import Engine
loader = FileSystemLoader("./views")
env = Environment(loader=loader)
VERSION = 'v2.1'
@route("/<filepath:path>")
def assets(filepath):
return static_file(filepath, root="./static")
@error(404)
def page404(error):
template = env.get_template("404.html")
content = template.render()
return content
@route("/")
def main():
page = request.query.page or "1"
page = int(page)
skip = (page - 1) * 60
limit = page * 60
query = storage.Query()
template = env.get_template("home.html")
try:
datas = query.datas[skip:limit]
except IndexError:
return redirect("/")
else:
if not datas:
return redirect("/")
content = template.render(datas=datas, version=VERSION)
return content
@route('/mobile')
def mobile():
page = request.query.page or "1"
page = int(page)
skip = (page - 1) * 60
limit = page * 60
query = storage.Query()
template = env.get_template("mobile.html")
try:
datas = query.datas[skip:limit]
except IndexError:
return redirect("/mobile")
content = template.render(datas=datas)
return content
application = Engine(default_app())
@application.define
def update(**kwargs):
fetcher = storage.Fetch()
query = storage.Query()
query.cleanData()
fetcher.fetch_all()
storage.Fetch.Live.save_all(fetcher.lives[:120])
@application.define
def change_version(version, **kwargs):
global VERSION
VERSION = version
if __name__ == '__main__':
from leancloud import cloudfunc
cloudfunc.run("change_version", version='v2.1')
# cloudfunc.run("update")