Added addition context

This commit is contained in:
2025-11-06 16:32:04 -05:00
parent a141fa76f1
commit 085cc008b4
4 changed files with 40 additions and 6 deletions

View File

@@ -39,7 +39,7 @@ def format_sort_title(title):
def combine_raw_jsons(google_json, ol_json):
'''
Returns a dictionary consisting of an array of dictionarys.
Returns a dictionary consisting of an array of dictionaries.
Each child dictionary is a transformed book ready to be
inserted into a database.
@@ -57,6 +57,7 @@ def combine_raw_jsons(google_json, ol_json):
isbn = ol_json['book_data'][index]['isbn']
sort_title = format_sort_title(title)
# Ensuring field variables have valid data
if 'categories' in google_json['book_data'][index]['volumeInfo']:
categories = ', '.join(google_json['book_data'][index]['volumeInfo']['categories'])
else:
@@ -69,6 +70,7 @@ def combine_raw_jsons(google_json, ol_json):
if 'publishedDate' in google_json['book_data'][index]['volumeInfo']:
published_date = google_json['book_data'][index]['volumeInfo']['publishedDate']
# Making sure the publishing date has a month and day associated
if len(published_date) == 4:
published_date += '-12-31'
elif len(published_date) < 10:
@@ -76,8 +78,6 @@ def combine_raw_jsons(google_json, ol_json):
else:
published_date = '9999-12-31'
lost_date = '9999-12-31'
if 'printType' in google_json['book_data'][index]['volumeInfo']:
print_type = google_json['book_data'][index]['volumeInfo']['printType']
else:
@@ -98,6 +98,7 @@ def combine_raw_jsons(google_json, ol_json):
description = ol_json['book_data'][index]['description']
price_in_cents = ol_json['book_data'][index]['price_in_cents']
cover_image_uri = ol_json['book_data'][index]['cover_image_uri']
lost_date = '9999-12-31'
transformed_dictionary_entry = {
'title': title,
@@ -120,6 +121,7 @@ def combine_raw_jsons(google_json, ol_json):
'price_in_cents': price_in_cents,
'cover_image_uri': cover_image_uri,
}
transformed_dictionary['books'].append(transformed_dictionary_entry)
return transformed_dictionary