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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c9b44547b6d811ad7332aa1fa72b75f1bbac24d
4
- data.tar.gz: aebbf60d6fa1c74c41d010174e6a5687c701ae9f
3
+ metadata.gz: 37394be004f4cec6e948ddb4b59cf484ec764773
4
+ data.tar.gz: 305494f7086c7cbc00253428075f5cdf1830170d
5
5
  SHA512:
6
- metadata.gz: 4b56080518be754488a16c2ba89aaa7b95c8345b912c0e2be6dca701865497b17b0b31a50cfd41cc57716acb808c5085d76ceda13fb99dbc2bf3d23ea4122564
7
- data.tar.gz: 1da362d1a322a282bfbf7aebc6be9f24fc897fa74bac472c60464f8ac8d3782fab3e08f4ea515d1298a29b907363d8cf9ec39e884a21ced7c890cf8fb2e62e78
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
- "ANS": 3826.53,
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
@@ -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'
@@ -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
- loop do
11
- table = Calculator.fund_hash(fund, CoinMarketCap.fetch)
12
- system('clear')
13
- puts Console.draw_table(table)
14
- sleep options.tick
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
@@ -3,7 +3,7 @@
3
3
  "symbols": {
4
4
  "MAID": 25452.47,
5
5
  "GAME": 22253.51,
6
- "ANS": 3826.53,
6
+ "NEO": 3826.53,
7
7
  "FCT": 525.67875,
8
8
  "SC": 4152770,
9
9
  "DCR": 453.22,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "Dynamic Fund",
3
3
  "symbols": {
4
- "ANS": 5102.04,
4
+ "NEO": 5102.04,
5
5
  "GAME": 41952.55,
6
6
  "SC": 10341309,
7
7
  "DCR": 791.489,
@@ -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'
@@ -10,6 +10,9 @@ module Capwatch
10
10
  opts.on('-t', '--tick [Integer]', Integer, 'Tick Interval') do |t|
11
11
  options.tick = t
12
12
  end
13
+ opts.on('-e', '--telegram-token=', String) do |val|
14
+ options.telegram = val
15
+ end
13
16
  end
14
17
  opt_parser.parse!(args)
15
18
  options
@@ -1,25 +1,35 @@
1
1
  module Capwatch
2
2
  class Console
3
- def self.colorize_table(hash)
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] = condition_color(format_percent(x[7]))
11
- x[8] = condition_color(format_percent(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] = condition_color(format_percent(hash[:footer][7]))
17
- hash[:footer][8] = condition_color(format_percent(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,10 @@
1
+ module Capwatch
2
+ class FundParser
3
+ def initialize(filename = '~/.capwatch')
4
+ @capwatch_file = File.expand_path(filename)
5
+ end
6
+ def fund
7
+ JSON.parse(File.open(@capwatch_file).read)
8
+ end
9
+ end
10
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Capwatch
2
- VERSION = '0.1.12'.freeze
2
+ VERSION = '0.1.13'.freeze
3
3
  end
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.12
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-05 00:00:00.000000000 Z
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: