Skip to content

Instantly share code, notes, and snippets.

@alfondotnet
Last active March 26, 2021 15:47
Show Gist options
  • Save alfondotnet/1bcb2dc28a5c34abb1b7f3b3dc44c71e to your computer and use it in GitHub Desktop.
Save alfondotnet/1bcb2dc28a5c34abb1b7f3b3dc44c71e to your computer and use it in GitHub Desktop.
chia alerter
import requests
import re
import time
import random
import subprocess
MAILGUN_API_KEY = 'API_KEY'
MAILGUN_DOMAIN = 'yourdomain.com'
CHIA_ADDRESS = 'CHIA_ADDRESS'
balance_reg = r'Total chia farmed: (\d+\.\d+)'
dest_email = 'your_email@email.com'
origin_email = 'your_email@email.com'
curr_balance = None
def __send_email(email, balance, chia_address, more=True):
if more:
subject = f'CHIA: 🌱 New Chia reward, balance: {balance}'
else:
subject = f'CHIA: Net balance on wallet decreased, balance: {balance}'
data = requests.post('https://api.mailgun.net/v3/{MAILGUN_DOMAIN}/messages',
auth=('api', MAILGUN_API_KEY),
data={
'from': f'Chia alerter <{origin_email}>',
'to': email,
'subject': subject,
'text': f'see: https://www.chiaexplorer.com/blockchain/address/{chia_address}'
})
if data.status_code == 200:
print(f'sent e-mail to {email}')
else:
print(f'error sending e-mail to {email}: {data.text}')
if __name__ == "__main__":
while True:
print(f"Checking balance...")
summary = str(subprocess.check_output(["chia", "farm", "summary"]))
new_balance = re.search(balance_reg, summary)[1]
if curr_balance and new_balance > curr_balance:
__send_email(dest_email, new_balance, CHIA_ADDRESS)
elif curr_balance and new_balance < curr_balance:
__send_email(dest_email, new_balance, CHIA_ADDRESS)
else:
print(f"\t Balance didn't change, {new_balance} == {curr_balance}")
curr_balance = new_balance
# print("\tSetting normal balance..., not sending e-mail")
time.sleep(60 * 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment