Example #1
0
    def __init__(self, email, password, portfolio=None):
        """
        Logs in to FinViz and send a GET request to the portfolio.
        """

        payload = {"email": email, "password": password}

        # Create a session and log in by sending a POST request
        self._session = requests.session()
        auth_response = self._session.post(
            LOGIN_URL,
            data=payload,
            headers={"User-Agent": generate_user_agent()})

        if not auth_response.ok:  # If the post request wasn't successful
            auth_response.raise_for_status()

        # Get the parsed HTML and the URL of the base portfolio page
        self._page_content, self.portfolio_url = http_request_get(
            url=PORTFOLIO_URL, session=self._session, parse=False)

        # If the user has not created a portfolio it redirects the request to <url>?v=2)
        self.created = True
        if self.portfolio_url == f"{PORTFOLIO_URL}?v=2":
            self.created = False

        if self.created:
            if portfolio:
                self._page_content, _ = self.__get_portfolio_url(portfolio)

            self.data = get_table(self._page_content, PORTFOLIO_HEADERS)
Example #2
0
def get_crypto(pair):
    """

    :param pair: crypto pair
    :return: dictionary
    """

    page_parsed, _ = http_request_get(url=CRYPTO_URL, parse=True)
    page_html, _ = http_request_get(url=CRYPTO_URL, parse=False)
    crypto_headers = page_parsed.cssselect('tr[valign="middle"]')[0].xpath('td//text()')
    crypto_table_data = get_table(page_html, crypto_headers)

    return crypto_table_data[pair]