forked from MusheAbdulHakim/Bitcoin-Notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
82 lines (62 loc) · 2.1 KB
/
Copy pathmain.py
File metadata and controls
82 lines (62 loc) · 2.1 KB
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
from notifypy import Notify
import time, schedule,locale,pprint
from cli import Cli
from pycoingecko import CoinGeckoAPI
class App():
def __init__(self,api,crypto_coin):
self.coingecko = api
self.notification = Notify()
self.crypto_coin = crypto_coin
self.currency = 'usd'
self.crypto = self.coingecko.get_price(ids=self.crypto_coin, vs_currencies=self.currency)
self.title = f"{self.crypto_coin.title()} Current Price"
self.message = f"The Current Price of {self.crypto_coin.title()} is {self.Price()}"
self.notification.icon = icon
self.notification.audio = sound
def notifyMe(self):
self.notification.title = self.title
self.notification.message = self.message
self.notification.send()
def Price(self):
coin_price = 0
for price in self.crypto:
coin_price = self.crypto[price]
return locale.currency(coin_price[self.currency], grouping=True)
def getCoinList(self):
coins_list = self.coingecko.get_coins_list()
return coins_list
def getCurrencies(self):
currencies = self.coingecko.get_supported_vs_currencies()
return currencies
locale.setlocale(locale.LC_ALL, '')
icon = "./images/bitcoin.png"
sound = "./sounds/gilfoyle_alert.wav"
cli = Cli()
time_type = cli.time_type
notify_time = cli.time
crypto_currency = cli.crypto
if cli.time == None:
notify_time = 1
if cli.time_type == None:
time_type = 'minutes'
if cli.crypto == None:
crypto_currency = 'bitcoin'
api = CoinGeckoAPI()
app = App(api,crypto_currency)
pp = pprint.PrettyPrinter(indent=4,compact=True)
if cli.getCoins:
pp.pprint(app.getCoinList())
if cli.getCurrencies:
pp.pprint(app.getCurrencies())
def get_notification():
return app.notifyMe()
try:
if time_type =='seconds':
schedule.every(int(notify_time)).seconds.do(get_notification)
schedule.every(int(notify_time)).minutes.do(get_notification)
#loop for our schedules
while True:
schedule.run_pending()
time.sleep(1)
except Exception as e:
print(e)