Browse Source

add logic to store transformed art data.

stable
Craig Oates 4 years ago
parent
commit
0ef9366102
  1. 45
      app/main.py
  2. 1
      app/services/art_services.py
  3. 5
      app/services/data_services.py

45
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()

1
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 = {}

5
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)