from flask import Flask, render_template, session, request, redirect
import random

app = Flask(__name__)
app.secret_key = 'my_secret_key'

@app.route('/')
def index():
    if not 'gold' in session:
        session['gold'] = 0
    if not 'activities' in session:
        session['activities'] = []
    return render_template('index.html', your_gold = session['gold'])

@app.route('/process_money', methods = ['POST'])
def process():
    buildings = {
        'farm':random.randint(10,20),
        'casino':random.randint(-50,50),
        'cave':random.randint(2,5),
        'house':random.randint(2,5)
    }
    if request.form['building'] in buildings:
        """ OMG What???"""
        result = buildings[ request.form['building'] ]
        session['gold'] = session['gold']+result
        result_dictionary = {
                                'class': ('red','green')[result > 0],
                                'activity': "You went to the {} and {} {} gold!".format(request.form['building'], ('lost','gained')[result > 0], result)
                            }
        session['activities'].append(result_dictionary)
    return redirect('/')


if __name__ == '__main__':
  app.run(debug = True)
