Skip to content

Commit

Permalink
Added extra fields support for Digi-Key
Browse files Browse the repository at this point in the history
  • Loading branch information
eeintech committed Apr 21, 2023
1 parent 74c19e6 commit ac2c82d
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 281 deletions.
3 changes: 2 additions & 1 deletion kintree/config/digikey/digikey_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ SEARCH_SKU: null
SEARCH_MANUFACTURER: null
SEARCH_MPN: null
SEARCH_SUPPLIER_URL: null
SEARCH_DATASHEET: null
SEARCH_DATASHEET: null
EXTRA_FIELDS: null
273 changes: 0 additions & 273 deletions kintree/config/digikey/digikey_parameters.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion kintree/config/element14/element14_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ SEARCH_SKU: null
SEARCH_MANUFACTURER: null
SEARCH_MPN: null
SEARCH_SUPPLIER_URL: null
SEARCH_DATASHEET: null
SEARCH_DATASHEET: null
EXTRA_FIELDS: null
3 changes: 3 additions & 0 deletions kintree/config/inventree/inventree_dev.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
ENABLE: true
ENABLE_PROXY: false
PASSWORD: !!binary |
''
PROXIES: null
SERVER_ADDRESS: ''
USERNAME: ''
3 changes: 3 additions & 0 deletions kintree/config/inventree/inventree_prod.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
ENABLE: true
ENABLE_PROXY: false
PASSWORD: !!binary |
''
PROXIES: null
SERVER_ADDRESS: ''
USERNAME: ''
3 changes: 2 additions & 1 deletion kintree/config/lcsc/lcsc_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ SEARCH_SKU: null
SEARCH_MANUFACTURER: null
SEARCH_MPN: null
SEARCH_SUPPLIER_URL: null
SEARCH_DATASHEET: null
SEARCH_DATASHEET: null
EXTRA_FIELDS: null
3 changes: 2 additions & 1 deletion kintree/config/mouser/mouser_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ SEARCH_SKU: null
SEARCH_MANUFACTURER: null
SEARCH_MPN: null
SEARCH_SUPPLIER_URL: null
SEARCH_DATASHEET: null
SEARCH_DATASHEET: null
EXTRA_FIELDS: null
1 change: 0 additions & 1 deletion kintree/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ def load_suppliers():
CONFIG_DIGIKEY = config_interface.load_file(os.path.join(CONFIG_USER_FILES, 'digikey_config.yaml'))
CONFIG_DIGIKEY_API = os.path.join(CONFIG_USER_FILES, 'digikey_api.yaml')
CONFIG_DIGIKEY_CATEGORIES = os.path.join(CONFIG_USER_FILES, 'digikey_categories.yaml')
# CONFIG_DIGIKEY_PARAMETERS = os.path.join(CONFIG_USER_FILES, 'digikey_parameters.yaml')

# Mouser user configuration
CONFIG_MOUSER = config_interface.load_file(os.path.join(CONFIG_USER_FILES, 'mouser_config.yaml'))
Expand Down
24 changes: 21 additions & 3 deletions kintree/database/inventree_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ def translate_form_to_inventree(part_info: dict, category_tree: list, is_custom=
if not is_custom:
# Add Parameters
if parameter_map:
parameters_missing = []
for supplier_param, inventree_param in parameter_map.items():
# Some parameters may not be mapped
if inventree_param not in inventree_part['parameters'].keys():
Expand All @@ -281,15 +282,32 @@ def translate_form_to_inventree(part_info: dict, category_tree: list, is_custom=
value=part_info['parameters'][supplier_param],
)
inventree_part['parameters'][inventree_param] = parameter_value
except:
cprint(f'[INFO]\tWarning: Parameter "{supplier_param}" not found in supplier data', silent=settings.SILENT)
except KeyError:
parameters_missing.append(supplier_param)
else:
inventree_part['parameters'][inventree_param] = part_info['manufacturer_part_number']

# Check for missing parameters and fill value with dash
if parameters_missing:
msg = '[INFO]\tWarning: The following parameters were not found in supplier data:\n'
msg += str(parameters_missing)
cprint(msg, silent=settings.SILENT)

# Check for missing InvenTree parameters and fill value with dash
for inventree_param in parameter_map.values():
if inventree_param not in inventree_part['parameters'].keys():
inventree_part['parameters'][inventree_param] = '-'

# Check for extra parameters which weren't mapped
parameters_unmapped = []
for search_param in part_info['parameters'].keys():
if search_param not in parameter_map.keys():
parameters_unmapped.append(search_param)

if parameters_unmapped:
if not settings.SILENT:
msg = f'[INFO]\tThe following parameters are not mapped in {inventree_part["supplier_name"]} parameters configuration:\n'
msg += str(parameters_unmapped)
print(msg)
else:
cprint(f'[INFO]\tWarning: Parameter map for "{category_tree[0]}" does not exist or is empty', silent=settings.SILENT)

Expand Down
9 changes: 9 additions & 0 deletions kintree/search/digikey_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ def digikey_search_timeout():
# Append to parameters dictionary
part_info['parameters'][parameter_name] = parameter_value

# Extra search fields
if settings.CONFIG_DIGIKEY.get('EXTRA_FIELDS', None):
for extra_field in settings.CONFIG_DIGIKEY['EXTRA_FIELDS']:
if part.get(extra_field, None):
part_info['parameters'][extra_field] = part[extra_field]
else:
from ..common.tools import cprint
cprint(f'[INFO]\tWarning: Extra field "{extra_field}" not found in search results', silent=False)

return part_info


Expand Down

0 comments on commit ac2c82d

Please sign in to comment.