├── README.md └── price-alert.py /README.md: -------------------------------------------------------------------------------- 1 | ## cryptocurrency-price-alert 2 | 3 | Ubuntu desktop notification alerts for Bitcoin, Etherium and Litecoin prices. 4 | 5 | ### Requirements 6 | 1. `requests` (pip install -U requests) 7 | 2. `schedule` (pip install -U schedule) 8 | 9 | ### Usage 10 | Change the global variable `ALERT_INTERVAL` to a desired value (default 30 minutes) and run `price-alert.py` -------------------------------------------------------------------------------- /price-alert.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #-*- coding: utf-8 -*- 3 | 4 | import subprocess 5 | import requests 6 | import schedule 7 | import time 8 | 9 | btc_usd = 'https://api.cryptonator.com/api/full/btc-usd' 10 | eth_usd = 'https://api.cryptonator.com/api/full/eth-usd' 11 | ltc_usd = 'https://api.cryptonator.com/api/full/ltc-usd' 12 | 13 | ALERT_INTERVAL = 30 14 | 15 | def sendmessage(message): 16 | subprocess.Popen(['notify-send', message]) 17 | return 18 | 19 | 20 | def get_btc_usd(): 21 | try: 22 | r = requests.get(btc_usd).json() 23 | price = int(float(r['ticker']['price'])) 24 | return unicode(price) 25 | except: 26 | return '??' 27 | 28 | 29 | def get_eth_usd(): 30 | try: 31 | r = requests.get(eth_usd).json() 32 | price = round(float(float(r['ticker']['price'])), 1) 33 | return unicode(price) 34 | except: 35 | return '??' 36 | 37 | 38 | def get_ltc_usd(): 39 | try: 40 | r = requests.get(ltc_usd).json() 41 | price = round(float(float(r['ticker']['price'])), 2) 42 | return unicode(price) 43 | except: 44 | return '??' 45 | 46 | 47 | def send_notification(): 48 | message = 'BTC: '+get_btc_usd()+' | '+'ETH: '+get_eth_usd()+' | '+'LTC: '+get_ltc_usd() 49 | sendmessage(message) 50 | 51 | if __name__ == '__main__': 52 | schedule.every(ALERT_INTERVAL).minutes.do(send_notification) 53 | while True: 54 | schedule.run_pending() 55 | time.sleep(1) 56 | 57 | --------------------------------------------------------------------------------