Last active
March 26, 2021 15:47
-
-
Save alfondotnet/1bcb2dc28a5c34abb1b7f3b3dc44c71e to your computer and use it in GitHub Desktop.
chia alerter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = '[email protected]' | |
origin_email = '[email protected]' | |
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