|
17 | 17 |
|
18 | 18 | def check_last_updated(socrata_token, dataset_id, logger): |
19 | 19 | """Check last updated timestamp to determine data should be pulled or not.""" |
20 | | - client = Socrata("data.cdc.gov", socrata_token) |
21 | | - response = client.get_metadata(dataset_id) |
22 | | - |
23 | | - updated_timestamp = datetime.utcfromtimestamp(int(response["rowsUpdatedAt"])) |
24 | | - now = datetime.utcnow() |
25 | | - recently_updated_source = (now - updated_timestamp) < timedelta(days=1) |
26 | | - |
27 | | - prelim_prefix = "Preliminary " if dataset_id == PRELIM_DATASET_ID else "" |
28 | | - if recently_updated_source: |
29 | | - logger.info(f"{prelim_prefix}NHSN data was recently updated; Pulling data", updated_timestamp=updated_timestamp) |
30 | | - else: |
31 | | - logger.info(f"{prelim_prefix}NHSN data is stale; Skipping", updated_timestamp=updated_timestamp) |
| 20 | + recently_updated_source = True |
| 21 | + try: |
| 22 | + client = Socrata("data.cdc.gov", socrata_token) |
| 23 | + response = client.get_metadata(dataset_id) |
| 24 | + |
| 25 | + updated_timestamp = datetime.utcfromtimestamp(int(response["rowsUpdatedAt"])) |
| 26 | + now = datetime.utcnow() |
| 27 | + recently_updated_source = (now - updated_timestamp) < timedelta(days=1) |
| 28 | + |
| 29 | + prelim_prefix = "Preliminary " if dataset_id == PRELIM_DATASET_ID else "" |
| 30 | + if recently_updated_source: |
| 31 | + logger.info( |
| 32 | + f"{prelim_prefix}NHSN data was recently updated; Pulling data", updated_timestamp=updated_timestamp |
| 33 | + ) |
| 34 | + else: |
| 35 | + logger.info(f"{prelim_prefix}NHSN data is stale; Skipping", updated_timestamp=updated_timestamp) |
| 36 | + # pylint: disable=W0703 |
| 37 | + except Exception as e: |
| 38 | + logger.info("error while processing socrata metadata; continuing processing", error=str(e)) |
32 | 39 | return recently_updated_source |
33 | 40 |
|
34 | 41 |
|
|
0 commit comments