-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreport_county_trends.py
94 lines (78 loc) · 2.37 KB
/
report_county_trends.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
"""
Create the CA cases trends report as HTML and upload to GitHub.
"""
import base64
import datetime
import os
import subprocess
import sys
import time
import pandas as pd
import papermill as pm
from processing_utils import github_utils as gh
from processing_utils import default_parameters
sys.path.append(os.getcwd())
#Turn off warning messages
import warnings
warnings.simplefilter('ignore')
#Only see the first warning
#warnings.filterwarnings(action='once')
# Constants for loading the file to GH Pages branch
TOKEN = os.environ["GITHUB_TOKEN_PASSWORD"]
REPO = "CityOfLosAngeles/covid19-indicators"
BRANCH = "gh-pages"
CURRENT_BRANCH=default_parameters.CURRENT_BRANCH
env_list=dict(os.environ)
search_str=CURRENT_BRANCH + "_env_PUBLISH_PATH"
if search_str in env_list:
PUBLISH_PATH=os.environ[search_str]
else:
PUBLISH_PATH="test_branch/"
DEFAULT_COMMITTER = {
"name": "Los Angeles ITA data team",
"email": "[email protected]",
}
notebooks_to_run = {
"ca-counties.ipynb": "./ca-county-trends.ipynb",
"us-counties.ipynb": "./us-county-trends.ipynb",
"la-neighborhoods.ipynb": "./la-neighborhoods-trends.ipynb",
"coronavirus-stats.ipynb": './coronavirus-stats.ipynb',
}
for key, file_name in notebooks_to_run.items():
try:
print(f"Running notebook {key}")
pm.execute_notebook(
f'/app/notebooks/{key}',
file_name,
cwd='/app/notebooks',
log_output=True
)
print(f"Ran notebook {key}")
# shell out, run NB Convert
output_format = 'html'
subprocess.run([
"jupyter",
"nbconvert",
"--to",
output_format,
"--no-input",
"--no-prompt",
file_name,
])
print("Converted to HTML")
# Now find the HTML file and upload
name = file_name.replace(".ipynb", "").replace("./", "")
html_file_name = f"{name}.html"
print(f"name: {name}")
print(f"html name: {PUBLISH_PATH}{html_file_name}")
gh.upload_file(
TOKEN,
REPO,BRANCH,
f"{html_file_name}",
f"{PUBLISH_PATH}{html_file_name}",
f"Update {name}",
DEFAULT_COMMITTER)
print("Successful upload to GitHub")
except:
print(f"Unsuccessful upload of {key}")
pass