Skip to content

Instantly share code, notes, and snippets.

@roelandp
Created December 26, 2018 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roelandp/157f6a8522ae235d83bbadd151123220 to your computer and use it in GitHub Desktop.
Save roelandp/157f6a8522ae235d83bbadd151123220 to your computer and use it in GitHub Desktop.
Alert Telegram bot for once you become active witness on bitshares (run as crontab) (will ping everytime, dumb script, could use some STATE for saving - e.g. pickle) Need to add telegram_token & telegram_id and update "myname" to yours
#!/usr/bin/env python3
from bitshares import BitShares
from bitshares.blockchain import Blockchain
from bitshares.account import Account
from bitshares.instance import set_shared_bitshares_instance
from bitshares.witness import Witness
import requests
websocket = "wss://btsws.roelandp.nl/ws"
bitshares = BitShares(websocket)
set_shared_bitshares_instance(bitshares)
#witness accountname to monitor:
myname = "roelandp"
telegram_token = "STRING" # Create your Telegram bot at @BotFather (https://telegram.me/botfather)
telegram_id = INT # Get your telegram id at @MyTelegramID_bot (https://telegram.me/mytelegramid_bot)
# Telegram barebones apicall
def telegram(method, params=None):
url = "https://api.telegram.org/bot"+telegram_token+"/"
params = params
r = requests.get(url+method, params = params).json()
return r
# Telegram notifyer
def alert_witness(msg):
# Send TELEGRAM NOTIFICATION
payload = {"chat_id":telegram_id, "text":msg,"parse_mode":"HTML"}
m = telegram("sendMessage", payload)
for wid in Blockchain().config()['active_witnesses']:
w = Witness(wid)
a = Account(w['witness_account'])
if a.name == myname:
print(a.name)
alert_witness("you have become active again on bitshares! Check your pricefeeds!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment