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

Digikey v4 + Python3.12 + Digikey Localization #263

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/test_deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- name: Checkout code
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
continue-on-error: true
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- name: Checkout code
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ Ki-nTree was developed by [@eeintech](https://github.com/eeintech) for [SPARK Mi

### Requirements

* Ki-nTree is currently tested for Python 3.9 to 3.11 versions.
* Ki-nTree is currently tested for Python 3.9 to 3.12 versions.
* Ki-nTree requires a Digi-Key **production** API instance. To create one, go to https://developer.digikey.com/. Create an account, an organization and add a **production** API to your organization. Save both Client ID and Secret keys.
> [Here is a video](https://youtu.be/OI1EGEc0Ju0) to help with the different steps
* Ki-nTree requires a Mouser Search API key. To request one, head over to https://www.mouser.ca/api-search/ and click on "Sign Up for Search API"
* Ki-nTree requires an Element14 Product Search API key to fetch part information for the following suppliers: Farnell (Europe), Newark (North America) and Element14 (Asia-Pacific). To request one, head over to https://partner.element14.com/ and click on "Register"
* on rolling release distributions like Arch Linux some Flet dependencies need to be repaired manually:
```
sudo pacman -S mpv
sudo ln -s /usr/lib/libmpv.so /usr/lib/libmpv.so.1
```

### Installation (system wide)

Expand Down
2 changes: 1 addition & 1 deletion kintree/common/part_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def clean_parameter_value(category: str, name: str, value: str) -> str:

# Remove parenthesis section
if '(' in value:
parenthesis = re.findall('\(.*\)', value)
parenthesis = re.findall(r'\(.*\)', value)

if parenthesis:
for item in parenthesis:
Expand Down
2 changes: 1 addition & 1 deletion kintree/common/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_image_with_retries(url, headers, retries=3, wait=5, silent=False):
scraper = cloudscraper.create_scraper()
for attempt in range(retries):
try:
response = scraper.get(url, headers=headers)
response = scraper.get(url, headers=headers, timeout=wait)
if response.status_code == 200:
return response
else:
Expand Down
10 changes: 2 additions & 8 deletions kintree/database/inventree_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,19 +751,12 @@ def create_supplier_part(part_id: int, manufacturer_name: str, manufacturer_mpn:
return False, False


def sanitize_price(price_in):
price = re.findall('\d+.\d+', price_in)[0]
price = price.replace(',', '.')
price = price.replace('\xa0', '')
return price


def update_price_breaks(supplier_part,
price_breaks: dict,
currency='USD') -> bool:
''' Update the Price Breaks associated with a supplier part '''
def sanitize_price(price_in):
price = re.findall('\d+.\d+', price_in)[0]
price = re.findall(r'\d+.\d+', price_in)[0]
price = price.replace(',', '.')
price = price.replace('\xa0', '')
return price
Expand Down Expand Up @@ -838,6 +831,7 @@ def create_parameter_template(name: str, units: str) -> int:
})
except:
cprint(f'[TREE]\tError: Failed to create parameter template "{name}".', silent=settings.SILENT)
return 0

if parameter_template:
return parameter_template.pk
Expand Down
3 changes: 2 additions & 1 deletion kintree/gui/views/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
maximizable=True,
),
leading_width=40,
title=ft.WindowDragArea(ft.Text(f'Ki-nTree | {__version__}'), maximizable=True),
title=ft.WindowDragArea(ft.Container(ft.Text(f'Ki-nTree | {__version__}'),
width=10000), maximizable=True),
center_title=False,
bgcolor=ft.colors.SURFACE_VARIANT,
actions=[],
Expand Down
30 changes: 29 additions & 1 deletion 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 @@ -291,7 +306,8 @@

# Settings AppBar
settings_appbar = ft.AppBar(
title=ft.Text('Ki-nTree Settings'),
title=ft.WindowDragArea(ft.Container(ft.Text('Ki-nTree Settings'),
width=10000), maximizable=True),
bgcolor=ft.colors.SURFACE_VARIANT
)

Expand Down Expand Up @@ -359,6 +375,15 @@ def __init__(self, page: ft.Page):

# Init view
super().__init__(page=page, appbar=settings_appbar, navigation_rail=settings_navrail)
if not self.appbar.actions:
self.appbar.actions.extend(
[
ft.IconButton(
ft.icons.CLOSE,
on_click=lambda _: page.window.close(),
),
]
)

# Update navigation rail
self.navigation_rail.on_change = self.nav_rail_redirect
Expand Down Expand Up @@ -673,6 +698,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
10 changes: 6 additions & 4 deletions kintree/search/automationdirect_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def search_timeout(timeout=10):
else:
cprint(f'[INFO]\tFound {part["numFound"]} results for "{part_number}", selecting first result', silent=False)
part = part['docs'][0] # choose the first part in the returned returned list
else:
part = None
except Exception as e:
cprint(f'[INFO]\tError: fetch_part_info(): {repr(e)}')
part = None
Expand Down Expand Up @@ -146,7 +148,7 @@ def search_timeout(timeout=10):
parameter_name = parameter_name.replace('/', '')
parameter_value = attribute_list[1]
try:
html_li_list = re.split("</?\s*[a-z-][^>]*\s*>|(\&(?:[\w\d]+|#\d+|#x[a-f\d]+);)", parameter_value)
html_li_list = re.split(r"</?\s*[a-z-][^>]*\s*>|(\&(?:[\w\d]+|#\d+|#x[a-f\d]+);)", parameter_value)
cleaned_html_li_list = list(filter(None, html_li_list))
parameter_value = ', '.join(cleaned_html_li_list)
except Exception as e:
Expand All @@ -156,7 +158,7 @@ def search_timeout(timeout=10):
# Nominal Input Voltage gives range min-max, parse it out to put in min/max params
if parameter_name == "Nominal Input Voltage":
if parameter_value.count('-') == 1:
parameter_value = re.sub('[^\d-]+', '', parameter_value)
parameter_value = re.sub(r'[^\d-]+', '', parameter_value)
values_list = parameter_value.split('-')
min_value = min(values_list)
max_value = max(values_list)
Expand All @@ -169,7 +171,7 @@ def search_timeout(timeout=10):
# Nominal Output Voltage gives range min-max, parse it out to put in min/max params
if parameter_name == "Nominal Output Voltage":
if parameter_value.count('-') == 1:
parameter_value = re.sub('[^\d-]+', '', parameter_value)
parameter_value = re.sub(r'[^\d-]+', '', parameter_value)
values_list = parameter_value.split('-')
min_value = min(values_list)
max_value = max(values_list)
Expand All @@ -189,7 +191,7 @@ def search_timeout(timeout=10):

# Parse out ordering attributes
pricing_attributes = {}
price_per_unit = part[price_key]
price_per_unit = part.get(price_key, '0')
try:
for attribute in part[ordering_attributes]:
attribute = attribute.split(':')
Expand Down
Loading
Loading