Advertisement
Guest User

Untitled

a guest
Nov 27th, 2017
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. import json
  2. import urllib.request
  3. import time
  4. import smtplib
  5. import datetime
  6.  
  7. url = "http://dbix.pool.sexy/api/accounts/0x1602928a5aeb0a1d73ea36891e134a3dddb9838c"
  8. data = json.load(urllib.request.urlopen(url))
  9. # print(data) - shows all data
  10.  
  11. # Gets whether or not selected rig is offline or online
  12. def isRigOffline(rigName):
  13. return str(data["workers"][rigName]["offline"])
  14.  
  15.  
  16.  
  17. def sendEmail(rigName):
  18. from email.mime.text import MIMEText
  19.  
  20. fromx = 'minerslj@gmail.com'
  21. to = 'ljlimitedbusiness@gmail.com'
  22. msg = MIMEText(rigName + " is offline!")
  23. msg['Subject'] = rigName + " is offline!"
  24. msg['From'] = fromx
  25. msg['To'] = to
  26.  
  27. server = smtplib.SMTP('smtp.gmail.com:587')
  28. server.starttls()
  29. server.ehlo()
  30. server.login('minerslj@gmail.com', 'fazazjimmy123')
  31. server.sendmail(fromx, to, msg.as_string())
  32. server.quit()
  33.  
  34. print('Timestamp: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()))
  35. print("Email sent to notify that " + rigName + " is offline!")
  36. print("-------------------------------")
  37.  
  38. global rigName, x
  39.  
  40. while True:
  41. try:
  42. # loop through every selected rig
  43. rigName = ["c1r1", "c1r2",
  44. "c2r1", "c2r2",
  45. "c3r1", "c3r2",
  46. "c4r1-j", "c4r2",
  47. "c5r1-j", "c5r2",
  48. "c6r1-j", "c6r2-j",
  49. "c7r1", "c7r2",
  50. "c8r1", "c8r2",
  51. "c9r1", "c9r2",
  52. "c10r1", "c10r2",
  53. "c11r1", "c11r2",
  54. "c12r1", "c12r2",
  55. "c13r1", "c13r2",
  56. "c14r1", "c14r2",
  57. "c15r1"]
  58. size = len(rigName)
  59. x = 0
  60. while x < size:
  61. # only send an email if the rig is offline
  62. if (isRigOffline(rigName[x]) == "True"):
  63. sendEmail(rigName[x])
  64. x += 1
  65.  
  66. except: # if we try to look specifically for the rig and it's not appearing then it's offline
  67. #sendEmail(rigName[x])
  68. print(rigName[x] + " is completely offline")
  69.  
  70. # keep this looping every 10 minutes
  71. time.sleep(1200)
  72.  
  73. # reload the data after 10 mins
  74. data = json.load(urllib.request.urlopen(url))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement