-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
79 lines (55 loc) · 1.7 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
75
76
77
78
79
import os, json, requests, time, sys
from bottle import route, run, template, static_file, redirect, request, response, put, post, get, error
from search import searchDatabase
from database import Database
dev = False
try:
database = Database(file='./database/wikiLinks.sqlite')
print('**** Found deployment database ****')
except:
database = Database(file='./database/wikiLinksDev.sqlite')
dev = True
if '-dev' in sys.argv:
dev = True
if dev:
print('**** Running in development mode ****')
@route('/')
def rootDir():
redirect('/wikiRace')
@error(404)
def error404(error):
return template('error404')
@route('/wikiRace/static/<filepath:path>')
def server_static(filepath):
return static_file(filepath, root='./assets')
@route('/wikiRace')
def index():
return template('race')
@route('/wikiRace/search', method='POST')
def search():
try:
data = json.loads(request.body.read().decode("utf-8"))
except Exception as e:
print(e)
routes = []
end = data['end']
start = data['start']
initialTime = time.time()
result = searchDatabase(database, start[1], end[1])
for route in result:
temp = []
for pageID in route:
temp.append(database.getPageName(pageID).replace('\'', '')) # replaced '[1:]' with '.replace()' as only linux has the extra inverted comma problem
routes.append(temp)
routes.insert(0, time.time() - initialTime)
return json.dumps(routes)
if __name__ == '__main__':
port = int(os.environ.get('PORT', 3100))
ip = '127.0.0.1'
run(host=ip, port=port, debug=True, reloader=True)
'''
TODO
some inputs (such as assassins creed) dont fill box with right name and get wrong id
desanetise inputs
button to swap start and end?
'''