-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
43 lines (38 loc) · 1.5 KB
/
server.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
from flask import Flask, render_template, redirect, request, session
import datetime
import random
app = Flask(__name__)
app.secret_key = 'abcdefghijklmnopqrstuvwxyz'
@app.route('/')
def index():
if 'gold' in session:
session['gold'] = session['gold']
else:
session['gold'] = 0
if 'append' not in session:
session['append'] = []
session['farm'] = random.randrange(10,20)
session['cave'] = random.randrange(5,10)
session['house'] = random.randrange(2,5)
session['casino'] = random.randrange(-50,50)
return render_template('index.html')
@app.route('/process_gold', methods=['POST'])
def gold():
if request.form['location'] == 'farm':
session['gold'] += session['farm']
session['append'].insert(0, "Gained " + str(session['farm']) + " from the farm. " + str(datetime.datetime.now()))
if request.form['location'] == 'cave':
session['gold'] += session['cave']
session['append'].insert(0, "Gained " + str(session['cave']) + " from the cave. " + str(datetime.datetime.now()))
if request.form['location'] == 'house':
session['gold'] += session['house']
session['append'].insert(0, "Gained " + str(session['house']) + " from the house " + str(datetime.datetime.now()))
if request.form['location'] == 'casino':
session['gold'] += session['casino']
session['append'].insert(0, str(session['casino']) + " from the casino " + str(datetime.datetime.now()))
return redirect('/')
@app.route('/reset')
def reset():
session.clear()
return redirect('/')
app.run(debug=True)