parent
204a91b1f6
commit
43a0a9408e
|
@ -78,33 +78,18 @@ class Stock:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.historical.append(parsed)
|
self.historical.append(parsed)
|
||||||
top_data = soup.find(id="quote-header-info")
|
|
||||||
try:
|
|
||||||
self.current_price = float(
|
|
||||||
top_data.findAll("span")[11].string.replace(",", "")
|
|
||||||
)
|
|
||||||
raw_change = top_data.findAll("span")[12].string
|
|
||||||
except IndexError:
|
|
||||||
self.current_price = float(
|
|
||||||
top_data.findAll("span")[3].string.replace(",", "")
|
|
||||||
)
|
|
||||||
raw_change = top_data.findAll("span")[4].string
|
|
||||||
except ValueError:
|
|
||||||
self.current_price = float(
|
|
||||||
top_data.findAll("span")[9].string.replace(",", "")
|
|
||||||
)
|
|
||||||
raw_change = top_data.findAll("span")[10].string
|
|
||||||
|
|
||||||
|
price_selector = f'fin-streamer[data-field="regularMarketPrice"][data-symbol="{self.symbol}"]'
|
||||||
|
price_element = soup.select_one(price_selector)
|
||||||
|
self.current_price = float(price_element.text)
|
||||||
|
|
||||||
self.increase_dollars = float(
|
change_selector = f'fin-streamer[data-field="regularMarketChange"][data-symbol="{self.symbol}"]'
|
||||||
raw_change.split(" ")[0].replace(",", "")
|
change_element = soup.select_one(change_selector)
|
||||||
)
|
self.increase_dollars = float(change_element.text)
|
||||||
self.increase_percent = float(
|
|
||||||
raw_change.split(" ")[1]
|
change_percent_selector = f'fin-streamer[data-field="regularMarketChangePercent"][data-symbol="{self.symbol}"]'
|
||||||
.replace(",", "")
|
change_percent_element = soup.select_one(change_percent_selector)
|
||||||
.replace("(", "")
|
change_percent_text = ''.join([char for char in change_percent_element.text if char in '-.0123456789'])
|
||||||
.replace(")", "")
|
self.increase_percent = float(change_percent_text)
|
||||||
.replace("%", "")
|
|
||||||
)
|
|
||||||
except AttributeError as error:
|
except AttributeError as error:
|
||||||
raise StockDoesNotExistError(ticker) from error
|
raise StockDoesNotExistError(ticker) from error
|
||||||
|
|
Loading…
Reference in New Issue
Block a user