-
Notifications
You must be signed in to change notification settings - Fork 0
/
rawgs_to_riches.py
71 lines (62 loc) · 2.29 KB
/
rawgs_to_riches.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
import market
from flask import Flask, session, render_template, request, redirect, url_for, flash
app = Flask(__name__)
# Sam's first comment
@app.route('/')
def index():
"""the homepage"""
player = None
if 'username' in session:
if session['username'] not in market.players:
flash('Invalid username. You have been logged out')
return redirect(url_for('logout'))
player = market.players[session['username']]
return render_template('index.html', player=player)
@app.route('/update', methods=['GET', 'POST'])
def update():
"""update a player's info"""
if 'username' not in session:
flash('You must log in first.')
return redirect(url_for('login'))
if session['username'] not in market.players:
flash('Invalid username. You have been logged out')
return redirect(url_for('logout'))
player = market.players[session['username']]
try:
player.update(**{field: int(request.form[field]) for field in ['rawg_demand', 'rawg_price', 'rig_supply', 'rig_price']})
except ValueError as e:
flash(e.message)
return redirect(url_for('index'))
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
username = request.form['username']
if not username: # empty string is not allowed
flash('Invalid username.')
return redirect(url_for('login'))
if username in market.players:
flash('That username is already taken.')
return redirect(url_for('login'))
else:
market.add_player(username)
session['username'] = request.form['username']
return redirect(url_for('index'))
# request.method == 'GET'
if 'username' in session: # already logged in
return redirect(url_for('index'))
return render_template('login.html')
@app.route('/logout')
def logout():
# remove the username from the session if it's there
session.pop('username', None)
return redirect(url_for('index'))
# Build in a troubleshooting page.
@app.route('/troubleshoot')
def troubleshoot():
wholemarket = market
return render_template('troubleshoot.html',market = wholemarket)
if __name__ == '__main__':
import os
app.secret_key = os.urandom(24)
app.debug = True
app.run()