Bitcoin Forum
November 17, 2018, 02:20:12 PM *
News: Latest Bitcoin Core release: 0.17.0 [Torrent].
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: DIY Coinotron JSON API  (Read 1551 times)
idler
Newbie
*
Offline Offline

Activity: 11
Merit: 0


View Profile
April 21, 2013, 07:08:57 PM
 #1

I think coinotron is a good LTC Pool, but it doesn't provide JSON API to allow monitoring or logging, so I've made my own one, let's share it for you. Hope all would help.

The script is written in ruby and designed to run in cgi-bin of an web server.

The main purpose is to raise the awareness of the importance of the read only API. If the developer of coinotron released these extremely simple JSON API, this script would be useless. Thank you!

Code:
#!/usr/bin/env ruby

username = "xxxxxxxx"
password = "xxxxxxxxx"

puts "Content-type: text/text\n\n" unless ENV["HTTP_HOST"].nil?

require 'httpclient'
clnt = HTTPClient.new
clnt.set_cookie_store("cookie.dat")

r = clnt.get "https://coinotron.com/coinotron/AccountServlet?action=home"
while r.header.status_code == 302 do
  r = clnt.get r.header["Location"][0]
end
clnt.post "https://coinotron.com/coinotron/AccountServlet?action=logon", {"name" => username, "password" => password, "Logon" => "Logon"}

html = clnt.get_content "https://coinotron.com/coinotron/AccountServlet?action=myaccount"

require 'nokogiri'
doc = Nokogiri::HTML.parse html

h = Hash.new
h["worker"] = Hash.new

ltc_cr = ltc_ucf = ltc_c = 0

doc.css("input").each do |i|
  ltc_cr  = i["value"].to_f if i["name"] == "CurrentRoundRewardsLTC"
  ltc_ucf = i["value"].to_f if i["name"] == "UnconfirmedRewardsLTC"
  ltc_c   = i["value"].to_f if i["name"] == "ConfirmedRewardsLTC"
end

ltc_ct = ltc_cr + ltc_ucf + ltc_c

h["CurrentRoundRewardsLTC"] = ltc_cr
h["UnconfirmedRewardsLTC"] = ltc_ucf
h["ConfirmedRewardsLTC"] = ltc_c
h["TotalRewordsLTC"] = ltc_ct

doc.css("form").each do |f|

  if f["action"] == "/coinotron/AccountServlet?action=changeworkercoin"
    worker_name = f.xpath("input[@name=\"workername\"]").first["value"]
    h["worker"][worker_name] = Hash.new if h[worker_name].nil?
    coin = ""
    f.css("option").each do |o|
      unless o["selected"].nil?
        coin = o.text ; break
      end
    end
    h["worker"][worker_name]["coin"] = coin
  end

  if f["action"] == "/coinotron/AccountServlet?action=changeworkerrewardtype"
    worker_name = f.xpath("input[@name=\"workername\"]").first["value"]
    h["worker"][worker_name] = Hash.new if h[worker_name].nil?
    workerrewardtype = ""
    f.css("option").each do |o|
      unless o["selected"].nil?
        workerrewardtype = o.text ; break
      end
    end
    h["worker"][worker_name]["workerrewardtype"] = workerrewardtype
  end

end


doc.css("tr").each do |row|
  ct = 0
  worker_name = khash = ""
  row.children.each do |c|
    worker_name = c.text.strip if c.name == "td"  and  ct == 2
    khash = c.text.strip if c.name == "td" and ct == 6
    ct +=1
  end
  next if h["worker"][worker_name].nil?
  h["worker"][worker_name]["khash"] = khash
end

#puts h

require 'json'
puts h.to_json




Then output looks like

Code:
{"CurrentRoundRewardsLTC"=>0.0, "UnconfirmedRewardsLTC"=>0.0, "ConfirmedRewardsLTC"=>2.91905758, "TotalRewordsLTC"=>2.91905758, "idler921.gpu"=>{"coin"=>"LTC", "workerrewardtype"=>"Round based pay per share", "khash"=>"152.2 KH/s"}, "idler921.cpu"=>{"coin"=>"LTC", "workerrewardtype"=>"Pay per share", "khash"=>"45.0 KH/s"}}
1542464412
Hero Member
*
Offline Offline

Posts: 1542464412

View Profile Personal Message (Offline)

Ignore
1542464412
Reply with quote  #2

1542464412
Report to moderator
1542464412
Hero Member
*
Offline Offline

Posts: 1542464412

View Profile Personal Message (Offline)

Ignore
1542464412
Reply with quote  #2

1542464412
Report to moderator
1542464412
Hero Member
*
Offline Offline

Posts: 1542464412

View Profile Personal Message (Offline)

Ignore
1542464412
Reply with quote  #2

1542464412
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
FatMagic
Full Member
***
Offline Offline

Activity: 224
Merit: 100



View Profile
May 07, 2013, 04:56:43 PM
 #2

Thanks Idler! Going to try this out... was hoping for an API from Coinotron, but no dice. I'll report back my results with this...

FastCoin
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
May 07, 2013, 05:00:14 PM
 #3

great man ..
Thanks
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!