Skip to content

Commit

Permalink
Add utils to locally load/save item data for specified item ids
Browse files Browse the repository at this point in the history
  • Loading branch information
woctezuma committed Jun 17, 2021
1 parent 44763b7 commit f3ac99f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/item_data_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import json
from pathlib import Path

from src.data_utils import save_data
from src.download_utils import download_from_item_data_tracker


def get_item_data_filename(item_id, folder_name="data/items/"):
Path(folder_name).mkdir(parents=True, exist_ok=True)

fname = f"{item_id}.json"

return folder_name + fname


def load_item_data(item_id):
fname = get_item_data_filename(item_id)

try:
with open(fname, encoding="utf8") as f:
item_data = json.load(f)
except FileNotFoundError:
item_data = download_from_item_data_tracker(item_id)
save_data(item_data, fname)

return item_data

0 comments on commit f3ac99f

Please sign in to comment.