-
Notifications
You must be signed in to change notification settings - Fork 3
/
freeze_web.py
48 lines (35 loc) · 1.48 KB
/
freeze_web.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
import os
import json
from flask_frozen import Freezer
from app import app
freezer = Freezer(app)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
app.config['URL'] = "https://ccl.northwestern.edu/netlogo/bind"
with open(os.path.join(BASE_DIR, 'app/static/primitives.json'), 'r') as df:
primitivesJson = json.load(df)
primitivesViaJson = primitivesJson['primitives']
mdDir = os.path.join(BASE_DIR, 'app/static/md/')
primitivesViaMd = [filename[:-3] for filename in os.listdir(mdDir) if filename.endswith('.md')]
validPrimitives = [primitive for primitive in primitivesViaMd if primitive in primitivesViaJson]
@freezer.register_generator
def primitive():
for primitive in validPrimitives:
yield '/primitive/' + primitive + '.html'
articlesDir = os.path.join(BASE_DIR, 'app/static/articles')
articles = [filename[:-3] for filename in os.listdir(articlesDir) if filename.endswith('.md')]
@freezer.register_generator
def article():
for article in articles:
yield '/article/' + article + '.html'
with open(os.path.join(BASE_DIR, 'app/static/videos.json')) as videosJsonFile:
videosJson = json.load(videosJsonFile)
videoFiles = [video['href'] for video in videosJson['videos']]
validVideoNames = [video[:-4] for video in videoFiles if video.endswith('.mp4')]
@freezer.register_generator
def watch():
for video in validVideoNames:
yield '/watch/' + video + '.html'
if __name__ == '__main__':
#freezer.run(port=4141)
#yay
freezer.freeze()