from selenium import webdriver
from urllib.request import urlopen
from bs4 import BeautifulSoup
from selenium.webdriver.chrome.options import Options
import requests

class FinViz:

    def __init__(self, stock_symbol):
    #    chrome_options = Options()
    #    chrome_options.add_argument("--headless")
    #    chrome_options.add_argument("--window-size=1920x1080")
    #    self.driver = webdriver.Chrome(chrome_options=chrome_options, executable_path='C:/Users/Vladio/PycharmProjects/stock_gathering/webdrivers/chromedriver.exe')
        self.base_url = ('https://finviz.com/quote.ashx?t=')
        self.symbol = stock_symbol

 #   def get_stock_symbol(self):
 #       self.symbol = input('Input stock symbol: ')
 #       return self.symbol

    def build_url(self):
        self.full_url = self.base_url + self.symbol
    #    self.driver.get(self.full_url)
        return self.full_url

    def parser(self):
       # client_url = urlopen(self.full_url)
       # self.parse_data = client_url.read()
       # client_url.close()
       self.parse_data = requests.get(self.full_url)
       self.parse_data = self.parse_data.content
       self.parsed_data = BeautifulSoup(self.parse_data, "html.parser")
       return self.parsed_data

    def pull_table_data(self):
        table_data = self.parsed_data.findAll("table", {"id":"news-table"})
        table_rows = table_data[0].findAll("tr")
        print(table_rows[0].text.strip())
        print(table_rows[1].text.strip())
        print(table_rows[2].text.strip())
        print(table_rows[3].text.strip())
