forked from VHP4Safety/ui-design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
209 lines (161 loc) · 7.89 KB
/
app.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
################################################################################
### Loading the required modules
from flask import Flask, request, jsonify, render_template, send_file, Blueprint, render_template, abort
import requests
from wikidataintegrator import wdi_core
import json
import re
from werkzeug.routing import BaseConverter
from jinja2 import TemplateNotFound
################################################################################
class RegexConverter(BaseConverter):
"""Converter for regular expression routes.
References
----------
Scholia views.py
https://stackoverflow.com/questions/5870188
"""
def __init__(self, url_map, *items):
"""Set up regular expression matcher."""
super(RegexConverter, self).__init__(url_map)
self.regex = items[0]
app = Flask(__name__)
################################################################################
### The landing page
@app.route('/')
def home():
return render_template('home.html')
################################################################################
################################################################################
### Pages under 'Project Information'
@app.route('/information/mission_and_vision')
def mission_and_vision():
return render_template('information/mission_and_vision.html')
@app.route('/information/research_lines')
def research_lines():
return render_template('information/research_lines.html')
@app.route('/case_studies_and_regulatory_questions')
def case_studies_and_regulatory_questions():
return render_template('information/case_studies_and_regulatory_questions.html')
@app.route('/information/partners_and_consortium')
def partners_and_consortium():
return render_template('information/partners_and_consortium.html')
@app.route('/information/contact')
def contact():
return render_template('information/contact.html')
@app.route('/youp')
def youp():
return render_template('case_studies/thyroid/youp.html')
################################################################################
################################################################################
### Pages under 'Services'
# Page to list all the services based on the list of services on the cloud repo.
@app.route('/templates/services/service_list')
def service_list():
# Github API link to receive the list of the services on the cloud repo:
url = f'https://api.github.com/repos/VHP4Safety/cloud/contents/docs/service'
response = requests.get(url)
# Checking if the request was successful (status code 200).
if response.status_code == 200:
# Extracting the list of files.
service_content = response.json()
# Separating .json and .md files.
json_files = {file['name']: file for file in service_content if file['type'] == 'file' and file['name'].endswith('.json')}
md_files = {file['name']: file for file in service_content if file['type'] == 'file' and file['name'].endswith('.md')}
png_files = {file['name']: file for file in service_content if file['type'] == 'file' and file['name'].endswith('.png')}
# Creating an empty list to store the results.
services = []
# Fetching the .json files.
for json_file_name, json_file in json_files.items():
# Skipping the template.json file.
if json_file_name == 'template.json':
continue
json_url = json_file['download_url'] # Using the download URL from the API response.
json_response = requests.get(json_url)
if json_response.status_code == 200:
json_data = json_response.json()
# Extracting the 'service' field from the json file.
service_name = json_data.get('service')
description_string = json_data.get('description')
if service_name:
# Replacing the .json extension with the .md to get the corresponding .md file.
md_file_name = json_file_name.replace('.json', '.md')
html_name = json_file_name.replace('.json', '.html')
url = "https://cloud.vhp4safety.nl/service/"+ html_name
if md_file_name in md_files:
md_file_url = f'https://raw.githubusercontent.com/VHP4Safety/cloud/main/docs/service/{md_file_name}'
else:
md_file_url = "md file not found"
png_file_name = md_file_name.replace('.md', '.png')
if png_file_name in png_files:
png_file_url = f'https://raw.githubusercontent.com/VHP4Safety/cloud/main/docs/service/{png_file_name}'
services.append({
'service': service_name,
'url': url,
'meta_data': md_file_url,
'description': description_string,
'png': png_file_url
})
else:
services.append({
'service': service_name,
'url': url,
'meta_data': md_file_url,
'description': description_string,
'png': "../../static/images/logo.png"
})
# Passing the services data to the template after processing all JSON files.
return render_template('services/service_list.html', services=services)
else:
return f"Error fetching files: {response.status_code}"
# return render_template('services/service_list.html')
@app.route('/templates/services/qsprpred')
def qsprpred():
return render_template('services/qsprpred.html')
################################################################################
################################################################################
### Pages under 'Case Studies'
@app.route('/templates/case_studies/kidney/kidney')
def kidney_main():
return render_template('case_studies/kidney/kidney.html')
@app.route('/case_studies/parkinson/parkinson')
def parkinson_main():
return render_template('case_studies/parkinson/parkinson.html')
@app.route("/services/qAOPapp")
def qaop_app():
return render_template("services/qAOPapp.html")
@app.route('/case_studies/parkinson/workflows/parkinson_qAOP')
def parkinson_qaop():
return render_template('case_studies/parkinson/workflows/parkinson_qAOP.html')
@app.route("/case_studies/thyroid/workflows/thyroid_qAOP")
def thyroid_qaop():
return render_template("case_studies/thyroid/workflows/thyroid_qAOP.html")
@app.route('/workflow/<workflow>')
def show(workflow):
try:
return render_template(f'case_studies/parkinson/workflows/{workflow}_workflow.html')
except TemplateNotFound:
abort(404)
@app.route('/compound/<cwid>')
def show_compound(cwid):
try:
return render_template(f'compound.html', cwid=cwid)
except TemplateNotFound:
abort(404)
@app.route('/templates/case_studies/thyroid/thyroid')
def thyroid_main():
return render_template('case_studies/thyroid/thyroid.html')
@app.route('/templates/case_studies/thyroid/workflows/thyroid_hackathon_demo_workflow')
def thyroid_workflow_1():
return render_template('case_studies/thyroid/workflows/thyroid_hackathon_demo_workflow.html')
@app.route('/templates/case_studies/thyroid/workflows/ngra_silymarin')
def ngra_silymarin():
return render_template('case_studies/thyroid/workflows/ngra_silymarin.html')
################################################################################
# Import the new blueprint
from routes.aop_app import aop_app
# Register the blueprint
app.register_blueprint(aop_app)
################################################################################
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)