Created
November 22, 2021 18:23
-
-
Save hahaschool/47da9ca80412e045ad5114474cff1c84 to your computer and use it in GitHub Desktop.
SimplePuffMonitor
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 web3 | |
import time | |
import requests | |
import urllib.request, json | |
import os | |
def telegram_bot_sendtext(bot_message): | |
bot_token = '' # insert your tg bot key | |
bot_chatID = '' # https://medium.com/@ManHay_Hong/how-to-create-a-telegram-bot-and-send-messages-with-python-4cf314d9fa3e | |
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=Markdown&text=' + bot_message | |
response = requests.get(send_text) | |
return response.json() | |
def play_alarm_macos(alert_msg): | |
os.system('afplay <some.wav/.aiff files>') # Play something loud to wake you up! | |
os.system('say "' + alert_msg + '"') | |
if __name__ == '__main__': | |
print('PuffMonitor initiated') | |
# Setup web3 interface | |
w3 = web3.Web3(web3.Web3.HTTPProvider('https://mainnet.infura.io/v3/<replace_with_infura_project_id>')) | |
# Load contract | |
GBAC_contract_address = '0x916758C4588D0614488F2C53dDC6c337a245d7d7' | |
with urllib.request.urlopen("https://api.etherscan.io/api?module=contract&action=getabi&address=0x916758c4588d0614488f2c53ddc6c337a245d7d7") as url: | |
info_json = json.loads(url.read().decode()) | |
print("Loading ABI...") | |
print(info_json) | |
GBAC_abi = info_json["result"] | |
GBAC_instance = w3.eth.contract(address=GBAC_contract_address, abi=GBAC_abi) | |
wallets_to_monitor = ['<wallet_addr_here>'] | |
expected_wallet_counts = {'<wallet_addr_here>': 2} | |
# Telegram setting | |
while True: | |
for cur_wallet in wallets_to_monitor: | |
cur_wallet_GBAC_count = GBAC_instance.functions.balanceOf(cur_wallet).call() | |
print(cur_wallet, '@', w3.eth.block_number, ':', cur_wallet_GBAC_count) | |
if cur_wallet_GBAC_count != expected_wallet_counts[cur_wallet]: | |
alert_msg = 'GBAC number not as expected for wallet ' + cur_wallet + ', your Mob may have arrived!' + '(expected ' + str(expected_wallet_counts[cur_wallet]) + ' current ' + str(cur_wallet_GBAC_count) + ')' | |
print(alert_msg) | |
telegram_bot_sendtext(alert_msg) | |
play_alarm_macos(alert_msg) | |
time.sleep(60) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment