hildogjr / KiCost

Build cost spreadsheet for a KiCad project.
MIT License
493 stars 97 forks source link

Prices in euros are not working with mouser #519

Closed Tremoneck closed 2 years ago

Tremoneck commented 2 years ago

I've tried to use KiCost with Mouser and Prices in Euros. It reports the error that "0,419 €" can't be converted to float with float(string[index:]), caused in by api_mouser.py, 60:get_number.

The issue at hand is, that the Euro is behind and the dollar is in front of prices. The Dollar is removed, while the Euro is not. A possible patch would be:

def get_number(string):
    index = next((i for i, d in enumerate(string) if d.isdigit()), None) 
    if index is None:
        raise MouserError('Malformed price: ' + string)
    end = next((i for i, d in enumerate(string, start=index) if not (d.isdigit() or d == ',')), None)
    string = string.replace(',','.')    
    if end is not None:
        return float(string[index:end])
    else:
        return float(string[index:])

I have only checked the mouser api. The same problem might also be in other files

set-soft commented 2 years ago

Hi @Tremoneck ! Thanks for the information. I think Mouser is the only that decorates data, all the others just send ... well the information (amount and currency). Are you using other APIs? I want some feadback from the new APIs, to know if I can do a release.