/
btc-wallet-price
executable file
·58 lines (46 loc) · 1 KB
/
btc-wallet-price
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
#!/usr/bin/ruby
# TODO: -w
# Usage: btc-wallet-price [--xosd]
ENV['BUNDLE_GEMFILE'] = File.dirname(__FILE__) + "/Gemfile"
require 'rubygems'
require 'bundler/setup'
require_relative 'bitcoin-price'
module BtcKit
class BtcWalletPrice
def initialize
@config = Config.new
end
def wallet_value
BtcPrice.new.current_wallet_value
end
def main
raw = false
xosd = false
until ARGV.empty?
case ARGV.shift
when "--xosd" then xosd = true
when "--raw" then raw = true
else puts "Usage: btc-wallet-price [--xosd] [--raw]"; exit 1
end
end
initialCZK = @config.initial_czk
currentCZK = wallet_value
delta = currentCZK - initialCZK
deltaPercent = (delta / initialCZK) * 100.0
result =
if raw
"%.2f" % currentCZK
else
"%.2f Kč (%+.2f Kč, %+.2f%%)" % [currentCZK, delta, deltaPercent]
end
if xosd
system "xosdutilctl", "echo", result
else
puts result
end
end
end
end
if __FILE__ == $0
BtcKit::BtcWalletPrice.new.main
end