cryptocoin_fanboi 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -3
- data/lib/cryptocoin_fanboi.rb +254 -186
- 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: fda022b85bf61606e5a6cc3f2cf705b8e44b5c37
|
4
|
+
data.tar.gz: 55faedfb06f1e44100e22b8f762f7a728b1eaca3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee471b908f0860b4cb46233cfc5298116bc867ebffc2aaf399afa9354571d43c275970b893768b6446843b66aad61ccef63db54048a705afca1dac8d2cc8c39d
|
7
|
+
data.tar.gz: 2fd4ae33dc66cecca94b52ac91b14d6276f3e121f03734b852a1447416e375a0a260707aba7c17b26ea19e1333d3cae9e350dd1165f9515050608c761ad8deae
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1,3 +1 @@
|
|
1
|
-
|
2
|
-
f���(�H!A�9��
|
3
|
-
0�����ے���اF��Ķ<�r�f��p"^��cs&�=��J�%Vl�>�X�h������ƫ���F�o�O��|N���`1�$�ـ��`~�����*9�ZqGo��9����tB���_K�
|
1
|
+
Y��:н�lX/�Gݕќ`J^���{�+E�֔�OMh\�tQY�'bГ��D�戂�E�s3���5%��-Ow~d�;+n�E�kO���d�wmtJ,����$'�鲤B)��&��i���ޥ�pKZ�:B�A����"}*��G�Ҷˣ��Bu.�,��Cu�읷h�)�c@�ҜϷX|�s��I0�X)��Ԧ�V�3�D�(�!�Z��`��\�_%����үP�!rY`>�WUxKS[#
|
data/lib/cryptocoin_fanboi.rb
CHANGED
@@ -1,187 +1,255 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# file: cryptocoin_fanboi.rb
|
4
|
-
|
5
|
-
|
6
|
-
require 'psych'
|
7
|
-
require 'colored'
|
8
|
-
require 'coinmarketcap'
|
9
|
-
require 'table-formatter'
|
10
|
-
|
11
|
-
|
12
|
-
class CryptocoinFanboi
|
13
|
-
|
14
|
-
attr_reader :coins, :all_coins
|
15
|
-
attr_accessor :colored
|
16
|
-
|
17
|
-
def initialize(watch: [], ignore: [], colored: true, debug: false)
|
18
|
-
|
19
|
-
@colored, @debug = colored, debug
|
20
|
-
@watch= watch.map(&:upcase)
|
21
|
-
@ignore = ignore.map(&:upcase)
|
22
|
-
|
23
|
-
@fields = %w(rank name price_usd price_btc percent_change_1h
|
24
|
-
percent_change_24h percent_change_7d)
|
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
|
-
puts 'h.key.first: ' + h.keys.first.inspect if @debug
|
42
|
-
puts '@year: ' + @year.inspect if @debug
|
43
|
-
@growth = (h.keys.first == @year) ? h[@year] : fetch_growth(@all_coins)
|
44
|
-
puts '@growth: ' + @growth.inspect if @debug
|
45
|
-
else
|
46
|
-
|
47
|
-
# fetch the currency prices from the start of the year
|
48
|
-
@growth = fetch_growth(@all_coins)
|
49
|
-
File.write cache_filename, {@year => @growth}.to_yaml
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
def coin_abbreviations()
|
56
|
-
@coins.map {|x| "%s (%s)" % [x['name'], x['symbol']] }
|
57
|
-
end
|
58
|
-
|
59
|
-
alias abbreviations coin_abbreviations
|
60
|
-
|
61
|
-
|
62
|
-
# View the coins with the largest gains in the past hour
|
63
|
-
#
|
64
|
-
def now(limit: 5, markdown: false)
|
65
|
-
|
66
|
-
build_table top_coins('1h', limit: limit), markdown: markdown
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
# View the coins with the largest gains this week (past 7 days)
|
71
|
-
#
|
72
|
-
def this_week(limit: 5, markdown: false)
|
73
|
-
|
74
|
-
build_table top_coins(limit: limit), markdown: markdown
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
alias week this_week
|
79
|
-
|
80
|
-
# View the coins with the largest gains today (past 24 hours)
|
81
|
-
#
|
82
|
-
def today(limit: 5, markdown: false)
|
83
|
-
|
84
|
-
build_table top_coins('24h', limit: limit), markdown: markdown
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
def to_s(limit: nil, markdown: false)
|
89
|
-
|
90
|
-
coins = fetch_coinlist(limit: limit).map do |coin|
|
91
|
-
|
92
|
-
@fields.map {|x| coin[x] }
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
build_table coins, markdown: markdown
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
private
|
101
|
-
|
102
|
-
def build_table(a, markdown: markdown)
|
103
|
-
|
104
|
-
coins = a.map do |x|
|
105
|
-
@growth.has_key?(x[1]) ? x + [@growth[x[1]].to_s] : x
|
106
|
-
end
|
107
|
-
|
108
|
-
puts 'coins: ' + coins.inspect if @debug
|
109
|
-
s = TableFormatter.new(source: coins, labels: @labels, markdown: markdown)\
|
110
|
-
.display
|
111
|
-
|
112
|
-
return s if @colored == false
|
113
|
-
|
114
|
-
a = s.lines
|
115
|
-
|
116
|
-
body = a[3..-2].map do |line|
|
117
|
-
|
118
|
-
fields = line.split('|')
|
119
1
|
|
120
|
-
a2 = fields[5..-2].map {|x|
|
121
2
|
x[/^ +-/] ? x.red : x.green
|
122
3
|
}
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
limit
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
4
|
+
#!/usr/bin/env ruby
|
5
|
+
|
6
|
+
# file: cryptocoin_fanboi.rb
|
7
|
+
|
8
|
+
|
9
|
+
require 'psych'
|
10
|
+
require 'colored'
|
11
|
+
require 'coinmarketcap'
|
12
|
+
require 'table-formatter'
|
13
|
+
require 'rxfhelper'
|
14
|
+
|
15
|
+
|
16
|
+
=begin
|
17
|
+
|
18
|
+
# Examples
|
19
|
+
|
20
|
+
## Basic usage
|
21
|
+
|
22
|
+
c = CryptocoinFanboi.new
|
23
|
+
|
24
|
+
puts.to_s limit: 5 # Display the top 5 coins
|
25
|
+
puts c.this_week # Display the top 5 coins this week
|
26
|
+
puts c.last_day # Display the top 5 coins in the last 24 hours
|
27
|
+
puts c.last_hour # Display the top 5 coins in the last hour
|
28
|
+
|
29
|
+
|
30
|
+
## Advance usage
|
31
|
+
|
32
|
+
### Display a selection of coins in order of rank
|
33
|
+
|
34
|
+
c = CryptocoinFanboi.new watch: %w(btc xrp eth trx dash xmr neo xem)
|
35
|
+
puts.to_s
|
36
|
+
|
37
|
+
### Ignore possibly risky coins (e.g. Asian stock market coins etc.)
|
38
|
+
|
39
|
+
c = CryptocoinFanboi.new ignore: %w(xp bts kcs gxs rhoc)
|
40
|
+
puts c.this_week
|
41
|
+
|
42
|
+
=end
|
43
|
+
|
44
|
+
class CryptocoinFanboi
|
45
|
+
|
46
|
+
attr_reader :coins, :all_coins
|
47
|
+
attr_accessor :colored
|
48
|
+
|
49
|
+
def initialize(watch: [], ignore: [],
|
50
|
+
colored: true, debug: false)
|
51
|
+
|
52
|
+
@colored, @debug = colored, debug
|
53
|
+
|
54
|
+
@watch= watch.map(&:upcase)
|
55
|
+
@ignore = ignore.map(&:upcase)
|
56
|
+
|
57
|
+
@fields = %w(rank name price_usd price_btc percent_change_1h
|
58
|
+
percent_change_24h percent_change_7d)
|
59
|
+
|
60
|
+
@year = Time.now.year.to_s
|
61
|
+
@labels = %w(Rank Name USD BTC) + ['% 1hr:', '% 24hr:',
|
62
|
+
'% 1 week:', '% ' + @year + ':']
|
63
|
+
@coins = fetch_coinlist()
|
64
|
+
|
65
|
+
# check for the local cache file containing a record of currency
|
66
|
+
# prices from the start of the year
|
67
|
+
|
68
|
+
cache_filename = 'cryptocoin_fanboi.yaml'
|
69
|
+
|
70
|
+
if File.exists? cache_filename then
|
71
|
+
|
72
|
+
#load the file
|
73
|
+
h = Psych.load File.read(cache_filename)
|
74
|
+
puts 'h.key.first: ' + h.keys.first.inspect if @debug
|
75
|
+
puts '@year: ' + @year.inspect if @debug
|
76
|
+
@growth = (h.keys.first == @year) ? h[@year] : fetch_growth(@all_coins)
|
77
|
+
puts '@growth: ' + @growth.inspect if @debug
|
78
|
+
|
79
|
+
else
|
80
|
+
|
81
|
+
# fetch the currency prices from the start of the year
|
82
|
+
@growth = fetch_growth(@all_coins)
|
83
|
+
File.write cache_filename, {@year => @growth}.to_yaml
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
def coin_abbreviations()
|
90
|
+
@coins.map {|x| "%s (%s)" % [x['name'], x['symbol']] }
|
91
|
+
end
|
92
|
+
|
93
|
+
def coins()
|
94
|
+
@coins.map {|x| OpenStruct.new(x) }
|
95
|
+
end
|
96
|
+
|
97
|
+
alias abbreviations coin_abbreviations
|
98
|
+
|
99
|
+
def inspect()
|
100
|
+
|
101
|
+
c = @coins.inspect.length > 50 ? @coins.inspect[0..50] + '...' : @coins.inspect
|
102
|
+
"#<%s:%s @coins=\"%s\ @all_coins=\"...\">" % [self.class,
|
103
|
+
self.object_id, c]
|
104
|
+
end
|
105
|
+
|
106
|
+
def find(name)
|
107
|
+
|
108
|
+
coins.find {|coin| coin.name =~ /#{name}/i }
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
# View the coins with the largest gains in the past hour
|
113
|
+
#
|
114
|
+
def now(limit: 5, markdown: false)
|
115
|
+
|
116
|
+
build_table2 top_coins('1h', limit: limit), markdown: markdown
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
alias hour now
|
121
|
+
alias last_hour now
|
122
|
+
|
123
|
+
# View the coins with the largest gains this week (past 7 days)
|
124
|
+
#
|
125
|
+
def this_week(limit: 5, markdown: false)
|
126
|
+
|
127
|
+
coins = top_coins(limit: limit)
|
128
|
+
build_table2 coins, markdown: markdown
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
alias week this_week
|
133
|
+
|
134
|
+
# View the coins with the largest gains today (past 24 hours)
|
135
|
+
#
|
136
|
+
def today(limit: 5, markdown: false)
|
137
|
+
|
138
|
+
build_table2 top_coins('24h', limit: limit), markdown: markdown
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
alias last_day today
|
143
|
+
alias day today
|
144
|
+
|
145
|
+
def to_s(limit: nil, markdown: false)
|
146
|
+
|
147
|
+
coins = fetch_coinlist(limit: limit).map do |coin|
|
148
|
+
|
149
|
+
@fields.map {|x| coin[x] }
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
build_table coins, markdown: markdown
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
private
|
158
|
+
|
159
|
+
def build_table(a, markdown: markdown, labels: @labels)
|
160
|
+
|
161
|
+
coins = a.map do |x|
|
162
|
+
@growth.has_key?(x[1]) ? x + [@growth[x[1]].to_s] : x
|
163
|
+
end
|
164
|
+
|
165
|
+
format_table(coins, markdown: markdown, labels: @labels)
|
166
|
+
end
|
167
|
+
|
168
|
+
def build_table2(a, markdown: markdown, labels: @labels)
|
169
|
+
|
170
|
+
format_table(a, markdown: markdown, labels: @labels[0..-2])
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
def format_table(source, markdown: markdown, labels: @labels)
|
175
|
+
s = TableFormatter.new(source: source, labels: labels, markdown: markdown)\
|
176
|
+
.display
|
177
|
+
|
178
|
+
return s if @colored == false
|
179
|
+
|
180
|
+
a = s.lines
|
181
|
+
|
182
|
+
body = a[3..-2].map do |line|
|
183
|
+
|
184
|
+
fields = line.split('|')
|
185
|
+
|
186
|
+
a2 = fields[5..-2].map {|x| x[/^ +-/] ? x.red : x.green }
|
187
|
+
(fields[0..4] + a2 + ["\n"]).join('|')
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
(a[0..2] + body + [a[-1]]).join
|
192
|
+
end
|
193
|
+
|
194
|
+
def fetch_coinlist(limit: nil)
|
195
|
+
|
196
|
+
@all_coins = JSON.parse(Coinmarketcap.coins.body)\
|
197
|
+
.map {|x| OpenStruct.new x}
|
198
|
+
|
199
|
+
a = if @watch.any? then
|
200
|
+
@all_coins.select {|x| @watch.include? x.symbol }
|
201
|
+
elsif @ignore.any?
|
202
|
+
@all_coins.reject {|x| @ignore.include? x.symbol }
|
203
|
+
else
|
204
|
+
@all_coins
|
205
|
+
end
|
206
|
+
|
207
|
+
limit ? a.take(limit) : a
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
# fetch the currency prices from the start of the year
|
212
|
+
#
|
213
|
+
def fetch_growth(coins)
|
214
|
+
|
215
|
+
puts 'fetching growth ...' if @debug
|
216
|
+
|
217
|
+
coins.inject({}) do |r, coin|
|
218
|
+
|
219
|
+
day1 = @year + '0101'
|
220
|
+
puts 'coin: ' + coin.name.inspect if @debug
|
221
|
+
|
222
|
+
begin
|
223
|
+
|
224
|
+
a = Coinmarketcap.get_historical_price(coin.name.gsub(/ /,'-'),
|
159
225
|
day1, day1)
|
160
|
-
rescue
|
161
|
-
puts 'warning : ' +
|
162
|
-
end
|
163
|
-
|
164
|
-
if a and a.any? then
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
end
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
226
|
+
rescue
|
227
|
+
puts 'warning : ' + coin.name.inspect + ' ' + ($!).inspect
|
228
|
+
end
|
229
|
+
|
230
|
+
if a and a.any? then
|
231
|
+
|
232
|
+
latest_day, year_start = coin.price_usd.to_f, a[0][:close]
|
233
|
+
r.merge({coin.name => (100.0 / (year_start /
|
234
|
+
(latest_day - year_start))).round(2)})
|
235
|
+
else
|
236
|
+
r
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|
242
|
+
|
243
|
+
def top_coins(period='7d', limit: 5)
|
244
|
+
|
245
|
+
a = @coins.sort_by {|x| -x['percent_change_' + period].to_f}.take(limit)
|
246
|
+
a.map {|coin| @fields.map {|key| coin[key] }}
|
247
|
+
|
248
|
+
end
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
|
253
|
+
if __FILE__ == $0 then
|
254
|
+
|
255
|
+
ccf = CryptocoinFanboi.new
|
256
|
+
puts ccf.to_s
|
257
|
+
|
258
|
+
end
|
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.4
|
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-05 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: colored
|
metadata.gz.sig
CHANGED
Binary file
|