Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #cs ----------------------------------------------------------------------------
- AutoIt Version: 3.3.6.1
- Author: Eremite
- ###########################################################
- DONATE via bitcoin: 1LWz9cn4XtRCQgfdAVfsuTcsh4EhgM564K
- ###########################################################
- Script Function:
- Generate a simple html document with information about your miners/workers in a pretty, sortable table.
- Combine with DropBox shared folders to have a link you can visit offline or include in an <iframe> etc.
- #ce ----------------------------------------------------------------------------
- ;#############################################################################################
- ;These are the options to edit. Output file = location where the .html file is generated.
- ;Note that you should have the sorttable.js , miners.css and miner.gif file in the same dir
- ;I tried to use divs with IDs liberally so that styling can be done through CSS exclusively.
- ;#############################################################################################
- ;The output file path. By default, I have it set to \stats\miners.htm
- Global $Output = @ScriptDir & "\stats\miners.htm"
- ;time in second between update. default is 5 minutes (300sec)
- Global $UpdateDelay=300
- ;time in seconds to auto-refresh the webpage when viewing the results.
- Global $AutoRefreshDelay = 60
- ;Deepbit.net primary email address for trimming it out of the user-name:
- Global $DBEmail = "me@you.us"
- ;The JSON URL from https://deepbit.net/settings Copy the "API" link location, or simply
- ;replace the numbers below with your API token.
- $JSONURL = "http://deepbit.net/api/123"
- ;#############################################################################################
- ;scripty stuff goes below here. No need to mess with this unless you know what you're doing.
- ; See comments below to see what the script is doing and make sure it's not haxxing you.
- ;#############################################################################################
- #include <Constants.au3>
- ; Options to change how the tray icon works. Disables pause on click.
- ; Double click = Force an update, double-right-click = close
- AutoItSetOption("TrayAutoPause",0)
- AutoItSetOption("TrayMenuMode",1)
- AutoItSetOption("TrayOnEventMode",1)
- TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE,"GenerateStatus")
- TraySetOnEvent($TRAY_EVENT_SECONDARYDOUBLE,"Quit")
- ;declare globals since AutoIt bitches if they're not declared.
- Global $Shares,$Alive,$Worker,$Stale,$ActiveWorkers,$JSON,$TotalWorkers
- While 1 ;basic loop, calls the generate status function every X seconds.
- GenerateStatus()
- Sleep($UpdateDelay*1000)
- WEnd
- ;meat and potatoes
- Func GenerateStatus() ; Downloads and parses JSON string using Regex since AutoIt has no JSON UDFs that i'm aware of.
- $Date = @YEAR & "/" & @MON & "/" & @MDAY & " @ " & @HOUR & ":" & @MIN & ":" & @SEC
- $JSON = GetJSON() ;workaround for grabbing JSON data from URL since I'm not aware of a UDF for this.
- $TotalReward = StringRegExpReplace($JSON,'{"confirmed_reward":([0-9]*\.[0-9]*).*',"$1") ; Read reward armount (pending)
- $TotalPayouts = StringRegExpReplace($JSON,'.*,"payout_history":(.*),"workers":.*',"$1") ; Read payout history
- $HashRate = StringRegExpReplace($JSON,'.*hashrate":(.*),"ipa":.*',"$1") ; Read Hash Rate
- $JSON = StringRegExpReplace($JSON,'{"confirmed.*workers":{(.*)}}',",$1") ; Now that we have that info, we re-assign JSON to only contain the Workers section.
- ParseWorkers() ; and then we parse that data into an array.
- FileDelete($Output) ; Delete the existing output file before writing to it.
- #EndRegion
- #region Generate Player Table
- ;Woohoo! We have a buttload of data now, so lets write it all into an HTML document!
- FileWriteLine($Output,'<html><head>')
- FileWriteLine($Output,' <link rel="stylesheet" href="miners.css" type="text/css" />') ; include miners.css for custom formatting and whatnot
- FileWriteLine($Output,' <script src="sorttable.js"></script>') ; Include sorttable.js to let you click the tables to sort them. :D
- FileWriteLine($Output,' <script src="https://code.jquery.com/jquery-latest.js"></script>') ; jquery
- FileWriteLine($Output,' <meta http-equiv="refresh" content="' & $AutoRefreshDelay & '">')
- FileWriteLine($Output,' <title>' & $ActiveWorkers & " Miners@" & $HashRate & 'Mhash/s</title>') ; Add small summary to tab name
- FileWriteLine($Output,'</head><body>')
- FileWriteLine($Output,' <div id="leftPanel">')
- FileWriteLine($Output,' <div class="minerScript">')
- FileWriteLine($Output,' <img src="miner.gif"/>Mining for Bitcoins!<br/>') ; cute little image. Feel free to replace it.
- FileWriteLine($Output,' </div>')
- FileWriteLine($Output,' <div id="miningStats">')
- FileWriteLine($Output,' <div id="miningStatsHeader"><b>' & $ActiveWorkers & ' of ' & $TotalWorkers[0] & ' workers @ ' & $HashRate & 'Mhash/sec<br />')
- FileWriteLine($Output,' <span id="pending">' & StringTrimRight($TotalReward,4) & ' pending</span> + <span id="paidout">' & _
- $TotalPayouts & 'paid</span> :: <span id="totalpaid">' & StringTrimRight(($TotalReward + $TotalPayouts),4) & '</span> total. </div>')
- ;Building the player Table
- FileWriteLine($Output,' <div id="miningStatsTable">')
- FileWriteLine($Output,' <table width="100%" class="sortable" align="left">')
- FileWriteLine($Output,' <thead>')
- FileWriteLine($Output,' <tr>')
- FileWriteLine($Output,' <th width="40%">Name</th>')
- FileWriteLine($Output,' <th width="30%">Shares</th>')
- FileWriteLine($Output,' <th width="15%">Stale</th>')
- FileWriteLine($Output,' <th width="15%">%</th>')
- FileWriteLine($Output,' </tr>')
- FileWriteLine($Output,' </thead>')
- FileWriteLine($Output,' <tbody>')
- For $i = 1 to $TotalWorkers[0] Step 1
- If $Shares[$i] <> 0 Then ; Only show miners with more than 1 share submitted.
- FileWriteLine($Output,' <tr>')
- If $Alive[$i] = "true" Then
- FileWriteLine($Output,' <td><span class="OnlineMiner">' & $Worker[$i] & '</span></td>')
- Else
- FileWriteLine($Output,' <td><span class="OfflineMiner">' & $Worker[$i] & '</span></td>')
- EndIf
- FileWriteLine($Output,' <td>'& $Shares[$i] &'</td>')
- FileWriteLine($Output,' <td>'& $Stale[$i] &'</td>')
- FileWriteLine($Output,' <td>'& Round((($Shares[$i]-$Stale[$i])/$Shares[$i])*100,2) &'%</td>')
- FileWriteLine($Output,' </tr>')
- EndIf
- Next
- FileWriteLine($Output,' </tbody>')
- FileWriteLine($Output,' </table><hr><center>Updated: ' & $Date & '</center></div>')
- FileWriteLine($Output,' </div>')
- FileWriteLine($Output,' </div>')
- ;End Player Table
- FileWriteLine($Output,'</body></html>')
- ;End of HTML
- #Region DEBUG
- ConsoleWrite( @CRLF & "-==========(JSON PARSE RESULTS)==========-" & @CRLF & _
- "Total Reward :: " & $TotalReward & @CRLF & _
- " Hash Rate :: " & $HashRate & @CRLF & _
- "---Workers-----------------------------------------" & @CRLF & _
- $JSON & @CRLF & @CRLF)
- #endregion DEBUG
- EndFunc
- Func ParseWorkers() ; More regex crap here. Basically creating a series of Arrays with worker information in them.
- $JSON = StringTrimLeft(StringRegExpReplace($JSON,',"' & $DBEmail & '_',"|",0),1)
- Global $TotalWorkers = StringSplit($JSON,"|")
- Global $Worker[$TotalWorkers[0]+1],$Alive[$TotalWorkers[0]+1],$Shares[$TotalWorkers[0]+1],$Stale[$TotalWorkers[0]+1]
- Global $ActiveWorkers = 0
- For $i = 1 To UBound($TotalWorkers) - 1 Step 1
- $Alive[$i] = StringRegExpReplace($TotalWorkers[$i],'.*{"alive":(.*),"shares.*}',"$1")
- $Worker[$i] = StringRegExpReplace($TotalWorkers[$i],'(.*)":{"alive".*',"$1")
- $Shares[$i] = StringRegExpReplace($TotalWorkers[$i],'.*,"shares":([0-9]*),"stales".*',"$1")
- $Stale[$i] = StringRegExpReplace($TotalWorkers[$i],'.*,"stales":([0-9]*)}',"$1")
- If $Alive[$i]="true" Then $ActiveWorkers = $ActiveWorkers + 1
- ConsoleWrite($TotalWorkers[$i] & " " & $Alive[$i] & " " & $Worker[$i] & " " & $Shares[$i] & " " & $Stale[$i] & @CRLF) ; debugging
- Next
- EndFunc
- Func GetJSON() ; silly way of grabbing the JSON string and assigning it to a variable.
- InetGet($JSONURL,@TempDir & "\json.txt",1)
- Local $Return = FileReadLine(@TempDir & "\json.txt",1)
- FileDelete(@TempDir & "\json.txt")
- Return $Return
- EndFunc
- Func Quit()
- Exit
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement