Advertisement
Eremite

deepbit.net mining status page generator (AutoIt)

Jul 28th, 2012
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 8.35 KB | None | 0 0
  1. #cs ----------------------------------------------------------------------------
  2.  
  3.  AutoIt Version: 3.3.6.1
  4.  Author:         Eremite
  5.  
  6.  ###########################################################
  7.  DONATE via bitcoin: 1LWz9cn4XtRCQgfdAVfsuTcsh4EhgM564K
  8.  ###########################################################
  9.  
  10.  Script Function:
  11.     Generate a simple html document with information about your miners/workers in a pretty, sortable table.
  12.     Combine with DropBox shared folders to have a link you can visit offline or include in an <iframe> etc.
  13.  
  14. #ce ----------------------------------------------------------------------------
  15.  
  16. ;#############################################################################################
  17. ;These are the options to edit.  Output file = location where the .html file is generated.
  18. ;Note that you should have the sorttable.js , miners.css and miner.gif file in the same dir
  19. ;I tried to use divs with IDs liberally so that styling can be done through CSS exclusively.
  20. ;#############################################################################################
  21.  
  22. ;The output file path.  By default, I have it set to \stats\miners.htm
  23. Global $Output = @ScriptDir & "\stats\miners.htm"
  24. ;time in second between update.  default is 5 minutes (300sec)
  25. Global $UpdateDelay=300
  26. ;time in seconds to auto-refresh the webpage when viewing the results.
  27. Global $AutoRefreshDelay = 60
  28. ;Deepbit.net primary email address for trimming it out of the user-name:
  29. Global $DBEmail = "me@you.us"
  30. ;The JSON URL from https://deepbit.net/settings  Copy the "API" link location, or simply
  31. ;replace the numbers below with your API token.
  32. $JSONURL = "http://deepbit.net/api/123"
  33.  
  34. ;#############################################################################################
  35. ;scripty stuff goes below here.  No need to mess with this unless you know what you're doing.
  36. ;   See comments below to see what the script is doing and make sure it's not haxxing you.
  37. ;#############################################################################################
  38.  
  39. #include <Constants.au3>
  40.  
  41. ; Options to change how the tray icon works.  Disables pause on click.
  42. ; Double click = Force an update, double-right-click = close
  43. AutoItSetOption("TrayAutoPause",0)
  44. AutoItSetOption("TrayMenuMode",1)
  45. AutoItSetOption("TrayOnEventMode",1)
  46. TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE,"GenerateStatus")
  47. TraySetOnEvent($TRAY_EVENT_SECONDARYDOUBLE,"Quit")
  48.  
  49. ;declare globals since AutoIt bitches if they're not declared.
  50. Global $Shares,$Alive,$Worker,$Stale,$ActiveWorkers,$JSON,$TotalWorkers
  51.  
  52.  
  53. While 1  ;basic loop, calls the generate status function every X seconds.
  54.     GenerateStatus()
  55.     Sleep($UpdateDelay*1000)
  56. WEnd
  57.  
  58. ;meat and potatoes
  59.  
  60. Func GenerateStatus() ; Downloads and parses JSON string using Regex since AutoIt has no JSON UDFs that i'm aware of.
  61.     $Date = @YEAR & "/" & @MON & "/" & @MDAY & " @ " & @HOUR & ":" & @MIN & ":" & @SEC
  62.     $JSON = GetJSON() ;workaround for grabbing JSON data from URL since I'm not aware of a UDF for this.
  63.     $TotalReward = StringRegExpReplace($JSON,'{"confirmed_reward":([0-9]*\.[0-9]*).*',"$1") ; Read reward armount (pending)
  64.     $TotalPayouts = StringRegExpReplace($JSON,'.*,"payout_history":(.*),"workers":.*',"$1") ; Read payout history
  65.     $HashRate = StringRegExpReplace($JSON,'.*hashrate":(.*),"ipa":.*',"$1") ; Read Hash Rate
  66.     $JSON = StringRegExpReplace($JSON,'{"confirmed.*workers":{(.*)}}',",$1") ; Now that we have that info, we re-assign JSON to only contain the Workers section.
  67.     ParseWorkers() ; and then we parse that data into an array.
  68.     FileDelete($Output) ; Delete the existing output file before writing to it.
  69.     #EndRegion
  70.     #region Generate Player Table
  71.     ;Woohoo!  We have a buttload of data now, so lets write it all into an HTML document!
  72.     FileWriteLine($Output,'<html><head>')
  73.     FileWriteLine($Output,'  <link rel="stylesheet" href="miners.css" type="text/css" />') ; include miners.css for custom formatting and whatnot
  74.     FileWriteLine($Output,'  <script src="sorttable.js"></script>') ; Include sorttable.js to let you click the tables to sort them. :D
  75.     FileWriteLine($Output,'  <script src="https://code.jquery.com/jquery-latest.js"></script>') ; jquery
  76.     FileWriteLine($Output,'  <meta http-equiv="refresh" content="' & $AutoRefreshDelay & '">')
  77.     FileWriteLine($Output,'  <title>' & $ActiveWorkers & " Miners@" & $HashRate & 'Mhash/s</title>') ; Add small summary to tab name
  78.     FileWriteLine($Output,'</head><body>')
  79.     FileWriteLine($Output,'  <div id="leftPanel">')
  80.     FileWriteLine($Output,'    <div class="minerScript">')
  81.     FileWriteLine($Output,'      <img src="miner.gif"/>Mining for Bitcoins!<br/>') ; cute little image.  Feel free to replace it.
  82.     FileWriteLine($Output,'    </div>')
  83.     FileWriteLine($Output,'    <div id="miningStats">')
  84.     FileWriteLine($Output,'      <div id="miningStatsHeader"><b>' & $ActiveWorkers & ' of ' & $TotalWorkers[0] & ' workers @ ' & $HashRate & 'Mhash/sec<br />')
  85.     FileWriteLine($Output,'        <span id="pending">' & StringTrimRight($TotalReward,4) & ' pending</span> + <span id="paidout">' & _
  86.                                    $TotalPayouts & 'paid</span> :: <span id="totalpaid">' & StringTrimRight(($TotalReward + $TotalPayouts),4) & '</span> total. </div>')
  87.     ;Building the player Table
  88.     FileWriteLine($Output,'      <div id="miningStatsTable">')
  89.     FileWriteLine($Output,'        <table width="100%" class="sortable" align="left">')
  90.     FileWriteLine($Output,'        <thead>')
  91.     FileWriteLine($Output,'          <tr>')
  92.     FileWriteLine($Output,'            <th width="40%">Name</th>')
  93.     FileWriteLine($Output,'            <th width="30%">Shares</th>')
  94.     FileWriteLine($Output,'            <th width="15%">Stale</th>')
  95.     FileWriteLine($Output,'            <th width="15%">%</th>')
  96.     FileWriteLine($Output,'          </tr>')
  97.     FileWriteLine($Output,'        </thead>')
  98.     FileWriteLine($Output,'        <tbody>')
  99.     For $i = 1 to $TotalWorkers[0] Step 1
  100.         If $Shares[$i] <> 0 Then ; Only show miners with more than 1 share submitted.
  101.             FileWriteLine($Output,'          <tr>')
  102.             If $Alive[$i] = "true" Then
  103.                 FileWriteLine($Output,'          <td><span class="OnlineMiner">' & $Worker[$i] & '</span></td>')
  104.             Else
  105.                 FileWriteLine($Output,'          <td><span class="OfflineMiner">' & $Worker[$i] & '</span></td>')
  106.             EndIf
  107.             FileWriteLine($Output,'            <td>'& $Shares[$i] &'</td>')
  108.             FileWriteLine($Output,'            <td>'& $Stale[$i] &'</td>')
  109.             FileWriteLine($Output,'            <td>'& Round((($Shares[$i]-$Stale[$i])/$Shares[$i])*100,2) &'%</td>')
  110.             FileWriteLine($Output,'          </tr>')
  111.         EndIf
  112.     Next
  113.     FileWriteLine($Output,'    </tbody>')
  114.     FileWriteLine($Output,'  </table><hr><center>Updated: ' & $Date & '</center></div>')
  115.     FileWriteLine($Output,'  </div>')
  116.     FileWriteLine($Output,'  </div>')
  117.     ;End Player Table
  118.     FileWriteLine($Output,'</body></html>')
  119.     ;End of HTML
  120.     #Region DEBUG
  121.     ConsoleWrite( @CRLF & "-==========(JSON PARSE RESULTS)==========-" & @CRLF & _
  122.     "Total Reward :: " & $TotalReward & @CRLF & _
  123.     "   Hash Rate :: " & $HashRate & @CRLF & _
  124.     "---Workers-----------------------------------------" & @CRLF & _
  125.     $JSON & @CRLF & @CRLF)
  126.     #endregion DEBUG
  127. EndFunc
  128.  
  129. Func ParseWorkers() ; More regex crap here. Basically creating a series of Arrays with worker information in them.
  130.     $JSON = StringTrimLeft(StringRegExpReplace($JSON,',"' & $DBEmail & '_',"|",0),1)
  131.     Global $TotalWorkers = StringSplit($JSON,"|")
  132.     Global $Worker[$TotalWorkers[0]+1],$Alive[$TotalWorkers[0]+1],$Shares[$TotalWorkers[0]+1],$Stale[$TotalWorkers[0]+1]
  133.     Global $ActiveWorkers = 0
  134.     For $i = 1 To UBound($TotalWorkers) - 1 Step 1
  135.         $Alive[$i] = StringRegExpReplace($TotalWorkers[$i],'.*{"alive":(.*),"shares.*}',"$1")
  136.         $Worker[$i] = StringRegExpReplace($TotalWorkers[$i],'(.*)":{"alive".*',"$1")
  137.         $Shares[$i] = StringRegExpReplace($TotalWorkers[$i],'.*,"shares":([0-9]*),"stales".*',"$1")
  138.         $Stale[$i] = StringRegExpReplace($TotalWorkers[$i],'.*,"stales":([0-9]*)}',"$1")
  139.         If $Alive[$i]="true" Then $ActiveWorkers = $ActiveWorkers + 1
  140.         ConsoleWrite($TotalWorkers[$i] & "   " &  $Alive[$i] & "   " & $Worker[$i] & "   " & $Shares[$i] & "   " & $Stale[$i] & @CRLF) ; debugging
  141.     Next
  142. EndFunc
  143.  
  144. Func GetJSON() ; silly way of grabbing the JSON string and assigning it to a variable.
  145.     InetGet($JSONURL,@TempDir & "\json.txt",1)
  146.     Local $Return = FileReadLine(@TempDir & "\json.txt",1)
  147.     FileDelete(@TempDir & "\json.txt")
  148.     Return $Return
  149. EndFunc
  150.  
  151. Func Quit()
  152.     Exit
  153. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement