capwatch 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -1
- data/capwatch.gemspec +1 -0
- data/exe/capwatch +9 -7
- data/funds/demo/basic.json +1 -1
- data/funds/demo/dynamic.json +1 -1
- data/lib/capwatch.rb +3 -0
- data/lib/capwatch/cli.rb +3 -0
- data/lib/capwatch/console.rb +16 -6
- data/lib/capwatch/fundparser.rb +10 -0
- data/lib/capwatch/telegram.rb +50 -0
- data/lib/capwatch/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37394be004f4cec6e948ddb4b59cf484ec764773
|
4
|
+
data.tar.gz: 305494f7086c7cbc00253428075f5cdf1830170d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a05c7e5f0a8204a3dea47f39d3f937726b0eb11054d40005d202723d4d264057b9db9b1fae63b476516dfff944187d674505e8009a4cc4036b8a18a24e9212ff
|
7
|
+
data.tar.gz: 33429b9c8095c53cb77d00b14eb3bd747d4c08be8b099a661f4c2ee6a507d6ce5ce0c8e0a9fb8b682df30b3343a13c270f1c68ea97b7f1f4bf615a12593f20ca
|
data/README.md
CHANGED
@@ -19,7 +19,7 @@ cat <<EOT > ~/.capwatch
|
|
19
19
|
"symbols": {
|
20
20
|
"MAID": 25452.47,
|
21
21
|
"GAME": 22253.51,
|
22
|
-
"
|
22
|
+
"NEO": 3826.53,
|
23
23
|
"FCT": 525.67875,
|
24
24
|
"SC": 4152770,
|
25
25
|
"DCR": 453.22,
|
@@ -34,6 +34,25 @@ EOT
|
|
34
34
|
|
35
35
|
$ capwatch
|
36
36
|
|
37
|
+
|
38
|
+
## Telegram
|
39
|
+
|
40
|
+
If you want to get portfolio notifications on demand to your telegram, you'll need:
|
41
|
+
|
42
|
+
1. Create a telegram bot via [BotFather](https://core.telegram.org/bots)
|
43
|
+
2. Get the bot `token`
|
44
|
+
3. Start capwatch with the bot `token` in hand
|
45
|
+
|
46
|
+
|
47
|
+
$capwatch -e <bot_token>
|
48
|
+
|
49
|
+
Currently Capwatch supports only two commands
|
50
|
+
|
51
|
+
- `/watch` - shows the entire portfolio
|
52
|
+
- `/cap` - shows only the footer of the portfolio, e.g. summaries
|
53
|
+
|
54
|
+
Remember to start it on a server in a tmux window or as a daemon.
|
55
|
+
|
37
56
|
## Fund Examples
|
38
57
|
|
39
58
|
Fund examples can be found [here](funds/demo)
|
@@ -41,3 +60,7 @@ Fund examples can be found [here](funds/demo)
|
|
41
60
|
Demo funds taken from www.bluemagic.info
|
42
61
|
|
43
62
|
Data is being processed from from http://coinmarketcap.com
|
63
|
+
|
64
|
+
## Todo
|
65
|
+
- [ ] Write Tests
|
66
|
+
- [ ] Re-factor the table class
|
data/capwatch.gemspec
CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
|
26
26
|
spec.add_dependency 'terminal-table', '~> 1.8'
|
27
27
|
spec.add_dependency 'colorize', '~> 0.8'
|
28
|
+
spec.add_dependency 'telegram_bot', '~> 0.0.7'
|
28
29
|
|
29
30
|
spec.add_development_dependency 'bundler', '~> 1.15'
|
30
31
|
spec.add_development_dependency 'rake', '~> 10.0'
|
data/exe/capwatch
CHANGED
@@ -4,12 +4,14 @@ require 'capwatch'
|
|
4
4
|
include Capwatch
|
5
5
|
|
6
6
|
options = CLI.parse(ARGV)
|
7
|
-
capwatch_file = File.expand_path('~/.capwatch')
|
8
|
-
fund = JSON.parse(File.open(capwatch_file).read)
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
if options.telegram
|
9
|
+
Telegram.new(token: options.telegram).start
|
10
|
+
else
|
11
|
+
loop do
|
12
|
+
table = Calculator.fund_hash(FundParser.new.fund, CoinMarketCap.fetch)
|
13
|
+
system('clear')
|
14
|
+
puts Console.draw_table(table)
|
15
|
+
sleep options.tick
|
16
|
+
end
|
15
17
|
end
|
data/funds/demo/basic.json
CHANGED
data/funds/demo/dynamic.json
CHANGED
data/lib/capwatch.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'colorize'
|
2
2
|
require 'terminal-table'
|
3
|
+
require 'telegram_bot'
|
3
4
|
|
4
5
|
require 'capwatch/version'
|
6
|
+
require 'capwatch/fundparser'
|
5
7
|
require 'capwatch/coinmarketcap'
|
6
8
|
require 'capwatch/calculator'
|
7
9
|
require 'capwatch/cli'
|
8
10
|
require 'capwatch/console'
|
11
|
+
require 'capwatch/telegram'
|
data/lib/capwatch/cli.rb
CHANGED
data/lib/capwatch/console.rb
CHANGED
@@ -1,25 +1,35 @@
|
|
1
1
|
module Capwatch
|
2
2
|
class Console
|
3
|
-
def self.
|
3
|
+
def self.format_table(hash)
|
4
4
|
hash[:table].each do |x|
|
5
5
|
x[1] = format_usd(x[1])
|
6
6
|
x[3] = format_usd(x[3])
|
7
7
|
x[4] = format_btc(x[4])
|
8
8
|
x[5] = format_eth(x[5])
|
9
9
|
x[6] = format_percent(x[6])
|
10
|
-
x[7] =
|
11
|
-
x[8] =
|
10
|
+
x[7] = format_percent(x[7])
|
11
|
+
x[8] = format_percent(x[8])
|
12
12
|
end
|
13
13
|
hash[:footer][3] = format_usd(hash[:footer][3])
|
14
14
|
hash[:footer][4] = format_btc(hash[:footer][4])
|
15
15
|
hash[:footer][5] = format_eth(hash[:footer][5])
|
16
|
-
hash[:footer][7] =
|
17
|
-
hash[:footer][8] =
|
16
|
+
hash[:footer][7] = format_percent(hash[:footer][7])
|
17
|
+
hash[:footer][8] = format_percent(hash[:footer][8])
|
18
|
+
hash
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.colorize_table(hash)
|
22
|
+
hash[:table].each do |x|
|
23
|
+
x[7] = condition_color(x[7])
|
24
|
+
x[8] = condition_color(x[8])
|
25
|
+
end
|
26
|
+
hash[:footer][7] = condition_color(hash[:footer][7])
|
27
|
+
hash[:footer][8] = condition_color(hash[:footer][8])
|
18
28
|
hash
|
19
29
|
end
|
20
30
|
|
21
31
|
def self.draw_table(hash)
|
22
|
-
hash = colorize_table(hash)
|
32
|
+
hash = colorize_table(format_table(hash))
|
23
33
|
table = Terminal::Table.new do |t|
|
24
34
|
t.title = hash[:title].upcase
|
25
35
|
t.style = {
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Capwatch
|
4
|
+
class Telegram
|
5
|
+
|
6
|
+
attr_reader :logger, :bot, :fund
|
7
|
+
|
8
|
+
def initialize(fund: FundParser.new.fund, token:)
|
9
|
+
@fund = fund
|
10
|
+
@logger = Logger.new(STDOUT, Logger::DEBUG)
|
11
|
+
@logger.debug 'Starting telegram bot...'
|
12
|
+
@bot = TelegramBot.new(token: token)
|
13
|
+
end
|
14
|
+
|
15
|
+
def start
|
16
|
+
bot.get_updates(fail_silently: true) do |message|
|
17
|
+
logger.info "@#{message.from.username}: #{message.text}"
|
18
|
+
command = message.get_command_for(bot)
|
19
|
+
|
20
|
+
message.reply do |reply|
|
21
|
+
begin
|
22
|
+
case command
|
23
|
+
when /\/cap/i
|
24
|
+
table = Console.format_table(Calculator.fund_hash(fund, CoinMarketCap.fetch))
|
25
|
+
reply.text = table[:footer].reject(&:empty?).join("\n")
|
26
|
+
when /\/watch/i
|
27
|
+
table = Console.format_table(Calculator.fund_hash(fund, CoinMarketCap.fetch))
|
28
|
+
text = [
|
29
|
+
"*#{table[:title]}*",
|
30
|
+
"\n",
|
31
|
+
table[:table].map{|x| x.join(" | ") }.join("\n"),
|
32
|
+
"\n",
|
33
|
+
table[:footer].reject(&:empty?).join(" | ")
|
34
|
+
].join("\n")
|
35
|
+
reply.text = text
|
36
|
+
else
|
37
|
+
reply.text = "#{message.from.first_name}, have no idea what _#{command}_ means."
|
38
|
+
end
|
39
|
+
logger.info "sending #{reply.text.inspect} to @#{message.from.username}"
|
40
|
+
reply.parse_mode = 'Markdown'
|
41
|
+
reply.send_with(bot)
|
42
|
+
rescue => e
|
43
|
+
logger.error e
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
data/lib/capwatch/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capwatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Bugaiov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: terminal-table
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: telegram_bot
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.7
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.7
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +122,8 @@ files:
|
|
108
122
|
- lib/capwatch/cli.rb
|
109
123
|
- lib/capwatch/coinmarketcap.rb
|
110
124
|
- lib/capwatch/console.rb
|
125
|
+
- lib/capwatch/fundparser.rb
|
126
|
+
- lib/capwatch/telegram.rb
|
111
127
|
- lib/capwatch/version.rb
|
112
128
|
homepage: https://cryptowatch.one
|
113
129
|
licenses:
|