-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathweb.py
More file actions
63 lines (41 loc) · 1.35 KB
/
web.py
File metadata and controls
63 lines (41 loc) · 1.35 KB
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
"""
Mount Olympus web scraping example project for Real Python
https://realpython.com
"""
from datetime import datetime
import random
import bottle
@bottle.route('/')
def root():
return bottle.redirect('/login')
@bottle.route('/login')
def login():
return bottle.template('views/login.html')
@bottle.route('/login', method='POST')
def submit_login():
username = bottle.request.forms.get('user')
password = bottle.request.forms.get('pwd')
if username == 'zeus' and password == 'ThunderDude':
return bottle.redirect('/profiles')
return bottle.template('views/login_failed.html')
@bottle.route('/static/<filepath:path>')
def serve_static(filepath):
return bottle.static_file(filepath, root='static/')
@bottle.route('/profiles')
def profiles():
return bottle.template('views/profiles.html')
@bottle.route('/profiles/aphrodite')
def aphrodite():
return bottle.template('views/aphrodite.html')
@bottle.route('/profiles/poseidon')
def poseidon():
return bottle.template('views/poseidon.html')
@bottle.route('/profiles/dionysus')
def dionysus():
return bottle.template('views/dionysus.html')
@bottle.route('/dice')
def dice():
result = random.randint(1, 6)
time = datetime.now().strftime("%B %d, %Y %I:%M:%S%p")
return bottle.template('views/dice.html', random=result, time=time)
app = bottle.default_app()