Author

Topic: [ANN] blockfound - push notifications when your pool solves a block (Read 1702 times)

legendary
Activity: 1150
Merit: 1004
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 `
'

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.
member
Activity: 64
Merit: 10
sr. member
Activity: 258
Merit: 250
No hurry.
Didnt know about the Pushover App until this thread, so thank you about that too! :-)
member
Activity: 64
Merit: 10
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.
sr. member
Activity: 258
Merit: 250
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 `
': undefined method `[]' for nil:NilClass (NoMethodError)

my command line looks like
Code:
ruby blockfound.rb --pool P2Pool
member
Activity: 64
Merit: 10
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.
sr. member
Activity: 258
Merit: 250
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... :-)
member
Activity: 64
Merit: 10
member
Activity: 64
Merit: 10
Whoops, found a bug, i think i misinterpreted the api for blockchain.info
member
Activity: 64
Merit: 10
also, open for suggestions for other types of notifications
member
Activity: 64
Merit: 10
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

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 (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 (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
Jump to: