Skip to content

Instantly share code, notes, and snippets.

@UdjinM6
Last active April 15, 2016 11:35
Show Gist options
  • Save UdjinM6/1c20957179ffb1f71485 to your computer and use it in GitHub Desktop.
Save UdjinM6/1c20957179ffb1f71485 to your computer and use it in GitHub Desktop.
Fixed: dashninja.pl API usage; Changed: switched to explorer.dash.org to fetch balances
from Tkinter import *
import urllib2
from datetime import datetime
import smtplib
import time
import os
import ConfigParser as con
from appdirs import AppDirs
import json
# $MN$v3
def main():
root = Tk()
root.title("$MN$")
root.resizable(0,0)
def rtnsettingsshow():
btnsettingsshow32.grid_forget()
btnsettingshide32.grid(row=3, column=5)
lblsettingsMNlist.grid(row=4, column=1, columnspan =2)
lstMNlist.grid(row=5, column=1, columnspan =2)
btnMNlistremove.grid(row=5, column=5, sticky = S, columnspan =2)
entryMNadd.grid(row=6, column=1, columnspan =2)
btnMNlistadd.grid(row=6, column=5, columnspan =2)
lblnotifyaddress.grid(row=7, column=1)
entrynotifyaddress.grid(row=7, column=2, sticky = E)
btnnotifyaddresshelp.grid(row=7, column=5, columnspan =2)
lblmnbotaddress.grid(row=8, column=1)
entrymnbotaddress.grid(row=8, column=2, sticky = E)
btnmnbotaddresshelp.grid(row=8, column=5, columnspan =2)
lblmnbotpw.grid(row=9, column=1)
entrymnbotpw.grid(row=9, column=2, sticky = E)
lblIPSetting.grid(row=10,column=1)
rdIPON.grid(row=10,column=2, sticky = W)
rdIPOFF.grid(row=10,column=2)
lblActiveSetting.grid(row=11, column=1)
rdActiveON.grid(row=11,column=2, sticky =W)
rdActiveOFF.grid(row=11, column=2)
lblNotifyActivty.grid(row=12,column=1)
rdActivityON.grid(row=12,column=2, sticky =W)
rdActivityOFF.grid(row=12,column=2)
lblSumSetting.grid(row=13, column=1)
rdSumON.grid(row=13,column=2, sticky =W)
rdSumOFF.grid(row=13, column=2)
btnupdatesettings.grid(row=14, column=5, columnspan =2)
def rtnsettingshide():
btnsettingshide32.grid_forget()
btnsettingsshow32.grid(row=3, column=5)
lblsettingsMNlist.grid_forget()
lstMNlist.grid_forget()
btnMNlistremove.grid_forget()
entryMNadd.grid_forget()
btnMNlistadd.grid_forget()
lblnotifyaddress.grid_forget()
entrynotifyaddress.grid_forget()
btnnotifyaddresshelp.grid_forget()
lblmnbotaddress.grid_forget()
entrymnbotaddress.grid_forget()
btnmnbotaddresshelp.grid_forget()
lblmnbotpw.grid_forget()
entrymnbotpw.grid_forget()
lblIPSetting.grid_forget()
rdIPON.grid_forget()
rdIPOFF.grid_forget()
lblActiveSetting.grid_forget()
rdActiveON.grid_forget()
rdActiveOFF.grid_forget()
lblSumSetting.grid_forget()
rdSumON.grid_forget()
rdSumOFF.grid_forget()
lblNotifyActivty.grid_forget()
rdActivityON.grid_forget()
rdActivityOFF.grid_forget()
btnupdatesettings.grid_forget()
def rtnabout():
AboutWin = Tk()
AboutWin.title('About $MN$')
AboutWin.resizable(0,0)
lblAbout1 = Label (AboutWin, text="I hope this program is useful to you!")
lblAbout1.grid(row=0, column=0)
lblAbout2 = Label (AboutWin, text="Instructions on how to begin can be found at:")
lblAbout2.grid(row=1, column=0)
entryAbout1 = Entry(AboutWin, width=18)
entryAbout1.insert(0,"http://goo.gl/kB2HJd")
entryAbout1.grid(row=3, column=0)
lblAbout3 = Label(AboutWin, text=" ")
lblAbout3.grid(row=4, column=0)
lblAbout4 = Label(AboutWin, text="Donations are welcome!")
lblAbout4.grid(row=5, column=0)
entryAbout2 = Entry(AboutWin, width=35)
entryAbout2.insert(0,"Xwkrxyd1qkBktWUG8HQxqViPwwoAnGpimd")
entryAbout2.grid(row=6, column=0)
def rtnMNlistremove():
mnaddremove=lstMNlist.curselection()
lstMNlist.delete(mnaddremove, mnaddremove)
lstBalanceShow.delete(mnaddremove, mnaddremove)
lstMNshow.delete(mnaddremove, mnaddremove)
lstTimeShow.delete(mnaddremove, mnaddremove)
lstIPshow.delete(mnaddremove, mnaddremove)
lstActiveShow.delete(mnaddremove, mnaddremove)
MNlistsize=lstMNlist.size()
lstMNshow.configure(height=MNlistsize)
lstBalanceShow.configure(height=MNlistsize)
lstTimeShow.configure(height=MNlistsize)
lstActiveShow.configure(height=MNlistsize)
lstIPshow.configure(height=MNlistsize)
def rtnMNlistadd():
mnaddaddress=entryMNadd.get()
lstMNlist.insert(END, mnaddaddress)
entryMNadd.delete(0, END)
lstMNshow.insert(END, mnaddaddress)
lstBalanceShow.insert(END, "-")
lstTimeShow.insert(END, "-")
lstIPshow.insert(END, "-")
lstActiveShow.insert(END, "-")
MNlistsize=lstMNlist.size()
lstMNshow.configure(height=MNlistsize)
lstBalanceShow.configure(height=MNlistsize)
lstTimeShow.configure(height=MNlistsize)
lstActiveShow.configure(height=MNlistsize)
lstIPshow.configure(height=MNlistsize)
def rtnnotifyaddresshelp():
NotifyWin = Tk()
NotifyWin.title('Notify Help')
NotifyWin.resizable(0,0)
lblNotify1 = Label (NotifyWin, text="To receive text message notifcations, use this format:")
lblNotify1.grid(row=0, column=0)
entryNotify1 = Entry(NotifyWin, width=16)
entryNotify1.insert(0,"http://goo.gl/ouiYn")
entryNotify1.grid(row=3, column=0)
def rtnmnbotaddresshelp():
AddressWin = Tk()
AddressWin.title('MN BOT Help')
AddressWin.resizable(0,0)
lblAddress1 = Label (AddressWin, text="Create new gmail account for ONLY this use!!!!")
lblAddress1.grid(row=0, column=0)
lblAddress2 = Label (AddressWin, text="Must disable a security setting at this link:")
lblAddress2.grid(row=1, column=0)
entryAddress1 = Entry(AddressWin, width=17)
entryAddress1.insert(0,"http://goo.gl/jVIYzu")
entryAddress1.grid(row=3, column=0)
def rtnupdatesettings():
del MNlist[:]
MNlistsize=lstMNlist.size()
lpticker=0
while lpticker < MNlistsize:
lpdummy=lstMNlist.get(lpticker)
MNlist.append(lpdummy)
lpticker = lpticker + 1
MNliststring='-'.join(MNlist)
notifyaddress=entrynotifyaddress.get()
mnbotaddress=entrymnbotaddress.get()
mnbotpw=entrymnbotpw.get()
dummyIPsetting =sttngIP.get()
dummyACTIVEsetting =sttngActive.get()
dummySUMsetting =sttngSum.get()
dummyNotifyActivitysetting =sttngActivityNotify.get()
################################
if dummyIPsetting==1:
lstIPshow.grid(row=1, column=3, columnspan =1, rowspan =1, sticky = N)
else:
lstIPshow.grid_forget()
if dummyACTIVEsetting==1:
lstActiveShow.grid(row=1, column=4, columnspan =1, rowspan =1, sticky = N)
else:
lstActiveShow.grid_forget()
if dummySUMsetting==1:
lblsumshow.grid(row=2,column=5, stick = W)
else:
lblsumshow.grid_forget()
###############################
inisettings=con.ConfigParser()
inisettings.add_section("settings")
inisettings.set("settings","MNlist", MNliststring)
inisettings.set("settings","notifyaddress", notifyaddress)
inisettings.set("settings","mnbotaddress", mnbotaddress)
inisettings.set("settings","mnbotpw", mnbotpw)
inisettings.set("settings","ipview", dummyIPsetting)
inisettings.set("settings","activeview", dummyACTIVEsetting)
inisettings.set("settings","sumview", dummySUMsetting)
inisettings.set("settings","notifyactivity", dummyNotifyActivitysetting)
dummy=open(pathnameini,"w")
inisettings.write(dummy)
dummy.close()
if sys.platform == 'win32':
settingsWin = Tk()
settingsWin.title('HEADS UP')
settingsWin.resizable(0,0)
lblAbout1 = Label (settingsWin, text="Some versions of windows require you to ")
lblAbout1.grid(row=0, column=0)
lblAbout2 = Label (settingsWin, text="restart the program after changing settings")
lblAbout2.grid(row=1, column=0)
def rtnpaste1():
clipbrddummy=root.selection_get(selection = "CLIPBOARD")
entryMNadd.delete(0, END)
entryMNadd.insert(0,clipbrddummy)
def popup1(event):
menu1.post(event.x_root, event.y_root)
def rtnpaste2():
clipbrddummy=root.selection_get(selection = "CLIPBOARD")
entrynotifyaddress.delete(0, END)
entrynotifyaddress.insert(0,clipbrddummy)
def popup2(event):
menu2.post(event.x_root, event.y_root)
def rtnpaste3():
clipbrddummy=root.selection_get(selection = "CLIPBOARD")
entrymnbotaddress.delete(0, END)
entrymnbotaddress.insert(0,clipbrddummy)
def popup3(event):
menu3.post(event.x_root, event.y_root)
def rtnpaste4():
clipbrddummy=root.selection_get(selection = "CLIPBOARD")
entrymnbotpw.delete(0, END)
entrymnbotpw.insert(0,clipbrddummy)
def popup4(event):
menu4.post(event.x_root, event.y_root)
def rtngettime():
ze = datetime.now().strftime('%H:%M:%S')
return ze
def rtnshowmessage(dummytext):
msgscreen = Tk()
w = Message(msgscreen, text=dummytext, width=200)
w.pack()
def rtnupdatesum():
lpticker=0
MNlistsize=lstMNlist.size()
drktotal=0
while lpticker < MNlistsize:
try:
drkaddressbalance=lstBalanceShow.get(lpticker)
drkaddint = float(drkaddressbalance)
drktotal = drktotal + drkaddint
lpticker = lpticker +1
except:
lpticker = lpticker + 1
a=("%.2f" % drktotal)
lblsumshow.configure(text=float(a))
def rtngetbalance(MNaddress):
errorstatus=0
try:
urldummy="http://explorer.dash.org/chain/Dash/q/addressbalance/"+MNaddress
usockdummy = urllib2.urlopen(urldummy)
datastr = usockdummy.read()
usockdummy.close()
MNbalancedummy = float(datastr)
a=("%.2f" % MNbalancedummy)
MNbalance=float(a)
return MNbalance
except urllib2.HTTPError as e:
print e.code
print e.read
except:
errorstatus=1
def rtnbalanceupdatecheck():
errorstatus =0
try:
MNlistsize=len(MNlist)
lpticker=0
while lpticker < MNlistsize:
oldbalance=lstBalanceShow.get(lpticker)
dummyaddress= MNlist[lpticker]
dummybalance=rtngetbalance(dummyaddress)
dummytime=rtngettime()
lstTimeShow.delete(lpticker)
lstTimeShow.insert(lpticker, dummytime)
lstBalanceShow.delete(lpticker)
lstBalanceShow.insert(lpticker, dummybalance)
if dummybalance > oldbalance:
dummydifference=dummybalance-oldbalance
dummydifferencestring = str(dummydifference)
mailstring="MN "+dummyaddress+" WAS PAID!! +"+dummydifferencestring
rtnsendmail(mailstring)
rtnshowmessage(mailstring)
lstBalanceShow.delete(lpticker)
lstBalanceShow.insert(lpticker, dummybalance)
lpticker = lpticker + 1
time.sleep(.2)
rtnupdatesum()
except urllib2.HTTPError as e:
print e.code
print e.read
except:
errorstatus=1
root.after(60000, rtnbalanceupdatecheck)
def rtnsendmail(stringmessage):
inigrab=con.ConfigParser()
inigrab.read(pathnameini)
inivaluemnbotaddress=inigrab.get("settings","mnbotaddress")
inivaluemnbotpw=inigrab.get("settings","mnbotpw")
inivaluenotify = inigrab.get("settings","notifyaddress")
if inivaluemnbotaddress == "" or inivaluemnbotpw == "" or inivaluenotify == "":
return;
dummyloginlocation = inivaluemnbotaddress.find('@')
dummylogin = inivaluemnbotaddress[:dummyloginlocation]
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(dummylogin,inivaluemnbotpw)
server.sendmail(inivaluemnbotaddress, inivaluenotify, stringmessage)
server.quit()
def rtnOnlinecheck():
try:
MNlistsize=len(MNlist)
if MNlistsize > 0:
reqList = 'pubkeys=["' + '","'.join(MNlist) + '"]'
urldummy="https://dashninja.pl/api/masternodes?" + reqList
usockdummy = urllib2.urlopen(urldummy)
strResult = usockdummy.read()
usockdummy.close()
lResult = json.loads(strResult)['data']
nResultSize = len(lResult)
lpticker=0
while lpticker < nResultSize:
tempRes = lResult[lpticker]
if tempRes['MasternodePubkey'] in MNlist:
indexFound = MNlist.index(tempRes['MasternodePubkey'])
lstIPshow.delete(indexFound)
lstIPshow.insert(indexFound, tempRes['MasternodeIP'])
intActive = int(tempRes['ActiveCount'])
intInactive = tempRes['InactiveCount']
intUnlisted = tempRes['UnlistedCount']
dummytotal = intActive + intInactive + intUnlisted
dummyActiveRatio = (intActive / dummytotal) * 100
if dummyActiveRatio<=50:
mailstring="MN "+tempRes['MasternodePubkey']+" has dropped below 50% activity!!"
if inivalueACTIVITYnotify=="1":
rtnsendmail(mailstring)
rtnshowmessage(mailstring)
lstActiveShow.delete(indexFound)
lstActiveShow.insert(indexFound, str(dummyActiveRatio) + "%")
lpticker = lpticker + 1
except urllib2.HTTPError as e:
print e.code
print e.read
except:
errorstatus=1
root.after(180000, rtnOnlinecheck)
##################################################################
pathname = AppDirs('MN', 'g8F98FF3gjafogj4').user_data_dir
if not os.path.exists(pathname):
os.makedirs(pathname)
if sys.platform == 'win32':
pathnameini = pathname + "\\MN.ini"
else:
pathnameini = pathname + "/MN.conf"
inivalueMNlist=""
inivaluenotify=""
inivaluemnbotaddress=""
inivaluemnbotpw=""
inivalueIPview=1
inivalueACTIVEview=1
inivalueSUMview=1
inivalueACTIVITYnotify=0
try:
inigrab=con.ConfigParser()
inigrab.read(pathnameini)
inivalueMNlist=inigrab.get("settings","MNlist")
inivaluenotify=inigrab.get("settings","notifyaddress")
inivaluemnbotaddress=inigrab.get("settings","mnbotaddress")
inivaluemnbotpw=inigrab.get("settings","mnbotpw")
inivalueIPview=inigrab.get("settings","ipview")
inivalueACTIVEview=inigrab.get("settings","activeview")
inivalueSUMview=inigrab.get("settings","sumview")
inivalueACTIVITYnotify=inigrab.get("settings","notifyactivity")
except Exception as e:
print e
sttngIP = IntVar()
sttngActive = IntVar()
sttngSum = IntVar()
sttngActivityNotify = IntVar()
##################################################################
lblpad = Label(text=" ")
lblpad.grid(row=1, column=0)
lstMNshow = Listbox(root, width=40, height=1, borderwidth=0, highlightthickness=0, activestyle='none')
lstMNshow.grid(row=1, column=1, columnspan =2, rowspan =2, sticky = N)
#######################
lstIPshow = Listbox(root, width=15, height=1, borderwidth=0, highlightthickness=0, activestyle='none')
if inivalueIPview=="1":
lstIPshow.grid(row=1, column=3, columnspan =1, rowspan =1, sticky = N)
lstActiveShow = Listbox(root, width=7, height=1, borderwidth=0, highlightthickness=0, activestyle='none')
if inivalueACTIVEview=="1":
lstActiveShow.grid(row=1, column=4, columnspan =1, rowspan =1, sticky = W)
lblsumshow = Label(root)
if inivalueSUMview=="1":
lblsumshow.grid(row=2,column=5, stick = W)
##########################
lstBalanceShow = Listbox(root, width=8, height=1, borderwidth=0, highlightthickness=0, activestyle='none')
lstBalanceShow.grid(row=1, column=5, rowspan =1, sticky = W)
lstTimeShow = Listbox(root, height=1, width= 8, borderwidth=0, highlightthickness=0, activestyle='none')
lstTimeShow.grid(row=1, column=6, rowspan =1, sticky = N)
btnsettingsshow32 = Button(root, text="Settings", command=rtnsettingsshow)
btnsettingsshow32.grid(row=3, column=5)
btnsettingshide32 = Button(root, text="Settings", command=rtnsettingshide)
btnabout33 = Button(root, text="About", command=rtnabout)
btnabout33.grid(row=3, column=6)
#########################################################
lblsettingsMNlist = Label(root, text="Masternode List")
lstMNlist = Listbox(root, width=40, height = 6, selectmode=SINGLE)
btnMNlistremove = Button(root, text="Remove", command=rtnMNlistremove)
entryMNadd = Entry(root, width=40)
btnMNlistadd = Button(root, text=" Add ", command=rtnMNlistadd)
lblnotifyaddress = Label(root, text="Notify:")
entrynotifyaddress = Entry(root, width=21)
btnnotifyaddresshelp = Button(root, text=" ? ", command=rtnnotifyaddresshelp)
lblmnbotaddress = Label(root, text="MN BOT Address:")
entrymnbotaddress = Entry(root, width=21)
btnmnbotaddresshelp = Button(root, text=" ? ", command=rtnmnbotaddresshelp)
lblmnbotpw = Label(root, text="MN BOT PW:")
entrymnbotpw = Entry(root, width=21, show="*")
lblIPSetting = Label(root, text="Show IP:",)
rdIPON = Radiobutton(root, text="ON", variable=sttngIP, value=1)
rdIPOFF = Radiobutton(root, text="OFF", variable=sttngIP, value=0)
lblActiveSetting = Label(root, text="Show Activity:")
rdSumON = Radiobutton(root, text="ON", variable=sttngSum, value=1)
rdSumOFF = Radiobutton(root, text="OFF", variable=sttngSum, value=0)
lblNotifyActivty = Label(root, text="Notify Activity Drop",)
rdActiveON = Radiobutton(root, text="ON", variable=sttngActive, value=1)
rdActiveOFF = Radiobutton(root, text="OFF", variable=sttngActive, value=0)
lblSumSetting = Label(root, text="Show Sum:",)
rdActivityON = Radiobutton(root, text="ON", variable=sttngActivityNotify, value=1)
rdActivityOFF = Radiobutton(root, text="OFF", variable=sttngActivityNotify, value=0)
btnupdatesettings = Button(root, text="Update Settings", command=rtnupdatesettings)
######################################################
menu1 = Menu(root, tearoff=0)
menu1.add_command(label="Paste", command=rtnpaste1)
entryMNadd.bind("<Button-3>", popup1)
menu2 = Menu(root, tearoff=0)
menu2.add_command(label="Paste", command=rtnpaste2)
entrynotifyaddress.bind("<Button-3>", popup2)
menu3 = Menu(root, tearoff=0)
menu3.add_command(label="Paste", command=rtnpaste3)
entrymnbotaddress.bind("<Button-3>", popup3)
menu4 = Menu(root, tearoff=0)
menu4.add_command(label="Paste", command=rtnpaste4)
entrymnbotpw.bind("<Button-3>", popup4)
##########################################################
entrynotifyaddress.insert(0,inivaluenotify)
entrymnbotaddress.insert(0,inivaluemnbotaddress)
entrymnbotpw.insert(0,inivaluemnbotpw)
sttngIP.set(inivalueIPview)
sttngActive.set(inivalueACTIVEview)
sttngSum.set(inivalueSUMview)
sttngActivityNotify.set(inivalueACTIVITYnotify)
MNlist = inivalueMNlist.split('-')
MNlistsize=len(MNlist)
lstMNlist.delete(0, END)
lpticker=0
if MNlistsize == 0:
rtnshowmessage("Please configure settings!")
else:
try:
while lpticker < MNlistsize:
lpdummy=MNlist[lpticker]
dummybalancestring=rtngetbalance(lpdummy)
dummybalance=float(dummybalancestring)
dummytime=rtngettime()
lstMNlist.insert(END, lpdummy)
lstMNshow.insert(END, lpdummy)
lstBalanceShow.insert(END, dummybalance)
lstTimeShow.insert(END, dummytime)
lstIPshow.insert(END, "-")
lstActiveShow.insert(END, "-")
lpticker = lpticker + 1
time.sleep(.2)
rtnupdatesum()
except:
errorstats=1
lstMNshow.configure(height=MNlistsize)
lstBalanceShow.configure(height=MNlistsize)
lstTimeShow.configure(height=MNlistsize)
lstIPshow.configure(height=MNlistsize)
lstActiveShow.configure(height=MNlistsize)
##############################
root.after(3000, rtnOnlinecheck)
root.after(60000, rtnbalanceupdatecheck)
root.mainloop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment