-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathwebsite.py
67 lines (52 loc) · 1.63 KB
/
website.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
from configparser import SafeConfigParser
from bottle import route, run, template, static_file, redirect
from pymongo import MongoClient
config = SafeConfigParser()
config.read('config.ini')
db = MongoClient()[config.get('mongodb', 'db_name')]
register_count = 0
@route('/')
def index():
domains = [ d['domain'] for d in db.domains.find({'status': 'inactive'})
.sort('length').limit(30) ]
purchased = [ d['domain'] for d in
db.domains.find({'purchased_this_week': True}) ]
return template(
'index',
page=1,
domains=domains,
purchased=purchased
)
@route('/<page:re:\d+>')
def page(page):
index = int(page) - 1
if index < 0:
return 'Out of range!'
domains = [ d['domain'] for d in db.domains.find({'status': 'inactive'})
.sort('length').skip(index * 30).limit(30) ]
purchased = [ d['domain'] for d in
db.domains.find({'purchased_this_week': True}) ]
return template(
'index',
page=int(page),
domains=domains,
purchased=purchased
)
@route('/register/:domain')
def register(domain):
global register_count
register_count += 1
# for Domainr API access
if register_count >= 5:
redirect(config.get('register', 'domainr').replace('{{d}}', domain))
register_count = 0
else:
redirect(config.get('register', '101domain').replace('{{d}}', domain))
register_count += 1
@route('/static/<fn>')
def static(fn):
return static_file(fn, root='static')
def main():
run(host='localhost', port=3000)
if __name__ == '__main__':
main()