from flask import *
from random import randint
from flask_mysqldb import MySQL
app = Flask(__name__)


app.config['MYSQL_HOST'] = 'euclid.nmu.edu'
app.config['MYSQL_USER'] = 'nations'
app.config['MYSQL_PASSWORD'] = 'nations!'
app.config['MYSQL_DB'] = 'nations'

mysql = MySQL(app)

win=0
total=0
@app.route("/yes")
def yes():
   global win, total
   win += 1
   total += 1
   return redirect("/")

@app.route("/no")
def no():
   global win, total
   total += 1
   return redirect("/")

@app.route('/')
def index():
   global win, total
   cur = mysql.connection.cursor()
   cur.execute("select name, code from nations order by rand() limit 4")
   data = cur.fetchall()
   print(data)
   question = randint(0,3)
   #url = f"https://www.worldometers.info/img/flags/small/tn_" + data[0][1]+"-flag.gif"
   #return f"<img src={url}>"
   return render_template("quiz.html", data=data, question=question, win=win, total=total)

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