-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
29 lines (22 loc) · 979 Bytes
/
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
import os
import requests
import uuid
from flask import Flask, request, redirect, render_template
from markdown import markdown
app = Flask(__name__)
GENESAPI_TABULAR_URL = os.getenv('GENESAPI_TABULAR_URL', 'https://tabular.genesapi.org')
GENESAPI_STATIC_DIR = os.getenv('GENESAPI_STATIC_DIR', 'tables')
GENESAPI_STATIC_URL = os.getenv('GENESAPI_STATIC_URL', '/tables')
@app.route('/')
def api():
if not request.args:
with open('./README.md') as f:
content = markdown(f.read())
return render_template('docs.html', content=content)
url = GENESAPI_TABULAR_URL + '/?' + request.query_string.decode()
res = requests.get(url)
file_ext = 'json' if 'json' in res.headers['Content-Type'] else 'csv'
table_name = '%s.%s' % (str(uuid.uuid4()).replace('-', ''), file_ext)
with open(os.path.join(GENESAPI_STATIC_DIR, table_name), 'w') as f:
f.write(res.text)
return redirect('%s/%s' % (GENESAPI_STATIC_URL, table_name))