Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'preferences', 'pc_%s=%s' % (domain, currency_iso))
# Store new localized url in distributor_dict.
distributor_dict[self.name]['site']['url'] = self.browser.ret_url.rstrip('/')
distributor_dict[self.name]['site']['currency'] = pycountry.currencies.get(numeric=country.numeric).alpha_3
distributor_dict[self.name]['site']['locale'] = locale_iso
# Restarting complete session is required to apply
# new locale and currency settings.
self.browser.domain = distributor_dict[self.name]['site']['url']
self.browser.start_new_session()
except Exception as ex:
self.logger.log(DEBUG_OBSESSIVE, "Exception was %s" % type(ex).__name__)
self.logger.log(DEBUG_OVERVIEW, 'Kept the last configuration {}, {} on {}.'.format(
pycountry.currencies.get(alpha_3=distributor_dict[self.name]['site']['currency']).name,
pycountry.countries.get(alpha_2=distributor_dict[self.name]['site']['locale']).name,
distributor_dict[self.name]['site']['url']
)) # Keep the current configuration.
return
self.logger.log(DEBUG_OBSESSIVE,'No HTML page for DigiKey configuration.')
raise PartHtmlError
html = BeautifulSoup(html, 'lxml')
try:
if currency_iso and not locale_iso:
money = pycountry.currencies.get(alpha_3=currency_iso.upper())
locale_iso = pycountry.countries.get(numeric=money.numeric).alpha_2
if locale_iso:
locale_iso = locale_iso.upper()
country = pycountry.countries.get(alpha_2=locale_iso.upper())
html = html.find('li', text=re.compile(country.name, re.IGNORECASE))
url = html.find('a', id='linkcolor').get('href')
# Store new localized url in distributor_dict.
distributor_dict[self.name]['site']['url'] = url
distributor_dict[self.name]['site']['currency'] = pycountry.currencies.get(numeric=country.numeric).alpha_3
distributor_dict[self.name]['site']['locale'] = locale_iso
# Fetch cookies for new URL.
self.browser.scrape_URL(url)
except:
self.logger.log(DEBUG_OVERVIEW, 'Kept the last configuration {}, {} on {}.'.format(
pycountry.currencies.get(alpha_3=distributor_dict['digikey']['site']['currency']).name,
pycountry.countries.get(alpha_2=distributor_dict['digikey']['site']['locale']).name,
distributor_dict[self.name]['site']['url']
)) # Keep the current configuration.
return