Skip to content

Commit

Permalink
refactor: replace category dict key from Id to id
Browse files Browse the repository at this point in the history
  • Loading branch information
memorisanka committed Dec 9, 2023
1 parent 2ae6270 commit dcf5328
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def handle(self, *args, **kwargs):
root = etree.fromstring(xml_data)
categories = self.parse_categories(root)
for category in categories:
category['Id'] = int(category['Id'])
categories.sort(key=lambda x: x['Id'])
category['id'] = int(category['id'])
categories.sort(key=lambda x: x['id'])
self.import_ceneo_categories(categories)
self.stdout.write(self.style.SUCCESS('Ceneo categories data imported successfully.'))

Expand All @@ -38,7 +38,7 @@ def parse_categories(self, category_elem):
categories = []
for elem in category_elem:
category = {
'Id': int(elem.findtext('Id')),
'id': int(elem.findtext('Id')),
'name': elem.findtext('Name'),
}
subcategories_elem = elem.find('Subcategories')
Expand All @@ -53,10 +53,10 @@ def import_ceneo_categories(categories):
new_categories = []

for category in categories:
if category['Id'] in existing_categories:
logging.info(f"Category {category['Id']} ({category['name']}) already exists.")
if category['id'] in existing_categories:
logging.info(f"Category {category['id']} ({category['name']}) already exists.")
else:
new_categories.append(CeneoCategory(id=category['Id'], name=category['name']))
new_categories.append(CeneoCategory(id=category['id'], name=category['name']))

if new_categories:
CeneoCategory.objects.bulk_create(new_categories, ignore_conflicts=True, update_conflicts=False)
Expand Down

0 comments on commit dcf5328

Please sign in to comment.