-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.py
More file actions
35 lines (28 loc) · 962 Bytes
/
server.py
File metadata and controls
35 lines (28 loc) · 962 Bytes
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
from flask import Flask
from flask import render_template
from flask import send_from_directory
import jinja2
import json
from os import listdir
from os.path import isfile, join
app = Flask(__name__)
LIB_DIRECTORY = './lib/'
@app.route('/')
def index():
libraries = [ dir for dir in listdir(LIB_DIRECTORY) if not isfile(join(LIB_DIRECTORY, dir))]
libraries = map(getName, libraries)
return render_template('./index.html', libraries=libraries)
@app.route('/lib/<lib>/<file>')
def library(lib, file):
return send_from_directory('lib', '{0}/{1}'.format(lib, file))
@app.route('/cheatsheet')
def cheatsheet():
return send_from_directory('documents', 'LogicFactoryCheatSheet.pdf')
def getName(file):
path = '{0}{1}/{1}_lib.json'.format(LIB_DIRECTORY, file)
print path
with open(path) as data_file:
data = json.load(data_file)
return file, data['library_name']
if __name__ == "__main__":
app.run(debug=True)