diff --git a/app/main.py b/app/main.py index f127809..b49b947 100644 --- a/app/main.py +++ b/app/main.py @@ -3,27 +3,42 @@ import requests from datetime import datetime from services import art_services, data_services +from pathlib import Path def main(): - raw_art_data = data_services.get_json("https://api.craigoates.net/api/1.0/Artwork") - cd_totals = art_services.get_creation_date_totals(raw_art_data) - print(cd_totals) - cat_totals = art_services.get_db_column_totals(raw_art_data, "category") - print(cat_totals) - med_totals = art_services.get_db_column_totals(raw_art_data, "medium") - print(med_totals) - width_totals = art_services.get_dimension_totals(raw_art_data, "dimensions", "width") - print(width_totals) - height_totals = art_services.get_dimension_totals(raw_art_data, "dimensions", "height") - print(height_totals) - depth_totals = art_services.get_dimension_totals(raw_art_data, "dimensions", "depth") - print(depth_totals) + # The intention is for this to be accessible from other projects. + directory = str(f"{Path.home()}/coblob-data") + + raw_art_data = data_services.get_json( + "https://api.craigoates.net/api/1.0/Artwork") + + data_services.store_json( + art_services.get_creation_date_totals(raw_art_data), + f"{directory}/art_creation_dates.json") + + data_services.store_json( + art_services.get_db_column_totals(raw_art_data, "category"), + f"{directory}/art_category_totals.json") + + data_services.store_json( + art_services.get_db_column_totals(raw_art_data, "medium"), + f"{directory}/art_medium_total.json") + + data_services.store_json( + art_services.get_dimension_totals(raw_art_data, "dimensions", "width"), + f"{directory}/art_width_totals.json") + + data_services.store_json( + art_services.get_dimension_totals(raw_art_data, "dimensions", "height"), + f"{directory}/art_height_totals.json") + + data_services.store_json( + art_services.get_dimension_totals(raw_art_data, "dimensions", "depth"), + f"{directory}/art_depth_totals.json") # Use for console priting for the moment. date = datetime.now().strftime('%d/%m/%Y') time = datetime.now().strftime("%H:%M") - return 0 - if __name__ == "__main__": main() diff --git a/app/services/art_services.py b/app/services/art_services.py index 58c935a..bcb2d1e 100644 --- a/app/services/art_services.py +++ b/app/services/art_services.py @@ -12,6 +12,7 @@ the data-object this function receives. Unfortunately, I cannot do the same for years. That will continue to grow as the years roll on through here -- unless something monumental happens scientifically or politically. +This code is intended to be used in graphs -- in co-data project. ''' def get_creation_date_totals(data): years = {} diff --git a/app/services/data_services.py b/app/services/data_services.py index 0a1b5b9..65c1e8f 100644 --- a/app/services/data_services.py +++ b/app/services/data_services.py @@ -1,7 +1,12 @@ import requests +import json def get_data(url): return requests.get(url) def get_json(url): return requests.get(url).json() + +def store_json(data, file_name): + with open (file_name, "w") as outfile: + json.dump(data, outfile)