-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.rb
executable file
·83 lines (60 loc) · 2.05 KB
/
core.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
require 'net/http'
require 'uri'
require 'openssl'
require 'json'
class GetInfoCore
PRICE_BTC_JSON_URL = 'https://bitex.club/api/v2/trades?market=sibbtc'
PRICE_USD_JSON_URL = 'https://btc-e.com/api/2/btc_usd/trades'
PRICE_RUR_JSON_URL = 'https://btc-e.com/api/2/btc_rur/trades'
HASHRATE_JSON_URL = 'https://digger.pw/api/stats'
def initialize
end
def connect(method)
if method == 'btc'
uri = URI.parse(PRICE_BTC_JSON_URL)
elsif method == 'usd'
uri = URI.parse(PRICE_USD_JSON_URL)
elsif method == 'rur'
uri = URI.parse(PRICE_RUR_JSON_URL)
elsif method == 'hashrate'
uri = URI.parse(HASHRATE_JSON_URL)
end
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
parsed = JSON.parse(response.body)
if method == 'btc'
result = parsed[0]['price']
result = '%.8f' % result
puts('Write price BTC to file is OK!') if File.write('price_btc.txt', result)
@btc = result
elsif method == 'usd'
firstelement = parsed.first(1)
result = firstelement[0]['price'].to_f * @btc.to_f
result = '%.8f' % result
puts('Write price USD to file is OK!') if File.write('price_usd.txt', result)
@usd = result
elsif method == 'rur'
firstelement = parsed.first(1)
result = firstelement[0]['price'].to_f * @btc.to_f
result = '%.8f' % result
puts('Write price RUR to file is OK!') if File.write('price_rur.txt', result)
@rur = result
elsif method == 'hashrate'
temparrayfirst = Array[]
temparraysecond = Array[]
parsed['algos']['x11'].each do |element|
temparrayfirst.push(element)
end
temparrayfirst.each do |element|
temparraysecond.push(element[1])
end
result = temparraysecond[1]
result = '%.8f' % result
puts('Write Hashrate to file is OK!') if File.write('hashrate.txt', result.to_i)
@hashrate = result
end
end
end