Skip to content

Commit

Permalink
fixes handling of non existing product.json
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Nov 18, 2023
1 parent a7014b0 commit 278fe1e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion scan/__init__.py
@@ -1 +1 @@
__version__="0.2.0"
__version__="0.2.1"
15 changes: 8 additions & 7 deletions scan/product.py
Expand Up @@ -166,16 +166,17 @@ def save_to_json(self, filename: str = None):
with open(filename, 'w') as file:
json.dump(product_data, file, indent=2)

def load_from_json(self, filename: str = None):
def load_from_json(self, filepath: str = None):
"""
Loads products from a JSON file and updates the current list and mappings.
Args:
filename (str, optional): The filename from which to load the JSON data.
filepath (str, optional): The filepath from which to load the JSON data.
Defaults to the instance's store_path attribute.
"""
filename = filename or self.store_path
with open(filename, 'r') as file:
product_data = json.load(file)
for data in product_data:
self.add_product(Product(**data))
filename = filepath or self.store_path
if os.path.exists(filename):
with open(filepath, 'r') as file:
product_records = json.load(file)
for product_record in product_records:
self.add_product(Product(**product_record))
2 changes: 1 addition & 1 deletion scan/version.py
Expand Up @@ -15,7 +15,7 @@ class Version(object):
version=scan.__version__
description='Scan to Wiki by watching a scan folder'
date = '2021-12-20'
updated = '2023-11-16'
updated = '2023-11-18'

authors = 'Wolfgang Fahl'

Expand Down

0 comments on commit 278fe1e

Please sign in to comment.