-
Notifications
You must be signed in to change notification settings - Fork 13
/
price-alert.py
56 lines (42 loc) · 1.24 KB
/
price-alert.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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import subprocess
import requests
import schedule
import time
btc_usd = 'https://api.cryptonator.com/api/full/btc-usd'
eth_usd = 'https://api.cryptonator.com/api/full/eth-usd'
ltc_usd = 'https://api.cryptonator.com/api/full/ltc-usd'
ALERT_INTERVAL = 30
def sendmessage(message):
subprocess.Popen(['notify-send', message])
return
def get_btc_usd():
try:
r = requests.get(btc_usd).json()
price = int(float(r['ticker']['price']))
return unicode(price)
except:
return '??'
def get_eth_usd():
try:
r = requests.get(eth_usd).json()
price = round(float(float(r['ticker']['price'])), 1)
return unicode(price)
except:
return '??'
def get_ltc_usd():
try:
r = requests.get(ltc_usd).json()
price = round(float(float(r['ticker']['price'])), 2)
return unicode(price)
except:
return '??'
def send_notification():
message = 'BTC: '+get_btc_usd()+' | '+'ETH: '+get_eth_usd()+' | '+'LTC: '+get_ltc_usd()
sendmessage(message)
if __name__ == '__main__':
schedule.every(ALERT_INTERVAL).minutes.do(send_notification)
while True:
schedule.run_pending()
time.sleep(1)