-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* This adds a rudimentary implementation of the category feature. Almost nothing has been mapped and also not really tested so there might be lots of mistakes. * Also add a command line argument to support a different output directory if desired.
- Loading branch information
Showing
8 changed files
with
2,706 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import json | ||
import pathlib | ||
|
||
from hotprices_au.logging import logger | ||
|
||
PKG_DATA_FOLDER = pathlib.Path(__file__).parent / "data" | ||
|
||
def merge_save_save_categories(store, categories): | ||
store_file = PKG_DATA_FOLDER / f"{store}-categories.json" | ||
# Create folder if it doesn't exist | ||
PKG_DATA_FOLDER.mkdir(parents=True, exist_ok=True) | ||
|
||
if store_file.exists(): | ||
old_mapping = json.loads(store_file.read_text()) | ||
old_lookup = {c['id']: c for c in old_mapping} | ||
|
||
for category in categories: | ||
old_category = old_lookup.pop(category['id'], None) | ||
if old_category is None: | ||
logger.info(f"Found new unmapped category for {store}: {category['id']} - {category['description']}") | ||
else: | ||
category['code'] = old_category['code'] | ||
|
||
if old_lookup: | ||
for old_cat in old_lookup.values(): | ||
logger.info( | ||
f"Found category absent in latest mapping for {store}: " | ||
f"{old_cat['id']} - {old_cat['description']}") | ||
categories.append(old_cat) | ||
|
||
store_file.write_text(json.dumps(categories, indent=2)) | ||
return categories |
Oops, something went wrong.