aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorBonfaceKilz2020-11-03 21:59:49 +0300
committerBonfaceKilz2020-11-03 21:59:49 +0300
commita7622fc3d996407799cec166968c1e56baf07ea9 (patch)
treed055232527091024993c0dfde3478c902a80d3c6 /wqflask
parentb526fc6f6b6f450e169c01db5ffea92f94512393 (diff)
downloadgenenetwork2-a7622fc3d996407799cec166968c1e56baf07ea9.tar.gz
Move logic for fetching md files to it's own function
* wqflask/wqflask/markdown_routes.py (render_markdown): New function. (glossary): use render_markdown function.
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/markdown_routes.py31
1 files changed, 20 insertions, 11 deletions
diff --git a/wqflask/wqflask/markdown_routes.py b/wqflask/wqflask/markdown_routes.py
index e7e3c33e..33092947 100644
--- a/wqflask/wqflask/markdown_routes.py
+++ b/wqflask/wqflask/markdown_routes.py
@@ -2,6 +2,7 @@
Render pages from github, or if they are unavailable, look for it else where
"""
+import os
import requests
import mistune
@@ -11,19 +12,27 @@ from flask import render_template
glossary_blueprint = Blueprint('glossary_blueprint', __name__)
-@glossary_blueprint.route('/')
-def glossary():
- markdown_url = ("https://raw.githubusercontent.com"
- "/genenetwork/genenetwork2/"
- "wqflask/wqflask/static"
- "/glossary.md")
+def render_markdown(file_name):
+ """Try to fetch the file name from Github and if that fails, try to
+look for it inside the file system
+
+ """
+ markdown_url = (f"https://raw.githubusercontent.com"
+ f"/genenetwork/genenetwork2/"
+ f"wqflask/wqflask/static/"
+ f"{file_name}")
md_content = requests.get(markdown_url)
if md_content.status_code == 200:
- return render_template(
- "glossary_html",
- rendered_markdown=mistune.html(
- md_content.content.decode("utf-8"))), 200
+ return mistune.html(md_content.content.decode("utf-8"))
+
+ with open(os.path.join(os.path.abspath(os.path.dirname(__file__)),
+ f"static/markdown/{file_name}")) as md_file:
+ markdown = md_file.read()
+ return mistune.html(markdown)
+
+@glossary_blueprint.route('/')
+def glossary():
return render_template(
"glossary.html",
- rendered_markdown=mistune.html("# Github Down!")), 200
+ rendered_markdown=render_markdown("glossary.md")), 200