buzzkillb

powend.py

Dec 27th, 2019
203
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from denariusrpc.authproxy import AuthServiceProxy, JSONRPCException
  2.  
  3. # rpc_user and rpc_password are set in the denarius.conf file
  4. rpc_connection = AuthServiceProxy("http://%s:%s@127.0.0.1:32369"%("RPCUSER", "RPCPASSWORD"))
  5. import time
  6. import sys
  7. import datetime
  8. import urllib
  9. import json
  10. import requests
  11. from influxdb import InfluxDBClient
  12.  
  13. # Configure InfluxDB connection variables
  14. host = "127.0.0.1" # My Ubuntu NUC
  15. port = 8086 # default port
  16. user = "admin" # the user/password created for the pi, with write access
  17. password = "PASSWORDHERRE"
  18. dbname = "powend" # the database we created earlier
  19. interval = 60 # Sample period in seconds
  20.  
  21. # Create the InfluxDB client object
  22. client = InfluxDBClient(host, port, user, password, dbname)
  23.  
  24. # Enter the sensor details
  25. #sensor_gpio = 4
  26.  
  27. # think of measurement as a SQL table, it's not...but...
  28. measurement = "measurement"
  29. # location will be used as a grouping tag later
  30. blockchain = "denarius"
  31.  
  32. # Run until you get a ctrl^c
  33. #def main():
  34. import time
  35. # last_block = -1
  36. # while True:
  37. # Read the sensor using the configured driver and gpio
  38. denariuswinurl = "https://pos.watch/win.json"
  39. response = urllib.urlopen(denariuswinurl)
  40. windata = json.loads(response.read())
  41. averageblocktime = float(windata['blocktime'])
  42. print (averageblocktime)
  43.  
  44. powend = 3000000
  45. # get latest block count
  46. block = rpc_connection.getblockcount()
  47. blocksleft = powend - block
  48. timeleftsec = blocksleft * averageblocktime
  49. timeleftminutes = timeleftsec / 60
  50. timelefthours = timeleftminutes / 60
  51. timeleftdays = timelefthours / 24
  52.  
  53. # put blockhash from latest block and get extra info
  54. getblockhash = rpc_connection.getblockchaininfo()
  55. bestblockhash = str(getblockhash['bestblockhash'])
  56. getblockhashinfo = rpc_connection.getblock(bestblockhash)
  57. blockhashinfowork = str(getblockhashinfo['flags'])
  58. blockhashinfotime = int(getblockhashinfo['time']) * 1000000000
  59.  
  60. print (powend)
  61. print (block)
  62. print (blocksleft)
  63. print (timeleftsec)
  64. print (timeleftminutes)
  65. print (timelefthours)
  66. print (timeleftdays)
  67.  
  68. from datetime import datetime, timedelta
  69. pewpew = datetime.now()
  70. pewpew += timedelta(seconds=timeleftsec)
  71. powend = str(pewpew)
  72. print (powend)
  73.  
  74. data = [
  75. {
  76. "measurement": measurement,
  77. "tags": {
  78. "blockchain": blockchain,
  79. },
  80. "time": blockhashinfotime,
  81. "fields": {
  82. "block" : block,
  83. "timestamp" : blockhashinfotime,
  84. "powend" : powend,
  85. "averageblocktime" : averageblocktime
  86. }
  87. }
  88. ]
  89. # Send the JSON data to InfluxDB
  90. client.write_points(data)
  91. # Wait until it's time to query again...
  92.  
  93. # last_block = block
  94. # time.sleep(interval)
  95. #main()
RAW Paste Data