-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbalarm.py
86 lines (57 loc) · 2.75 KB
/
balarm.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import requests
import time
from win10toast import ToastNotifier
from menu import menu, profile
toaster = ToastNotifier()
print(' Welcome in Balarm. Bitcoin notification app for windows')
print('*********************************************************')
# This function will return float number which will represent price of 1 btc in USD.
def get_bitcoin_rate_usd():
r = requests.get('https://api.coindesk.com/v1/bpi/currentprice.json')
bitcoin_rate_usd = r.json()['bpi']['USD']['rate'].replace(',', '')
return round(float(bitcoin_rate_usd))
"""
This function will return number which will represent price of 1 BTC in CZK
bitcoin_rate = number representing price of 1 BTC in USD
"""
def btc_in_czk(bitcoin_rate):
r = requests.get('https://api.exchangerate-api.com/v4/latest/USD')
usd_czk_rate = r.json()['rates']['CZK']
btc_czk_rate = bitcoin_rate * usd_czk_rate
return round(btc_czk_rate)
"""
This function will check if {bitcoin_rate} is more or less then {bitcoin_price}
bitcoin_rate = number representing price of 1 BTC in USD
bitcoin_price = number which represent price of bitcoin you would like to check
"""
def check_bitcoin_rate(bitcoin_rate, bitcoin_price):
if bitcoin_rate > bitcoin_price:
return f'Bitcoin is more than {bitcoin_price}, bitcoin is : {bitcoin_rate}'
else:
return f'Bitcoin is less than {bitcoin_price}, bitcoin is : {bitcoin_rate}'
# returns worth of yours bitcoin in CZK
def czk_bitcoin_worth(price_in_czk):
worth_in_czk = price_in_czk * profile[0][1]
return round(worth_in_czk)
if __name__ == '__main__':
menu()
def czk_bitcoin_worth(price_in_czk):
worth_in_czk = price_in_czk * profile[0][1]
return round(worth_in_czk)
while True:
# Flash notification with btc prices in USD and CZK every two minutes.
if profile[0][2] == 1:
# If user chose CZK
messages_btc = 'HODL'
toaster.show_toast(f" btc is {btc_in_czk(get_bitcoin_rate_usd()):,} K CZK", messages_btc, icon_path='.\\icons\\btc.ico', threaded=True, duration=5)
time.sleep(120)
if profile[0][2] == 2:
# If user chose USD
messages_btc = 'HODL'
toaster.show_toast(f" btc is {get_bitcoin_rate_usd():,} K $", messages_btc, icon_path='.\\icons\\btc.ico', threaded=True, duration=5)
time.sleep(120)
if profile[0][2] == 3:
# If user chose both
messages_btc = f'btc is {btc_in_czk(get_bitcoin_rate_usd()):,} K CZK\nYou own {czk_bitcoin_worth(btc_in_czk(get_bitcoin_rate_usd())):,} CZK '
toaster.show_toast(f" btc is {get_bitcoin_rate_usd():,} K $", messages_btc, icon_path='.\\icons\\btc.ico', threaded=True, duration=7)
time.sleep(120)