How to use the finviz.helper_functions.error_handling.UnexistingPortfolioName function in finviz

To help you get started, we’ve selected a few finviz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mariostoev / finviz / finviz / portfolio.py View on Github external
# 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)