-
Notifications
You must be signed in to change notification settings - Fork 2
/
bitcoin_price_notifier.py
70 lines (61 loc) · 2.32 KB
/
bitcoin_price_notifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import requests
import time
from bs4 import BeautifulSoup
import datetime
from colorama import (init, Fore)
import os
from playsound import playsound
init()
os.system('cls')
def run_tracker():
url = 'https://finance.yahoo.com/quote/BTC-USD?p=BTC-USD&.tsrc=fin-srch'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'lxml')
price = soup.find_all('div', {'class':'D(ib) smartphone_Mb(10px) W(70%) W(100%)--mobp smartphone_Mt(6px)'})[0].find('span').text
return price
last_price = 0.0
float_last_price = float(last_price)
print('Current Btc value: ', run_tracker(), '$')
bell_value = input('Notify me if value is under: ')
print('')
while True:
ts = datetime.datetime.now()
current_price = run_tracker()
corrected_current_price_1 = current_price.replace('.','')
corrected_current_price_final = corrected_current_price_1.replace(',','')
corrected_current_price_final = float(corrected_current_price_final)
def bell_check():
if (int(corrected_current_price_final/100) < int(bell_value)) :
print(' 🔔')
playsound('alert.wav')
if (corrected_current_price_final > float_last_price):
change = corrected_current_price_final - float_last_price
print ('BitCoin: ', end = '')
print(run_tracker(), '$', end = '')
print (' | ', end = '')
print(ts, end = '')
print (' | ', end = '')
print(Fore.GREEN + ' UP', end = '')
print (' +', end = '')
print(change / 100, end = '')
print(' $', end = '')
print(Fore.WHITE + '', end = '')
float_last_price = corrected_current_price_final
bell_check()
print('')
elif (corrected_current_price_final < float_last_price):
change = float_last_price - corrected_current_price_final
print ('BitCoin: ', end = '')
print(run_tracker(), '$', end = '')
print (' | ', end = '')
print(ts, end = '')
print (' | ', end = '')
print(Fore.RED + ' DOWN', end = '')
print (' -', end = '')
print(change / 100, end = '')
print(' $', end = '')
print(Fore.WHITE + '', end = '')
float_last_price = corrected_current_price_final
bell_check()
print('')
time.sleep(5)