-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
57 lines (39 loc) · 1.8 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
# to run this (lol)
# export FLASK_APP=server.py
# export FLASK_ENV=development
# flask run
# todo: see if we can make these into one line of code
from flask import Flask
from flask import render_template
import os
app = Flask(__name__)
def renderIDE(folderName, fileName):
codeStuff = []
for tempSubFolder in os.listdir('code/'):
if os.path.isdir(os.path.join('code/', tempSubFolder)):
# tempSubFolder is the directory name
# find the files for the tempSubFolder and load into tempfiles
tempFiles = []
for file in os.listdir("code/" + tempSubFolder + "/"):
tempFiles.append(file)
# add a dictionary of the folder name and the files into codeStuff
codeStuff.append({"dirName": tempSubFolder, "files": tempFiles})
with open('code/'+ folderName.capitalize() + '/' + fileName) as file:
fileContent = file.read()
return render_template('render-files.html', files=codeStuff, folderName=folderName, fileName=fileName, fileContent=fileContent)
@app.route('/')
def home():
codeStuff = []
for tempSubFolder in os.listdir('code/'):
if os.path.isdir(os.path.join('code/', tempSubFolder)):
# tempSubFolder is the directory name
# find the files for the tempSubFolder and load into tempfiles
tempFiles = []
for file in os.listdir("code/" + tempSubFolder + "/"):
tempFiles.append(file)
# add a dictionary of the folder name and the files into codeStuff
codeStuff.append({"dirName": tempSubFolder, "files": tempFiles})
return render_template("home.html", files=codeStuff)
@app.route('/<folder>/<file>')
def specificProject(folder=None, file=None):
return renderIDE(folder, file)