Bitcoin Forum

Bitcoin => Project Development => Topic started by: Professoruss on February 18, 2014, 01:23:55 AM



Title: [ANN] blockfound - push notifications when your pool solves a block
Post by: Professoruss on February 18, 2014, 01:23:55 AM
I just updated this so it works on all pools via blockchain, so I figured, might as well post it in here.
Hope someone can get some use out of it.
https://github.com/professoruss/blockfound (https://github.com/professoruss/blockfound)
https://i.imgur.com/i5C9fQc.png
readme:

Blockfound will notify you when your pool finds a new block

Ruby
Support for Pushover - ios/android push notifications
Run via cron or irc bot
Data comes from blockchain.info API (or optionally slush API)
Version

2.0

Installation

gem install json
gem install yaml
git clone https://github.com/professoruss/blockfound.git
Command line options

--pool <Slush, BTC%Guild, Eligius> (Specify pool name from blockchain.info - use same case as https://blockchain.info/pools?timespan=24hrs, replace spaces with %20)
--oldschool (Get data from slush API instead of blockchain.info)
--output <cli, pushover> (specify the output, defaults to cli)
--help (uhh, help)
Run the damn thing!

output to console

ruby blockfound.rb --pool Slush
Push Notifications Via pushover

enter your token and user into the yaml file

cd blockfound
vim pushover.yaml
push notifications

ruby blockfound.rb --pool Slush --output pushover
Run via cron

* * * * * sleep 1 ;ruby blockfound/blockfound.rb --pool Slush --output pushover > /dev/null 2>&1


Title: Re: [ANN] blockfound - push notifications when your pool solves a block
Post by: Professoruss on February 18, 2014, 02:55:15 AM
also, open for suggestions for other types of notifications


Title: Re: [ANN] blockfound - push notifications when your pool solves a block
Post by: Professoruss on February 18, 2014, 03:22:03 AM
Whoops, found a bug, i think i misinterpreted the api for blockchain.info


Title: Re: [ANN] blockfound - push notifications when your pool solves a block
Post by: Professoruss on February 18, 2014, 03:37:53 AM
bug fixed


Title: Re: [ANN] blockfound - push notifications when your pool solves a block
Post by: dplusf on February 19, 2014, 06:21:40 PM
I like your script and installed it and will test it.
But i think ill have to wait a bit since i am mining on P2Pool... :-)


Title: Re: [ANN] blockfound - push notifications when your pool solves a block
Post by: Professoruss on February 19, 2014, 10:09:39 PM
Well, I think I found another bug, it sometimes doesn't detect the new block when pulling from blockchain.  I'll need to look into it.


Title: Re: [ANN] blockfound - push notifications when your pool solves a block
Post by: dplusf on February 20, 2014, 06:26:36 PM
Well, I think I found another bug, it sometimes doesn't detect the new block when pulling from blockchain.  I'll need to look into it.

i think i run into this bug. for testing i was using GHash.io, regardless i do not like centralised pools. script only found four blocks, one block was messaged to me three times.
maybe you want me to test something to get closer to the error?

another thing i would like to mention is if i switch to p2pool i ll get a error message:

blockfound.rb:86:in `<main>': undefined method `[]' for nil:NilClass (NoMethodError)

my command line looks like
Code:
ruby blockfound.rb --pool P2Pool


Title: Re: [ANN] blockfound - push notifications when your pool solves a block
Post by: Professoruss on February 20, 2014, 07:42:19 PM
I'll try to address these issues by the end of the week.  Work has me running around in quite a few directions this week, so I won't be able to dig into it until the weekend.


Title: Re: [ANN] blockfound - push notifications when your pool solves a block
Post by: dplusf on February 20, 2014, 08:27:24 PM
No hurry.
Didnt know about the Pushover App until this thread, so thank you about that too! :-)


Title: Re: [ANN] blockfound - push notifications when your pool solves a block
Post by: Professoruss on February 20, 2014, 08:41:01 PM
No prob!


Title: Re: [ANN] blockfound - push notifications when your pool solves a block
Post by: edonkey on March 18, 2015, 03:16:45 PM
Thanks for pulling this script together.

I'm trying to call it from Mac OS X Yosemite 10.10.2 and am getting the following error:

Code:
ruby blockfound.rb --pool Slush 
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:223:in `open_loop': redirection forbidden: http://blockchain.info/blocks/Slush?format=json -> https://blockchain.info/blocks/Slush?format=json (RuntimeError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:149:in `open_uri'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:689:in `open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open-uri.rb:34:in `open'
from blockfound.rb:83:in `<main>'

If I try to directly access the same URL (https://blockchain.info/blocks/Slush?format=json) from a browser, it works.

So I googled the problem and found this page:

http://stackoverflow.com/questions/10013293/open-uri-is-not-redirecing-http-to-https

I installed the open_uri_redirections gem, then made the minor mods to your script to allow redirections, and it works.

Here's the text of the patch, if you're interested:

Code:
*** ../blockfound/blockfound.rb	2015-03-18 07:40:34.000000000 -0700
--- blockfound.rb 2015-03-18 07:59:25.000000000 -0700
***************
*** 1,6 ****
--- 1,7 ----
  require 'rubygems'
  require 'json'
  require 'open-uri'
+ require 'open_uri_redirections'
  require 'yaml'
  require 'net/https'
  require 'optparse'
***************
*** 54,60 ****
    oldschool = res["oldschool"]
    if oldschool == true
      #slush specific
!     result = JSON.load(open("http://mining.bitcoin.cz/stats/json/"))
 
      #pool speed
      gh = result["ghashes_ps"]
--- 55,61 ----
    oldschool = res["oldschool"]
    if oldschool == true
      #slush specific
!     result = JSON.load(open("http://mining.bitcoin.cz/stats/json/", :allow_redirections => :safe))
 
      #pool speed
      gh = result["ghashes_ps"]
***************
*** 80,86 ****
      #clean up %20 if present
      pool_name = res["pool"]
      pool_name.gsub!('%20', ' ')
!     bc_pjson = JSON.load(open(bcurl))
      bc_latest_height = bc_pjson["blocks"][0]["height"]
      bc_latest_time = Time.at(bc_pjson["blocks"][0]["time"]).utc
      bc_second_time = Time.at(bc_pjson["blocks"][1]["time"]).utc
--- 81,87 ----
      #clean up %20 if present
      pool_name = res["pool"]
      pool_name.gsub!('%20', ' ')
!     bc_pjson = JSON.load(open(bcurl, :allow_redirections => :safe))
      bc_latest_height = bc_pjson["blocks"][0]["height"]
      bc_latest_time = Time.at(bc_pjson["blocks"][0]["time"]).utc
      bc_second_time = Time.at(bc_pjson["blocks"][1]["time"]).utc

Maybe an alternative simpler patch (which I didn't try) would be to change the URLs to https to avoid redirection.