Skip to content

Commit

Permalink
add localization options to digikey API
Browse files Browse the repository at this point in the history
  • Loading branch information
T0jan committed Oct 22, 2024
1 parent 7a9f36c commit 29cbd0e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
18 changes: 18 additions & 0 deletions kintree/gui/views/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@
ft.TextField(),
None,
]
supplier_settings[supplier]['Local Site'] = [
digikey_api_settings.get('DIGIKEY_LOCAL_SITE', 'US'),
ft.TextField(),
None,
]
supplier_settings[supplier]['Language'] = [
digikey_api_settings.get('DIGIKEY_LOCAL_LANGUAGE', 'en'),
ft.TextField(),
None,
]
supplier_settings[supplier]['Currency'] = [
digikey_api_settings.get('DIGIKEY_LOCAL_CURRENCY', 'USD'),
ft.TextField(),
None,
]
elif supplier == 'Mouser':
mouser_api_settings = config_interface.load_file(global_settings.CONFIG_MOUSER_API)
supplier_settings[supplier]['Part API Key'] = [
Expand Down Expand Up @@ -673,6 +688,9 @@ def save_s(self, e: ft.ControlEvent, supplier: str, show_dialog=True):
updated_settings = {
'DIGIKEY_CLIENT_ID': SETTINGS[self.title][supplier]['Client ID'][1].value,
'DIGIKEY_CLIENT_SECRET': SETTINGS[self.title][supplier]['Client Secret'][1].value,
'DIGIKEY_LOCAL_SITE': SETTINGS[self.title][supplier]['Local Site'][1].value,
'DIGIKEY_LOCAL_LANGUAGE': SETTINGS[self.title][supplier]['Language'][1].value,
'DIGIKEY_LOCAL_CURRENCY': SETTINGS[self.title][supplier]['Currency'][1].value,
}
digikey_settings = {**settings_from_file, **updated_settings}
config_interface.dump_file(digikey_settings, global_settings.CONFIG_DIGIKEY_API)
Expand Down
12 changes: 9 additions & 3 deletions kintree/search/digikey_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
'package_type'
]


os.environ['DIGIKEY_STORAGE_PATH'] = settings.DIGIKEY_STORAGE_PATH
# Check if storage path exists, else create it
if not os.path.exists(os.environ['DIGIKEY_STORAGE_PATH']):
Expand Down Expand Up @@ -58,7 +57,9 @@ def setup_environment(force=False) -> bool:
digikey_api_settings = config_interface.load_file(settings.CONFIG_DIGIKEY_API)
os.environ['DIGIKEY_CLIENT_ID'] = digikey_api_settings['DIGIKEY_CLIENT_ID']
os.environ['DIGIKEY_CLIENT_SECRET'] = digikey_api_settings['DIGIKEY_CLIENT_SECRET']

os.environ['DIGIKEY_LOCAL_SITE'] = digikey_api_settings.get('DIGIKEY_LOCAL_SITE', 'US')
os.environ['DIGIKEY_LOCAL_LANGUAGE'] = digikey_api_settings.get('DIGIKEY_LOCAL_LANGUAGE', 'en')
os.environ['DIGIKEY_LOCAL_CURRENCY'] = digikey_api_settings.get('DIGIKEY_LOCAL_CURRENCY', 'USD')
return check_environment()


Expand Down Expand Up @@ -103,7 +104,12 @@ def fetch_part_info(part_number: str) -> dict:
# Added logic to check the result in the GUI flow
@timeout(dec_timeout=20)
def digikey_search_timeout():
return digikey.product_details(part_number).to_dict()
return digikey.product_details(
part_number,
x_digikey_locale_site=os.environ['DIGIKEY_LOCAL_SITE'],
x_digikey_locale_language=os.environ['DIGIKEY_LOCAL_LANGUAGE'],
x_digikey_locale_currency=os.environ['DIGIKEY_LOCAL_CURRENCY'],
).to_dict()

# THIS METHOD WILL NOT WORK WITH DIGI-KEY PART NUMBERS...
# @timeout(dec_timeout=20)
Expand Down

0 comments on commit 29cbd0e

Please sign in to comment.