apply some pep8 rules to python script

This commit is contained in:
Mateusz Konieczny 2022-11-13 13:36:04 +01:00
parent 9512d30c28
commit 58e6625790

View File

@ -67,7 +67,7 @@ def load_data_into_database(cursor, data):
"status_explanation_note": status_explanation_note, "status_explanation_note": status_explanation_note,
"data_source": "Greater London Authority's Planning London DataHub", "data_source": "Greater London Authority's Planning London DataHub",
"data_source_link": None "data_source_link": None
} }
if date_in_future(entry["registered_with_local_authority_date"]): if date_in_future(entry["registered_with_local_authority_date"]):
print("registered_with_local_authority_date is treated as invalid:", entry["registered_with_local_authority_date"]) print("registered_with_local_authority_date is treated as invalid:", entry["registered_with_local_authority_date"])
# Brent-87_0946 has "valid_date": "23/04/9187" # Brent-87_0946 has "valid_date": "23/04/9187"
@ -183,35 +183,40 @@ def insert_entry(cursor, e):
e["data_source"], e["data_source"],
e["data_source_link"], e["data_source_link"],
e["uprn"]) e["uprn"])
) )
except psycopg2.errors.Error as error: except psycopg2.errors.Error as error:
show_dictionary(e) show_dictionary(e)
raise error raise error
def show_dictionary(data): def show_dictionary(data):
for key in data.keys(): for key in data.keys():
print(key, "=", data[key]) print(key, "=", data[key])
def days_since(date, now): def days_since(date, now):
if(date == None): if(date == None):
return None return None
return (now - date).days return (now - date).days
def date_object_into_date_string(date): def date_object_into_date_string(date):
if(date == None): if(date == None):
return None return None
return datetime.datetime.strftime(date, "%Y-%m-%d") return datetime.datetime.strftime(date, "%Y-%m-%d")
def parse_date_string_into_date_object(incoming): def parse_date_string_into_date_object(incoming):
if incoming == None: if incoming == None:
return None return None
date = None date = None
try: try:
date = datetime.datetime.strptime(incoming, "%d/%m/%Y") # '21/07/2022' date = datetime.datetime.strptime(incoming, "%d/%m/%Y") # '21/07/2022'
except ValueError: except ValueError:
date = datetime.datetime.strptime(incoming, "%Y-%m-%dT%H:%M:%S.%fZ") # '2022-08-08T20:07:22.238Z' date = datetime.datetime.strptime(incoming, "%Y-%m-%dT%H:%M:%S.%fZ") # '2022-08-08T20:07:22.238Z'
return date return date
def obtain_entry_link(provided_link, application_id): def obtain_entry_link(provided_link, application_id):
if provided_link != None: if provided_link != None:
if "Ealing" in application_id: if "Ealing" in application_id: