May-23-2020, 11:41 PM
(May-23-2020, 02:49 PM)Calli Wrote: One thing left is that can i keep this program running on the terminal and see the price change's in real time using the terminal how can i accomplish this in python
Output:E:\div_code\scrape
λ python stock_schedule.py
--- Sat, May 23, 2020 10:56 PM ---
-------------BTC Price------------
$9,199.46 +$5.0197 (+0.05%)
-------------ETH Price------------
$207.42 -$0.5514 (-0.27%)
--- Sat, May 23, 2020 10:57 PM ---
-------------BTC Price------------
$9,199.46 +$5.0197 (+0.05%)
-------------ETH Price------------
$207.42 -$0.5514 (-0.27%)
--- Sat, May 23, 2020 10:58 PM ---
-------------BTC Price------------
$9,199.46 +$5.0197 (+0.05%)
-------------ETH Price------------
$207.42 -$0.5514 (-0.27%)
--- Sat, May 23, 2020 10:59 PM ---
-------------BTC Price------------
$9,199.46 +$5.0197 (+0.05%)
-------------ETH Price------------
$207.42 -$0.5514 (-0.27%)
Something like this,so here using schedule.So need to organize your code in functions,as i already has written this then can just show code rather than bother with hints.
# pip install schedule, pendulum from bs4 import BeautifulSoup import requests import schedule import pendulum import time def stock(): requestbtc = requests.get("https://bitscreener.com/coins/bitcoin") requestseth = requests.get("https://bitscreener.com/coins/ethereum") content1 = requestbtc.content content2 = requestseth.content soup1 = BeautifulSoup(content1,"html.parser") soup2 = BeautifulSoup(content2,"html.parser") element1 = soup1.find('div',{"class":"header-price-container"}) btc = element1.text.strip().replace('\n',' \t ') element2 = soup2.find('div',{"class":"header-price-container"}) eth = element2.text.strip().replace('\n',' \t ') return btc, eth def display_prices(btc, eth): now = pendulum.now() print(f'--- {now.to_day_datetime_string()} ---' ) print("-------------BTC Price------------") print(btc) print("-------------ETH Price------------") print(eth) print('\n' * 2) if __name__ == '__main__': btc, eth = stock() #display_prices(btc, eth) schedule.every(1).minutes.do(display_prices, btc=btc, eth=eth) while 1: schedule.run_pending() time.sleep(1)