Craig Oates
4 years ago
4 changed files with 78 additions and 33 deletions
@ -0,0 +1,45 @@ |
|||||||
|
import requests |
||||||
|
from services import art_services, data_services, logging_services |
||||||
|
|
||||||
|
def update_art_data(arguments): |
||||||
|
directory = arguments.target |
||||||
|
v_setting = arguments.verbose |
||||||
|
v_out = logging_services.log # Partial function -- for brevity. |
||||||
|
save = data_services.store_json # (P.F.) For easier reading. |
||||||
|
|
||||||
|
v_out(v_setting, "Beginning to update Art data...") |
||||||
|
|
||||||
|
try: |
||||||
|
raw_art_data = data_services.get_json( |
||||||
|
"https://api.craigoates.net/api/1.0/Artwork") |
||||||
|
v_out(v_setting, "Data from API retrived.") |
||||||
|
|
||||||
|
save(art_services.get_creation_date_totals(raw_art_data), |
||||||
|
f"{directory}/art_creation_dates.json") |
||||||
|
v_out(v_setting, "Art creation dates processed.") |
||||||
|
|
||||||
|
save(art_services.get_db_column_totals(raw_art_data, "category"), |
||||||
|
f"{directory}/art_category_totals.json") |
||||||
|
v_out(v_setting, "Art categories processed.") |
||||||
|
|
||||||
|
save(art_services.get_db_column_totals(raw_art_data, "medium"), |
||||||
|
f"{directory}/art_medium_total.json") |
||||||
|
v_out(v_setting, "Art medium(s) totals processed.") |
||||||
|
|
||||||
|
save(art_services.get_dimension_totals(raw_art_data, "dimensions", "width"), |
||||||
|
f"{directory}/art_width_totals.json") |
||||||
|
v_out(v_setting, "Art width totals processed.") |
||||||
|
|
||||||
|
save(art_services.get_dimension_totals(raw_art_data, "dimensions", "height"), |
||||||
|
f"{directory}/art_height_totals.json") |
||||||
|
v_out(v_setting, "Art height totals processed.") |
||||||
|
|
||||||
|
save(art_services.get_dimension_totals(raw_art_data, "dimensions", "depth"), |
||||||
|
f"{directory}/art_depth_totals.json") |
||||||
|
v_out(v_setting, "Art depth totals processed.") |
||||||
|
|
||||||
|
v_out(v_setting, "Completed updating Art data.") |
||||||
|
|
||||||
|
except Exception: |
||||||
|
print("ERROR: Unable to update Art data. Exiting program.") |
||||||
|
return 0 |
@ -1,40 +1,13 @@ |
|||||||
#!/usr/bin/python3 |
#!/usr/bin/python3 |
||||||
|
|
||||||
import requests |
from services import parser_services |
||||||
from datetime import datetime |
from coordinators import art_coordinator |
||||||
from services import art_services, data_services |
|
||||||
from pathlib import Path |
|
||||||
|
|
||||||
def main(): |
def main(): |
||||||
# The intention is for this to be accessible from other projects. |
args = parser_services.create_args() |
||||||
directory = str(f"{Path.home()}/coblob-data") |
art_coordinator.update_art_data(args) |
||||||
|
# update_software_data(args) # Future update. |
||||||
raw_art_data = data_services.get_json( |
# update_article_data(args) # Future update. |
||||||
"https://api.craigoates.net/api/1.0/Artwork") |
|
||||||
|
|
||||||
save = data_services.store_json # For easier reading. |
|
||||||
|
|
||||||
save(art_services.get_creation_date_totals(raw_art_data), |
|
||||||
f"{directory}/art_creation_dates.json") |
|
||||||
|
|
||||||
save(art_services.get_db_column_totals(raw_art_data, "category"), |
|
||||||
f"{directory}/art_category_totals.json") |
|
||||||
|
|
||||||
save(art_services.get_db_column_totals(raw_art_data, "medium"), |
|
||||||
f"{directory}/art_medium_total.json") |
|
||||||
|
|
||||||
save(art_services.get_dimension_totals(raw_art_data, "dimensions", "width"), |
|
||||||
f"{directory}/art_width_totals.json") |
|
||||||
|
|
||||||
save(art_services.get_dimension_totals(raw_art_data, "dimensions", "height"), |
|
||||||
f"{directory}/art_height_totals.json") |
|
||||||
|
|
||||||
save(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") |
|
||||||
|
|
||||||
if __name__ == "__main__": |
if __name__ == "__main__": |
||||||
main() |
main() |
||||||
|
@ -0,0 +1,6 @@ |
|||||||
|
# This is for outputting the program's status when the verbose switch |
||||||
|
# is used. |
||||||
|
|
||||||
|
def log(log_output, message): |
||||||
|
if log_output is True: |
||||||
|
print(message) |
@ -0,0 +1,21 @@ |
|||||||
|
import argparse |
||||||
|
import os |
||||||
|
|
||||||
|
def dir_path(string): |
||||||
|
if os.path.isdir(string): |
||||||
|
return string |
||||||
|
else: |
||||||
|
raise NotADirectoryError(string) |
||||||
|
|
||||||
|
def create_args(): |
||||||
|
parser = argparse.ArgumentParser( |
||||||
|
"Parses the coblob database and transforms it. " + |
||||||
|
"This is mostly for the the benefit of the co-data project. " + |
||||||
|
"It, also, requires access to the co-api project, via the internet.") |
||||||
|
parser.add_argument("-t", "--target", type = dir_path, required = True, |
||||||
|
help = "the location you would like the data to be stored at.") |
||||||
|
parser.add_argument("-v", "--verbose", action = "store_true", |
||||||
|
help = "provides detailed output when program is running.") |
||||||
|
|
||||||
|
args = parser.parse_args() |
||||||
|
return args |
Reference in new issue