cryptocoin_fanboi 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +3 -3
- data/lib/cryptocoin_fanboi.rb +80 -15
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 561d34afff8a3d49fe5687ffb831ae060c42d677
|
4
|
+
data.tar.gz: e25930d3382809ef3c945942b862758f54340438
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dc393507855992feee85f77da2fb96ac3f1a35aca21d7a1f925d6e616a795b69b95db5c7b16ce7f0807cc0f3552752c1696d8cd083693025a53be0beccaa281
|
7
|
+
data.tar.gz: d1050779993531dc93e946dc9718c9481d3a35c9b644cf6bd582c721008afdbd314ec4689c1d891a1ffec06956d5cb775f7a3ea88922317afb5792702a52a418
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
�
|
1
|
+
3�O�1F�d?����T4O�j�^�mX��.�R��:i�4�#N�Qob���c>4sXU�X���m�LԺf���w
|
2
|
+
p����*
|
3
|
+
�7a��
|
data/lib/cryptocoin_fanboi.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
# file: cryptocoin_fanboi.rb
|
4
4
|
|
5
5
|
|
6
|
+
require 'psych'
|
6
7
|
require 'colored'
|
7
8
|
require 'coinmarketcap'
|
8
9
|
require 'table-formatter'
|
@@ -10,20 +11,44 @@ require 'table-formatter'
|
|
10
11
|
|
11
12
|
class CryptocoinFanboi
|
12
13
|
|
13
|
-
attr_reader :coins
|
14
|
+
attr_reader :coins, :all_coins
|
14
15
|
attr_accessor :colored
|
15
16
|
|
16
|
-
def initialize(watch: [], colored: true)
|
17
|
+
def initialize(watch: [], ignore: [], colored: true, debug: false)
|
17
18
|
|
18
|
-
@colored = colored
|
19
|
-
@watch
|
19
|
+
@colored, @debug = colored, debug
|
20
|
+
@watch= watch.map(&:upcase)
|
21
|
+
@ignore = ignore.map(&:upcase)
|
20
22
|
|
21
23
|
@fields = %w(rank name price_usd price_btc percent_change_1h
|
22
24
|
percent_change_24h percent_change_7d)
|
23
|
-
|
24
|
-
@labels = %w(Rank Name USD BTC) + ['% 1hr:', '% 24hr:', '% 1 week:']
|
25
|
-
@coins = fetch_coinlist(watch: @watch)
|
26
25
|
|
26
|
+
@year = Time.now.year.to_s
|
27
|
+
@labels = %w(Rank Name USD BTC) + ['% 1hr:', '% 24hr:',
|
28
|
+
'% 1 week:', '% ' + @year + ':']
|
29
|
+
@coins = fetch_coinlist()
|
30
|
+
|
31
|
+
|
32
|
+
# check for the local cache file containing a record of currency
|
33
|
+
# prices from the start of the year
|
34
|
+
|
35
|
+
cache_filename = 'cryptocoin_fanboi.yaml'
|
36
|
+
|
37
|
+
if File.exists? cache_filename then
|
38
|
+
|
39
|
+
#load the file
|
40
|
+
h = Psych.load File.read(cache_filename)
|
41
|
+
|
42
|
+
@growth = (h.keys.first == @year.to_i) ? h[@year.to_i] : fetch_growth(@all_coins)
|
43
|
+
|
44
|
+
else
|
45
|
+
|
46
|
+
# fetch the currency prices from the start of the year
|
47
|
+
@growth = fetch_growth(@all_coins)
|
48
|
+
File.write cache_filename, {@year => @growth}.to_yaml
|
49
|
+
|
50
|
+
end
|
51
|
+
|
27
52
|
end
|
28
53
|
|
29
54
|
def coin_abbreviations()
|
@@ -59,9 +84,9 @@ class CryptocoinFanboi
|
|
59
84
|
|
60
85
|
end
|
61
86
|
|
62
|
-
def to_s(limit: nil, markdown: false
|
87
|
+
def to_s(limit: nil, markdown: false)
|
63
88
|
|
64
|
-
coins = fetch_coinlist(limit: limit
|
89
|
+
coins = fetch_coinlist(limit: limit).map do |coin|
|
65
90
|
|
66
91
|
@fields.map {|x| coin[x] }
|
67
92
|
|
@@ -73,8 +98,13 @@ class CryptocoinFanboi
|
|
73
98
|
|
74
99
|
private
|
75
100
|
|
76
|
-
def build_table(
|
77
|
-
|
101
|
+
def build_table(a, markdown: markdown)
|
102
|
+
|
103
|
+
coins = a.map do |x|
|
104
|
+
@growth.has_key?(x[1]) ? x + [@growth[x[1]].to_s] : x
|
105
|
+
end
|
106
|
+
|
107
|
+
puts 'coins: ' + coins.inspect if @debug
|
78
108
|
s = TableFormatter.new(source: coins, labels: @labels, markdown: markdown)\
|
79
109
|
.display
|
80
110
|
|
@@ -94,11 +124,46 @@ class CryptocoinFanboi
|
|
94
124
|
|
95
125
|
end
|
96
126
|
|
97
|
-
def fetch_coinlist(limit: nil
|
127
|
+
def fetch_coinlist(limit: nil)
|
128
|
+
|
129
|
+
@all_coins = JSON.parse(Coinmarketcap.coins.body)
|
130
|
+
|
131
|
+
a = if @watch.any? then
|
132
|
+
@all_coins.select {|x| @watch.include? x['symbol']}
|
133
|
+
elsif @ignore.any?
|
134
|
+
@all_coins.reject {|x| @ignore.include? x['symbol']}
|
135
|
+
else
|
136
|
+
@all_coins
|
137
|
+
end
|
138
|
+
|
139
|
+
limit ? a.take(limit) : a
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
# fetch the currency prices from the start of the year
|
144
|
+
#
|
145
|
+
def fetch_growth(coins)
|
98
146
|
|
99
|
-
|
100
|
-
|
101
|
-
|
147
|
+
puts 'fetching growth ...' if @debug
|
148
|
+
|
149
|
+
coins.inject({}) do |r, x|
|
150
|
+
|
151
|
+
day1 = @year + '0101'
|
152
|
+
puts 'x: ' + x['name'].inspect if @debug
|
153
|
+
begin
|
154
|
+
a = Coinmarketcap.get_historical_price(x['name'].gsub(/ /,'-'), day1, day1)
|
155
|
+
rescue
|
156
|
+
puts 'warning : ' + x['name'].inspect + ' ' + ($!).inspect
|
157
|
+
end
|
158
|
+
|
159
|
+
if a and a.any? then
|
160
|
+
latest_day, year_start = x['price_usd'].to_f, a[0][:close]
|
161
|
+
r.merge({x['name'] => (latest_day / year_start).round(2)})
|
162
|
+
else
|
163
|
+
r
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
102
167
|
|
103
168
|
end
|
104
169
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cryptocoin_fanboi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
NgmsFfw10oaD3PWQ7UPxWJP14au2LUL+NGHkLrGHOMPphsZhYeXKugGO8NfcKukq
|
31
31
|
fps=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2018-01-
|
33
|
+
date: 2018-01-03 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: colored
|
metadata.gz.sig
CHANGED
Binary file
|