Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DYN Coin Google Home notification
#!/usr/bin/python
import subprocess
import time
import json
import requests
EARL = 'http://10.0.0.145:5000/play/cha.m4a'
CMD = '~/dynamic-1.5.0/bin/dynamic-cli getwalletinfo'
BALANCE = -1.0
def getBalance():
output = subprocess.Popen(CMD, shell=True, stdout=subprocess.PIPE)
json_str, _ = output.communicate()
jsonObject = json.loads(json_str)
global BALANCE
BALANCE = float(jsonObject["balance"])
return BALANCE
def didChange():
global BALANCE
prevBalance = BALANCE
BALANCE = getBalance()
if prevBalance < BALANCE and prevBalance != -1.0:
return True
return False
def sendNotification():
requests.get(EARL)
while True:
if didChange() == True:
print(BALANCE)
sendNotification()
else:
print(BALANCE)
print 'Kahjit got warez if you got coin'
time.sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment