Skip to content

Commit

Permalink
run autopep8
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoniecz committed Mar 21, 2024
1 parent 784960c commit 8f98403
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions etl/planning_data/obtain_livestream_data_and_load_into_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def main():
unexpected_status_statistics = {}
while True:
data = query(search_after).json()
unexpected_status_statistics = load_data_into_database(cursor, data, unexpected_status_statistics)
unexpected_status_statistics = load_data_into_database(
cursor, data, unexpected_status_statistics)
for entry in data["hits"]["hits"]:
downloaded += 1
last_sort = entry["sort"]
Expand Down Expand Up @@ -81,7 +82,8 @@ def load_data_into_database(cursor, data, unexpected_status_statistics):
)
uprn = entry["_source"]["uprn"]
status_before_aliasing = entry["_source"]["status"]
status_info = process_status(status_before_aliasing, decision_date, unexpected_status_statistics)
status_info = process_status(
status_before_aliasing, decision_date, unexpected_status_statistics)
unexpected_status_statistics = status_info['unexpected_status_statistics']
status = status_info["status"]
status_explanation_note = status_info["status_explanation_note"]
Expand Down Expand Up @@ -147,11 +149,14 @@ def throw_away_invalid_dates(entry):
entry[date_code] = None

if entry[date_code] != None:
if entry[date_code] < datetime.datetime(1950, 1, 1): # not believable values
print(date_code, "Unexpectedly early date, treating it as a missing date:", entry[date_code])
# not believable values
if entry[date_code] < datetime.datetime(1950, 1, 1):
print(
date_code, "Unexpectedly early date, treating it as a missing date:", entry[date_code])
entry[date_code] = None
return entry


def date_in_future(date):
if date is None:
return False
Expand Down Expand Up @@ -212,21 +217,25 @@ def make_api_call(url, headers, json_data):
)
except requests.exceptions.ConnectionError as e:
print(e)
sleep_before_retry("requests.exceptions.ConnectionError", url, headers, json_data)
sleep_before_retry(
"requests.exceptions.ConnectionError", url, headers, json_data)
continue
except requests.exceptions.HTTPError as e:
print(e.response.status_code)
if e.response.status_code == 503:
sleep_before_retry("requests.exceptions.HTTPError", url, headers, json_data)
sleep_before_retry(
"requests.exceptions.HTTPError", url, headers, json_data)
continue
raise e
except requests.exceptions.ReadTimeout as e:
print(e)
sleep_before_retry("requests.exceptions.ReadTimeout", url, headers, json_data)
sleep_before_retry(
"requests.exceptions.ReadTimeout", url, headers, json_data)
continue
except requests.exceptions.ChunkedEncodingError as e:
print(e)
sleep_before_retry("requests.exceptions.ChunkedEncodingError", url, headers, json_data)
sleep_before_retry(
"requests.exceptions.ChunkedEncodingError", url, headers, json_data)
continue


Expand Down Expand Up @@ -373,7 +382,8 @@ def process_status(status, decision_date, unexpected_status_statistics):
if decision_date is None:
status = "Submitted"
else:
print(status, "but with", decision_date, "marking as unknown status")
print(status, "but with", decision_date,
"marking as unknown status")
status = "Unknown"
if canonical_status in [
"refused",
Expand Down Expand Up @@ -407,7 +417,7 @@ def process_status(status, decision_date, unexpected_status_statistics):
"Unknown",
]:
return {
"status": status,
"status": status,
"status_explanation_note": None,
"unexpected_status_statistics": unexpected_status_statistics,
}
Expand Down

0 comments on commit 8f98403

Please sign in to comment.