Skip to content

Commit a7a8e6a

Browse files
authored
Merge pull request #263 from cmu-delphi/deploy-google_health
Propagate fix for #242 to main
2 parents 008bd9b + 3553e00 commit a7a8e6a

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

google_health/delphi_google_health/pull_api.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import pandas as pd
1212
import googleapiclient
1313
import googleapiclient.discovery
14+
from tenacity import retry, wait_fixed, stop_after_attempt
1415

1516
DISCOVERY_URL = "https://www.googleapis.com/discovery/v1/apis/trends/v1beta/rest"
1617
TERMS_IDS = "anosmia_ms"
@@ -80,7 +81,7 @@ def query(self, start_date: str, end_date: str, geo_id, dma=False) -> dict:
8081

8182
return data
8283

83-
84+
@retry(wait=wait_fixed(60), stop = stop_after_attempt(5))
8485
def get_counts_states(
8586
ght: GoogleHealthTrends,
8687
start_date: str,
@@ -127,7 +128,7 @@ def get_counts_states(
127128

128129
return state_df
129130

130-
131+
@retry(wait=wait_fixed(60), stop = stop_after_attempt(5))
131132
def get_counts_dma(
132133
ght: GoogleHealthTrends,
133134
start_date: str,
@@ -211,23 +212,22 @@ def _get_counts_geoid(
211212
output_dates = set(pd.date_range(start_date, end_date).to_native_types())
212213
cache_dates = set(dt["timestamp"].values)
213214
req_dates = list(output_dates - cache_dates)
214-
215215
try:
216216
if req_dates:
217217
sdate = min(req_dates)
218218
edate = max(req_dates)
219219
new_data = _api_data_to_df(
220-
ght.query(start_date=sdate, end_date=edate, geo_id=geo_id, dma=dma),
221-
geo_id=geo_id,
222-
)
220+
ght.query(start_date=sdate, end_date=edate, geo_id=geo_id, dma=dma),
221+
geo_id=geo_id,
222+
)
223223
new_data = new_data[new_data["timestamp"].isin(req_dates)]
224224
dt = dt.append(new_data).sort_values("timestamp")
225225
dt = dt.drop_duplicates(subset="timestamp")
226226
_write_cached_file(dt, geo_id, data_dir)
227227
dt = _load_cached_file(geo_id, data_dir)
228228
except googleapiclient.errors.HttpError:
229-
#  This is thrown in there is no data yet for the given days. Need to
230-
#  investigate this further.
229+
# This is thrown in there is no data yet for the given days. Need to
230+
# investigate this further.
231231
pass
232232

233233
dt = dt[dt["timestamp"].isin(output_dates)]

google_health/delphi_google_health/run.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def run_module():
107107
print(f"Failed to archive '{exported_file}'")
108108

109109

110-
def add_prefix(signal_names, wip_signal, prefix="wip_"):
110+
def add_prefix(signal_names, wip_signal, prefix):
111111
"""Adds prefix to signal if there is a WIP signal
112112
Parameters
113113
----------

google_health/setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"delphi-utils",
1212
"covidcast",
1313
"boto3",
14-
"moto"
14+
"moto",
15+
"tenacity"
1516
]
1617

1718
setup(

0 commit comments

Comments
 (0)