Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.6 #208

Merged
merged 6 commits into from
Feb 3, 2024
Merged

1.0.6 #208

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions kintree/config/config_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def dump_file(data: dict, file_path: str) -> bool:
''' Safe dump YAML file '''
with open(file_path, 'w') as file:
try:
yaml.safe_dump(data, file, default_flow_style=False)
yaml.safe_dump(data, file, default_flow_style=False, allow_unicode=True)
except yaml.YAMLError as exc:
print(exc)
return False
Expand Down Expand Up @@ -62,9 +62,12 @@ def load_config(path):
template_data = load_file(os.path.join(path, filename))
try:
user_data = load_file(os.path.join(path_to_user_files, filename))
# Join user data to template data
user_settings = {**template_data, **user_data}
except TypeError:
if list(template_data.keys()) == list(user_data.keys()):
# Join user data to template data
user_settings = {**template_data, **user_data}
else:
user_settings = user_data
except (TypeError, AttributeError):
cprint(f'[INFO]\tCreating new {filename} configuration file', silent=silent)
# Config file does not exists
user_settings = template_data
Expand Down
2 changes: 1 addition & 1 deletion kintree/database/inventree_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def inventree_fuzzy_company_match(name: str) -> str:
for company_name in inventree_companies.keys():
cprint(f'{name.lower()} == {company_name.lower()} % {fuzz.partial_ratio(name.lower(), company_name.lower())}',
silent=settings.HIDE_DEBUG)
if fuzz.partial_ratio(name.lower(), company_name.lower()) == 100:
if fuzz.partial_ratio(name.lower(), company_name.lower()) == 100 and len(name) == len(company_name):
return company_name

return name
Expand Down
2 changes: 1 addition & 1 deletion kintree/gui/views/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
'dropdown_width': 600,
'dropdown_dense': False,
'searchfield_width': 300,
'button_width': 100,
'button_width': 110,
'button_height': 56,
'icon_size': 40,
'text_size': 16,
Expand Down
13 changes: 9 additions & 4 deletions kintree/gui/views/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,20 @@ def run_search(self, e):
self.push_data()
self.page.splash.visible = False

if not self.data['manufacturer_part_number'] and not self.data['custom_part']:
if not self.data['supplier_part_number'] and not self.data['custom_part']:
self.show_dialog(
d_type=DialogType.ERROR,
message='Part not found',
)
elif not self.data['manufacturer_part_number']:
self.show_dialog(
d_type=DialogType.ERROR,
message='Found part has no manufacturer part number',
)
elif self.data['searched_part_number'].lower() != self.data['manufacturer_part_number'].lower():
self.show_dialog(
d_type=DialogType.WARNING,
message='Found part number does not match the requested part number',
message='Found manufacturer part number does not match the requested part number',
)
self.page.update()
return
Expand Down Expand Up @@ -915,7 +920,7 @@ def check_snapeda(self, e):
if not data_from_views.get('Part Search', {}).get('manufacturer_part_number', ''):
self.show_dialog(
d_type=DialogType.ERROR,
message='Missing Part Data',
message='Missing Manufacturer Part Number',
)
return

Expand Down Expand Up @@ -1203,7 +1208,7 @@ def create_part(self, e=None):
part_number = data_from_views['Part Search'].get('manufacturer_part_number', None)
if not custom:
if not part_number:
self.show_dialog(DialogType.ERROR, 'Missing Part Number')
self.show_dialog(DialogType.ERROR, 'Missing Manufacturer Part Number')
return
else:
# Update IPN (later overwritten)
Expand Down
6 changes: 4 additions & 2 deletions kintree/search/tme_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ def setup_environment(force=False) -> bool:

# Based on TME API snippets mentioned in API documentation: https://developers.tme.eu/documentation/download
# https://github.com/tme-dev/TME-API/blob/master/Python/call.py
def tme_api_request(endpoint, tme_api_settings, part_number, api_host='https://api.tme.eu', format='json'):
def tme_api_request(endpoint, tme_api_settings, part_number, api_host='https://api.tme.eu', format='json', **kwargs):
TME_API_TOKEN = tme_api_settings.get('TME_API_TOKEN', None)
TME_API_SECRET = tme_api_settings.get('TME_API_SECRET', None)

params = collections.OrderedDict()
params['Country'] = tme_api_settings.get('TME_API_COUNTRY', 'US')
params['Language'] = tme_api_settings.get('TME_API_LANGUAGE', 'EN')
params['SymbolList[0]'] = part_number
if kwargs.get('currency', None):
params['Currency'] = kwargs.get('currency')
if not TME_API_TOKEN and not TME_API_SECRET:
TME_API_TOKEN = os.environ.get('TME_API_TOKEN', None)
TME_API_SECRET = os.environ.get('TME_API_SECRET', None)
Expand Down Expand Up @@ -136,7 +138,7 @@ def search_product(response):
part_info['parameters'][param['ParameterName']] = param['ParameterValue']

# query the prices
response = download(tme_api_request('/Products/GetPrices', tme_api_settings, part_number))
response = download(tme_api_request('/Products/GetPrices', tme_api_settings, part_number, currency='USD'))
# check if accidentally no data returned
if response is None or response['Status'] != 'OK':
return part_info
Expand Down
Loading