Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __get_portfolio_url(self, portfolio_name):
""" Private function used to return the portfolio url from a given id/name. """
# If the user has provided an ID (Portfolio ID is always an int)
if isinstance(portfolio_name, int):
# Raise error for invalid portfolio ID
if not len(str(portfolio_name)) == PORTFOLIO_DIGIT_COUNT:
raise InvalidPortfolioID(portfolio_name)
else:
return http_request_get(url=f"{PORTFOLIO_URL}?pid={portfolio_name}",
session=self._session,
parse=False)
else: # else the user has passed a name
# We remove the first element, since it's redundant
for portfolio in parse(self._page_content).cssselect('option')[1:]:
if portfolio.text == portfolio_name:
return http_request_get(url=f"{PORTFOLIO_URL}?pid={portfolio.get('value')}",
session=self._session,
parse=False)
# Raise UnexistingPortfolioName if none of the names match
raise UnexistingPortfolioName(portfolio_name)