2021-06-29 19:54:51 +02:00
|
|
|
import flask
|
|
|
|
import urllib, json
|
|
|
|
import os
|
|
|
|
from update import *
|
|
|
|
|
2021-06-30 19:42:14 +02:00
|
|
|
# To add: server feedback (logging + capacity) using socket io in Flask
|
|
|
|
# https://towardsdatascience.com/how-to-add-on-screen-logging-to-your-flask-application-and-deploy-it-on-aws-elastic-beanstalk-aa55907730f
|
|
|
|
|
2021-06-29 19:54:51 +02:00
|
|
|
# Create the application.
|
|
|
|
APP = flask.Flask(__name__)
|
|
|
|
|
|
|
|
# ---
|
|
|
|
|
|
|
|
PROJECT_NAME = 'volumetric-regimes'
|
|
|
|
DIR_PATH = '.' # without trailing slash
|
|
|
|
PORTNUMBER = 5522
|
|
|
|
WIKI = 'https://possiblebodies.constantvzw.org/book' # remove tail slash '/'
|
|
|
|
PAGENAME = 'Unfolded'
|
2021-09-01 16:57:49 +02:00
|
|
|
STYLESHEET_PAD = 'volumetric-regimes.css'
|
2021-09-01 13:15:22 +02:00
|
|
|
STYLESHEET = 'print.css'
|
2021-06-29 19:54:51 +02:00
|
|
|
|
|
|
|
# ---
|
|
|
|
|
|
|
|
|
2021-10-13 14:26:23 +02:00
|
|
|
def download_stylesheet():
|
2021-06-29 19:54:51 +02:00
|
|
|
# using etherpump
|
2021-09-01 16:57:49 +02:00
|
|
|
os.system(f'{ DIR_PATH }/venv/bin/etherpump gettext { STYLESHEET_PAD } > { DIR_PATH }/static/css/{ STYLESHEET }')
|
2021-06-29 19:54:51 +02:00
|
|
|
|
|
|
|
@APP.route('/', methods=['GET'])
|
|
|
|
def pad():
|
|
|
|
if not os.path.exists(f'{ DIR_PATH }/static/Unfolded.html'):
|
2021-10-13 14:26:23 +02:00
|
|
|
download_stylesheet() # download the stylesheet pad
|
2021-06-29 19:54:51 +02:00
|
|
|
publication_unfolded = update_material_now(PAGENAME, WIKI) # download the latest version of the page
|
|
|
|
with open(f'{ DIR_PATH }/static/Unfolded.html', 'w') as out:
|
|
|
|
out.write(publication_unfolded) # save the html (without <head>) to file
|
|
|
|
else:
|
|
|
|
publication_unfolded = open(f'{ DIR_PATH }/static/Unfolded.html', 'r').read()
|
|
|
|
|
2021-10-13 14:26:23 +02:00
|
|
|
return flask.render_template('index.html', title=PROJECT_NAME)
|
2021-06-29 19:54:51 +02:00
|
|
|
|
2021-06-30 19:42:14 +02:00
|
|
|
@APP.route('/notes/', methods=['GET'])
|
|
|
|
def notes():
|
2021-10-13 14:26:23 +02:00
|
|
|
return flask.render_template('notes.html')
|
2021-06-30 19:42:14 +02:00
|
|
|
|
2021-06-29 19:54:51 +02:00
|
|
|
@APP.route('/update/', methods=['GET', 'POST'])
|
|
|
|
def update():
|
|
|
|
publication_unfolded = update_material_now(PAGENAME, WIKI) # download the latest version of the page
|
2021-10-13 14:26:23 +02:00
|
|
|
save(publication_unfolded, 'Unfolded') # save the html to file (without <head>) to file
|
2021-06-29 19:54:51 +02:00
|
|
|
|
2021-10-13 14:26:23 +02:00
|
|
|
return flask.render_template('index.html', title=PROJECT_NAME)
|
2021-06-29 19:54:51 +02:00
|
|
|
|
|
|
|
@APP.route('/pagedjs/', methods=['GET', 'POST'])
|
|
|
|
def pagedjs():
|
2021-10-13 14:26:23 +02:00
|
|
|
download_stylesheet() # download the stylesheet pad
|
2021-06-29 19:54:51 +02:00
|
|
|
publication_unfolded = open(f'{ DIR_PATH }/static/Unfolded.html', 'r').read()
|
|
|
|
|
2021-10-13 14:26:23 +02:00
|
|
|
return flask.render_template('pagedjs.html', publication_unfolded=publication_unfolded)
|
2021-06-29 19:54:51 +02:00
|
|
|
|
|
|
|
@APP.route('/inspect/', methods=['GET', 'POST'])
|
|
|
|
def inspect():
|
2021-10-13 14:26:23 +02:00
|
|
|
download_stylesheet() # download the stylesheet pad
|
2021-06-29 19:54:51 +02:00
|
|
|
publication_unfolded = open(f'{ DIR_PATH }/static/Unfolded.html', 'r').read()
|
|
|
|
|
2021-10-13 14:26:23 +02:00
|
|
|
return flask.render_template('inspect.html', publication_unfolded=publication_unfolded)
|
2021-06-29 19:54:51 +02:00
|
|
|
|
|
|
|
@APP.route('/stylesheet/', methods=['GET'])
|
|
|
|
def stylesheet():
|
2021-10-13 14:26:23 +02:00
|
|
|
return flask.render_template('stylesheet.html')
|
2021-06-29 19:54:51 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
APP.debug=True
|
|
|
|
APP.run(port=f'{ PORTNUMBER }')
|