|
| 1 | +# Function used to gather main information |
| 2 | +def stockInformation(url, url1, url2): |
| 3 | + # Requests is used to get the HTML page that we need to parse over |
| 4 | + session = HTMLSession() |
| 5 | + page = session.get(url).text |
| 6 | + |
| 7 | + soup = BeautifulSoup(page, "html5lib") |
| 8 | + |
| 9 | + # For EPS |
| 10 | + session1 = HTMLSession() |
| 11 | + page1 = session1.get(url1).text |
| 12 | + |
| 13 | + soup1 = BeautifulSoup(page1, "html5lib") |
| 14 | + |
| 15 | + # For High and Low |
| 16 | + session2 = HTMLSession() |
| 17 | + page2 = session2.get(url2).text |
| 18 | + |
| 19 | + soup2 = BeautifulSoup(page2, "html5lib") |
| 20 | + |
| 21 | + # Open Price |
| 22 | + openPrice = soup.find("table", class_="W(100%)").findAll("td", {"class" : "Ta(end) Fw(600) Lh(14px)"})[1].text |
| 23 | + |
| 24 | + # High |
| 25 | + high = soup2.find("table", {"data-test" : "historical-prices"}).find("tbody").find("tr", {"class" : "BdT Bdc($seperatorColor) Ta(end) Fz(s) Whs(nw)"}).findAll("td", {"class" : "Py(10px) Pstart(10px)"})[1].find("span").text |
| 26 | + |
| 27 | + # Low |
| 28 | + low = soup2.find("table", {"data-test" : "historical-prices"}).find("tbody").find("tr", {"class" : "BdT Bdc($seperatorColor) Ta(end) Fz(s) Whs(nw)"}).findAll("td", {"class" : "Py(10px) Pstart(10px)"})[2].find("span").text |
| 29 | + |
| 30 | + # Stock Price |
| 31 | + stockPrice = soup.find("fin-streamer", class_="Fw(b) Fz(36px) Mb(-4px) D(ib)").text |
| 32 | + #print(stockPrice) |
| 33 | + |
| 34 | + # Stock Change |
| 35 | + stockChange = soup.find("fin-streamer", class_="Fw(500) Pstart(8px) Fz(24px)").span.text |
| 36 | + #print(stockChange) |
| 37 | + |
| 38 | + # Stock Percentage Change |
| 39 | + StockPercentageChange = soup.find("fin-streamer", {"class" :"Fw(500) Pstart(8px) Fz(24px)", "data-field" : "regularMarketChangePercent"}).span.text[1:-1] |
| 40 | + floatStockChange = float(StockPercentageChange[:-1]) |
| 41 | + #print(floatStockChange) |
| 42 | + |
| 43 | + # EPS |
| 44 | + eps = soup1.find("div", {"class" : "group group--elements left"}).findAll("ul", {"class" : "list list--kv list--col50"})[0].findAll("li", {"class" : "kv__item"})[9].find("span", {"class" : "primary"}).text[1:] |
| 45 | + |
| 46 | + if soup.find("td", {"class" : "Ta(end) Fw(600) Lh(14px)", "data-test" : "ONE_YEAR_TARGET_PRICE-value"}) != None: |
| 47 | + # Investor Confidence (Price in One Year) |
| 48 | + investorConfidence = soup.find("td", {"class" : "Ta(end) Fw(600) Lh(14px)", "data-test" : "ONE_YEAR_TARGET_PRICE-value"}).text |
| 49 | + #print(investorConfidence) |
| 50 | + else: |
| 51 | + investorConfidence = None |
| 52 | + |
| 53 | + volume = float((soup.find("fin-streamer", {"data-field" : "regularMarketVolume"}).text).replace(",", "")) |
| 54 | + |
| 55 | + # stockPrice,stockChange,floatStockChange,investorConfidence,volume,volumePerMinute,month,day,year |
| 56 | + # It's important to remember that the stockChange and floatStockChange are all based on 1 minute transactions. |
| 57 | + # This is to better predict end of the day stock values |
| 58 | + # So as to make sure that the values aren't locked in on the moment, but rather a general trend over the day |
| 59 | + return [openPrice, high, low, stockPrice, float(stockChange) / 390, float(floatStockChange) / 390, investorConfidence, volume, int(volume / 390), datetime.datetime.now().month, datetime.datetime.now().day, datetime.datetime.now().year, "{month}/{day}/{year}".format(day = datetime.datetime.now().day, month = datetime.datetime.now().month, year = datetime.datetime.now().year), 0, eps, float(stockPrice) / float(eps)] |
0 commit comments