-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (47 loc) · 1.45 KB
/
main.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
from flask import Flask, render_template, request, g, session, redirect
import BF_Machine
import re
app = Flask(__name__)
app.secret_key = 'FUCK YOU SHOULD NOT BE SEEING THIS'
@app.route('/BFD', methods=['GET', 'POST'])
def BFD():
if request.method == "GET":
session['pc'] = -1
return render_template("BFDIN.html")
else:
noPost = False
if session['pc'] == -1:
#first time, grab code
session['code'] = request.form['code']
try:
session['code'][0]
except:
return redirect("/BFD")
session['pc'] = 0
session['scroll'] = 0
noPost = True
machine = BF_Machine.Machine(80)
success = machine.loadCode(session['code'])
if not success:
return redirect("/BFD")
#get back to old state
machine.runFor(session['pc'])
if noPost == False:
if request.form["post"] == "step+":
machine.step()
elif request.form["post"] == "step-":
reset = session['pc'] - 1
machine = BF_Machine.Machine(80)
machine.loadCode(session['code'])
machine.runFor(reset)
elif request.form["post"] == "skip":
machine.skipLoop()
elif request.form["post"] == "run":
machine.run()
elif request.form["post"] == "next":
machine.nextLoop(True)
session['pc'] = machine.cycles
session['scroll'] = request.form['scroll']
return render_template('BFD.html', code=machine.codeToHTML(), console=machine.consoleToHTML(), memory=machine.memoryToHTML(), scroll=session['scroll'])
if __name__ == '__main__':
app.run(debug=True)