-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
63 lines (52 loc) · 1.62 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from flask import Flask, render_template, redirect, request
from threading import Thread
from replit import db
from uuid import uuid4
from utils import coderun
URL = "http://scratch.si_abid.repl.co/bin"
app = Flask('')
app.config['SECRET_KEY'] = 'you-will-never-guess'
@app.route('/')
def home():
return "Hello, I am alive"
@app.route('/index')
def index():
posts = [
{
'author': {'username': 'Saiham'},
'body': 'First post in this page!'
}
]
if 'posts' in db.keys():
for post in db['posts']:
posts.append(post)
return render_template('index.html', title='Home', posts=posts)
@app.route('/bin', methods=['GET','POST'])
def bin():
if request.method=='POST':
user, code, lang, ptype, data = request.form['poster'], request.form['code'], request.form['syntax'], request.form['post_type'], request.form['data']
if ptype == 'run':
res = coderun(lang, code, data)[0]
if type(res)==str:
return render_template('mybin.html',user=user, code=code, output=res)
else:
return render_template('mybin.html',user=user, code='\n'.join(res))
filename=uuid4().hex
with open("./public/"+filename+'.txt',"w") as f:
f.write(user)
f.write('\n')
f.write(code)
return redirect('/mybin/'+filename)
return render_template('bin.html')
@app.route('/mybin/<name>')
def mybin(name):
loc='./public/'+name+'.txt'
file = open(loc,"r")
content = file.read()
user, code = content.split('\n',1)
return render_template('mybin.html',user=user, code=code)
def run():
app.run(host="0.0.0.0", port=8080)
def keep_alive():
t = Thread(target=run)
t.start()