-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflask_server.py
executable file
·72 lines (56 loc) · 2.95 KB
/
flask_server.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
"""This file is the main module which contains the app.
"""
import click
from app import create_app
from decouple import config
from app.api import ltc, aggregate_outbreaks, close_outbreaks, data_quality_checks, \
unreset_cumulative, process as process_module
import config as configs
# Figure out which config we want based on the `ENV` env variable
env_config = config("ENV", cast=str, default="develop")
config_dict = {
'production': configs.Production,
'develop': configs.Develop,
'testing': configs.Testing,
}
app = create_app(config_dict[env_config]())
# for production, require a real SECRET_KEY to be set
if env_config == 'production':
assert app.config['SECRET_KEY'] != "12345", "You must set a secure SECRET_KEY"
@app.cli.command()
def deploy():
"""Run deployment tasks."""
return # we have no deployment tasks
@app.cli.command("process")
@click.option('--states', default='ALL', help='State abbreviations to run for, e.g. "ME,DE"')
@click.option('--overwrite-final-gsheet', is_flag=True)
@click.option('--out-sheet-url', default='',
help='Write the processed data to the specified Google Sheet url')
@click.option('--outdir', default='',
help='Write the processed data to a CSV file in this local directory')
def process(states, overwrite_final_gsheet, out_sheet_url, outdir):
"""Process all data from the entry sheet in the input states as defined in the Sheet of Sheets.
States is expected to be a comma-separated list of state abbreviations like "ME,DE". If this
option isn't present, the functions will be run for every single state that
has any scripts defined.
The processing functions applied to each state are defined in app/api/process.py.
The resulting output can be saved to the final sheet defined in the Sheet of Sheets
(--write-to-gsheets), to a specified sheet url (--out-sheet-url), or as a CSV to a local
directory (--outdir).
"""
process_module.cli_process_state(states, overwrite_final_gsheet=overwrite_final_gsheet,
out_sheet_url=out_sheet_url, outdir=outdir)
@app.cli.command("check")
@click.option('--states', default='ALL', help='State abbreviations to run for, e.g. "ME,DE"')
@click.option('--outdir', default='',
help='Write the erroring rows to a CSV file in this local directory')
@click.option('--use-local-files', is_flag=True,
help='If present, will read the outputs from "<outdir>/*_processed.csv" instead of sheets')
def check(states, outdir, use_local_files):
"""Checks all data from the final sheet in the input states as defined in the Sheet of Sheets.
States is expected to be a comma-separated list of state abbreviations like "ME,DE". If this
option isn't present, checks will be run for every single state that has any scripts defined.
The resulting output if any duplicate outbreak rows exist are saved as a CSV to a local
directory (--outdir).
"""
process_module.cli_check_state(states, outdir=outdir, use_local_files=use_local_files)