This repository has been archived by the owner on Mar 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
executable file
·65 lines (47 loc) · 1.79 KB
/
main.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
#!/usr/bin/env python
import json
from os import getenv
from pathlib import Path
import uvicorn
from fastapi import FastAPI
from starlette.staticfiles import StaticFiles
from readme_tool import figshare, intake_form
app = FastAPI()
def configure():
app.mount("/templates", StaticFiles(directory="templates"), name="templates")
configure_routing()
configure_api()
def configure_routing():
app.include_router(figshare.router)
app.include_router(intake_form.router)
def configure_api():
figshare_api_key = getenv('FIGSHARE_API_KEY')
figshare_stage_api_key = getenv('FIGSHARE_STAGE_API_KEY')
if not figshare_api_key or not figshare_stage_api_key:
settings_file = 'settings.json'
file = Path(settings_file).absolute()
if not file.exists():
err_msg = "file not found; please see settings_template.json"
print(f"WARNING: {file} {err_msg}")
raise Exception(f"{settings_file} {err_msg}")
with open(file) as fin:
settings = json.load(fin)
if not figshare_api_key:
print("WARNING: FIGSHARE_API_KEY not set as ENV variable. "
"Obtaining from settings.json")
figshare_api_key = settings.get('figshare_api_key')
else:
print("FIGSHARE_API_KEY set as ENV variable.")
if not figshare_stage_api_key:
print("WARNING: FIGSHARE_STAGE_API_KEY not set as ENV variable. "
"Obtaining from settings.json")
figshare_stage_api_key = settings.get('figshare_stage_api_key')
else:
print("FIGSHARE_STAGE_API_KEY set as ENV variable")
figshare.api_key = figshare_api_key
figshare.stage_api_key = figshare_stage_api_key
if __name__ == "__main__":
configure()
uvicorn.run('main:app', port=8000, reload=True)
else:
configure()