satoshi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 396252905422c7ca379e749a38bae8d6e7c760b60d0654945b1a62f9a0b8603f
4
+ data.tar.gz: ce306dec328166f8152de49ee093cc785381b0c26d4ddba9b5b6def43fae043e
5
+ SHA512:
6
+ metadata.gz: 554e1121f301989b0b578538fba328802d1bded7f02204c58091b10468de6ff465e0dd9a9ae2b885534f9551cb2163b1865574b98b4fc6f2472dba871b11f545
7
+ data.tar.gz: b59778dadc5058f90d954a354ce35729c4e789cac347e13b4fdd35373b8581f06b9ba42c3ed4d03b7010dc187035f98ef7a696353c750363f645dd1ec55ff25d
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.3
7
+ before_install: gem install bundler -v 1.16.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at harryfbloch@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+ gem "nokogiri"
5
+ gem "catpix"
6
+ gem "timeout"
7
+
8
+ group :test,:development do
9
+ gem 'pry'
10
+ end
11
+ # Specify your gem's dependencies in satoshi.gemspec
12
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ satoshi (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ catpix (0.2.0)
10
+ docopt (~> 0.5, >= 0.5.0)
11
+ rmagick (~> 2.15, >= 2.15.2)
12
+ ruby-terminfo (~> 0.1, >= 0.1.1)
13
+ tco (~> 0.1, >= 0.1.8)
14
+ coderay (1.1.2)
15
+ diff-lcs (1.3)
16
+ docopt (0.6.1)
17
+ method_source (0.9.0)
18
+ mini_portile2 (2.3.0)
19
+ nokogiri (1.8.5)
20
+ mini_portile2 (~> 2.3.0)
21
+ pry (0.11.3)
22
+ coderay (~> 1.1.0)
23
+ method_source (~> 0.9.0)
24
+ rake (10.5.0)
25
+ rmagick (2.16.0)
26
+ rspec (3.8.0)
27
+ rspec-core (~> 3.8.0)
28
+ rspec-expectations (~> 3.8.0)
29
+ rspec-mocks (~> 3.8.0)
30
+ rspec-core (3.8.0)
31
+ rspec-support (~> 3.8.0)
32
+ rspec-expectations (3.8.2)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.8.0)
35
+ rspec-mocks (3.8.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.8.0)
38
+ rspec-support (3.8.0)
39
+ ruby-terminfo (0.1.1)
40
+ tco (0.1.8)
41
+ timeout (0.0.1)
42
+ timeout-extensions
43
+ timeout-extensions (0.1.1)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ bundler (~> 1.16)
50
+ catpix
51
+ nokogiri
52
+ pry
53
+ rake (~> 10.0)
54
+ rspec (~> 3.0)
55
+ satoshi!
56
+ timeout
57
+
58
+ BUNDLED WITH
59
+ 1.16.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 harryFBloch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Satoshi
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/satoshi`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'satoshi'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install satoshi
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/harryFBloch/satoshi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Satoshi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/harryFBloch/satoshi/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "satoshi"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/satoshi ADDED
@@ -0,0 +1,4 @@
1
+ #!usr/bin/env ruby
2
+ require_relative "../lib/satoshi"
3
+
4
+ Satoshi::Cli.run
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,143 @@
1
+ class Satoshi::Cli
2
+
3
+ @@selectable_array = []
4
+
5
+ def self.run
6
+ puts "Welcome to Satoshi! Here you can find info on the top 100 Coins:"
7
+ self.menu
8
+ end
9
+
10
+ def self.menu
11
+ self.create_coins(coin_array = Satoshi::Scraper.scrape_top_100_coins)
12
+ self.first_prompt_for_coins
13
+ end
14
+
15
+ def self.create_coins(coin_array)
16
+ coin_array.each {|coin_hash| Satoshi::Coin.create(coin_hash[:name], coin_hash[:info_link], coin_hash[:index], coin_hash[:usd_price])}
17
+ end
18
+
19
+ def self.first_prompt_for_coins
20
+ puts "-------------------------"
21
+ puts "enter 1-10 to view the top coins 1 = 1-10 , 2 = 11-20, 3 = 21-30...."
22
+ puts "or enter the name of the coin you wish to view"
23
+ puts "-------------------------"
24
+ input = gets.chomp
25
+ #binding.pry
26
+ self.exit if input == "exit"
27
+ coin = Satoshi::Coin.find_by_name(input)
28
+ #binding.pry
29
+ if coin
30
+ coin.load_info(Satoshi::Scraper.scrape_info_page(coin.info_link))
31
+ self.info_menu(coin)
32
+ end
33
+ input = input.to_i unless input == "exit"
34
+ if input > 0 && input < 11
35
+ input -= 1
36
+ lower_range = input * 10
37
+ higher_range = lower_range + 10
38
+ coins_to_print = Satoshi::Coin.all[lower_range...higher_range]
39
+ self.selectable_array = coins_to_print
40
+ puts "-------------------------"
41
+ coins_to_print.each {|coin| puts"#{coin.index}. #{coin.name} $#{coin.usd_price}"}
42
+ puts "-------------------------"
43
+ self.get_info_for_coin
44
+ else
45
+ #binding.pry
46
+ puts "Invalid argument, please try again!".red
47
+ self.first_prompt_for_coins
48
+ end
49
+ end
50
+
51
+ def self.get_info_for_coin
52
+ puts "Enter 1-10 to view coin info"
53
+ input = gets.chomp
54
+ return self.exit if input == "exit"
55
+ input = input.to_i
56
+ if input <= 10 && input > 0
57
+ coin = self.selectable_array[input - 1]
58
+ coin.load_info(Satoshi::Scraper.scrape_info_page(coin.info_link))
59
+ self.info_menu(coin)
60
+ else
61
+ puts "Invalid argument please try again!".red
62
+ self.get_info_for_coin
63
+ end
64
+ end
65
+
66
+ def self.info_menu(coin)
67
+ puts "-------------------------"
68
+ puts "You are looking at #{coin.name}"
69
+ puts "Enter graph , search, ticker, delete, or exit:"
70
+ input = gets.chomp
71
+ case input
72
+ when "graph"
73
+ type = self.graph_type_from_coin(coin)
74
+ timespan = self.graph_timeframe_from_coin(coin)
75
+ Satoshi::Graph.createGraphForCoin(coin.ticker, type, timespan)
76
+ self.info_menu(coin)
77
+ when "ticker"
78
+ Satoshi::Ticker.coin_array << coin unless Satoshi::Ticker.coin_array.find {|fcoin| fcoin == coin}
79
+ Satoshi::Ticker.ticker_for_coin_array(coin)
80
+ when "add"
81
+ Satoshi::Ticker.coin_array << coin unless Satoshi::Ticker.coin_array.find {|fcoin| fcoin == coin}
82
+ puts "coin has been added to ticker..You can add multiple coins to the ticker!".green
83
+ self.info_menu(coin)
84
+ when "delete"
85
+ Satoshi::Ticker.coin_array.delete_if {|dcoin| dcoin == coin}
86
+ puts "coin has been removed from ticker".red
87
+ self.info_menu(coin)
88
+ when "search"
89
+ self.first_prompt_for_coins
90
+ when "exit"
91
+ self.exit
92
+ else
93
+ puts "Invalid argument please try again!".red
94
+ self.info_menu(coin)
95
+ end
96
+ end
97
+
98
+ def self.graph_type_from_coin(coin)
99
+ puts "Would You Like to see a (c)candlestick or (l)line graph?"
100
+ input_type = gets.chomp
101
+ type = ""
102
+ case input_type
103
+ when "c"
104
+ type = "candlestick"
105
+ when "l"
106
+ type = "dark"
107
+ when "exit"
108
+ self.exit
109
+ else
110
+ puts "Invalid argument please try again!".red
111
+ self.graph_coin(coin)
112
+ end
113
+ type
114
+ end
115
+
116
+ def self.graph_timeframe_from_coin(coin)
117
+ puts "What time span would you like the graph to be?"
118
+ puts "Enter: 1y, 30d, 7d, or 24h"
119
+ timespan = gets.chomp
120
+ if timespan == "1y" || timespan == "30d" || timespan == "7d" || timespan == "24h"
121
+ timespan
122
+ elsif timespan == "exit"
123
+ self.exit
124
+ else
125
+ puts "Invalid argument please try again!".red
126
+ self.graph_timeframe_from_coin(coin)
127
+ end
128
+ end
129
+
130
+ def self.selectable_array=(array)
131
+ @@selectable_array = array
132
+ end
133
+
134
+ def self.selectable_array
135
+ @@selectable_array
136
+ end
137
+
138
+ def self.exit
139
+ puts "-------------------------"
140
+ abort("Goodbye")
141
+ end
142
+
143
+ end
@@ -0,0 +1,51 @@
1
+ class Satoshi::Coin
2
+ attr_accessor :percent_change, :btc_price, :usd_market_cap, :btc_market_cap, :volume_usd_24hr, :ticker, :volume_btc_24hr, :circulating_supply_btc, :max_supply, :info_link, :usd_price, :index, :name, :last_price
3
+ @@all = []
4
+
5
+ def save
6
+ self.class.all << self
7
+ end
8
+
9
+ def self.create(name, link, index, price)
10
+ coin = self.new
11
+ coin.name = name
12
+ coin.info_link = link
13
+ coin.index = index
14
+ coin.usd_price = price
15
+ coin.last_price = price.to_f
16
+ coin.save
17
+ self.sort_all_by_index
18
+ end
19
+
20
+ def self.sort_all_by_index
21
+ self.all.sort_by { |coin| coin.index}
22
+ end
23
+
24
+ def self.all
25
+ @@all
26
+ end
27
+
28
+ def load_info(info_hash)
29
+ info_hash.each {|key, value|
30
+ self.send("#{key}=",value)
31
+ }
32
+ display_info
33
+ end
34
+
35
+ def display_info
36
+ puts "-------------------------"
37
+ puts "#{self.name} = $#{self.usd_price}"
38
+ puts "Price In btc = #{self.btc_price}"
39
+ puts "Ticker = #{self.ticker}"
40
+ puts "24hr Percent Change = #{self.percent_change}%"
41
+ puts "Market Cap = $#{self.usd_market_cap} = #{self.btc_market_cap} btc"
42
+ puts "24hr Volume = $#{self.volume_usd_24hr} = #{self.volume_btc_24hr} btc"
43
+ puts "Circulating Supply = #{self.circulating_supply_btc}"
44
+ puts "Max Supply = #{self.max_supply}" if self.max_supply
45
+ puts "-------------------------"
46
+ end
47
+
48
+ def self.find_by_name(name)
49
+ self.all.find {|coin| coin.name.downcase == name.downcase}
50
+ end
51
+ end
Binary file
@@ -0,0 +1,27 @@
1
+ class Satoshi::Graph
2
+ attr_accessor
3
+ def self.createGraphForCoin(ticker, type , timeframe)
4
+ ticker = "iota" if ticker == "MIOTA"
5
+ url = "https://cryptohistory.org/charts/#{type}/#{ticker.downcase}-usd/#{timeframe}/png"
6
+ path = 'lib/satoshi/graph.png'
7
+
8
+ begin
9
+ File.write path, open(url).read
10
+ rescue OpenURI::HTTPError
11
+ puts "ERROR WITH TICKER FOR THAT COIN"
12
+ else
13
+ self.print_pic(path)
14
+ end
15
+ end
16
+
17
+ def self.print_pic(path)
18
+ Catpix::print_image path,
19
+ :limit_x => 0.8,
20
+ :limit_y => 1.2,
21
+ :center_x => true,
22
+ :center_y => true,
23
+ # :bg => "gray",
24
+ # :bg_fill => true,
25
+ :resolution => "high"
26
+ end
27
+ end
@@ -0,0 +1,54 @@
1
+ class Satoshi::Scraper
2
+ COIN_MARKET_CAP_URL = "https://coinmarketcap.com/"
3
+
4
+ def self.scrape_top_100_coins
5
+ doc = Nokogiri::HTML(open(COIN_MARKET_CAP_URL))
6
+ coin_array = doc.css("tbody tr").each_with_index.map { |coin_container, index|
7
+ name = coin_container.css("a.currency-name-container").text.strip
8
+ link = coin_container.css("a.currency-name-container").attr("href").value
9
+ price = coin_container.css("a.price").attr("data-usd").value.strip
10
+ #puts "#{index + 1}. #{name}-$#{price}"
11
+ coin_hash = {:name => name, :usd_price => price,:index => index + 1 , :info_link => link}
12
+ }
13
+ end
14
+
15
+ def self.scrape_info_page(url)
16
+ doc = Nokogiri::HTML(open(COIN_MARKET_CAP_URL + url))
17
+ info_hash = {}
18
+ info_hash[:percent_change] = doc.css(".details-panel-item--price .h2 span").text
19
+ info_hash[:btc_price] = doc.css(".details-panel-item--price .text-gray span").text.strip
20
+ info_hash[:ticker] = doc.css("span.h3").text.gsub("(","").gsub(")","")
21
+ market_cap_array = doc.css("div.coin-summary-item")
22
+
23
+ market_cap_array.each {|coin_container|
24
+ price_type = coin_container.css("h5.coin-summary-item-header").text
25
+ case price_type
26
+ when "Market Cap"
27
+ info_hash[:usd_market_cap] = coin_container.css("div.coin-summary-item-detail span span")[0].text
28
+ info_hash[:btc_market_cap] = coin_container.css("div.coin-summary-item-detail span span")[2].text.gsub("\n", "")
29
+ when "Volume (24h)"
30
+ info_hash[:volume_usd_24hr] = coin_container.css("div.coin-summary-item-detail span span")[0].text
31
+ info_hash[:volume_btc_24hr] = coin_container.css("div.coin-summary-item-detail span span")[2].text.gsub("\n", "")
32
+ when "Circulating Supply"
33
+ info_hash[:circulating_supply_btc] = coin_container.css("div.coin-summary-item-detail span").text.strip
34
+ when "Max Supply"
35
+ info_hash[:max_supply] = coin_container.css("div.coin-summary-item-detail span").text.strip
36
+ end
37
+ }
38
+ info_hash
39
+ end
40
+
41
+ def self.scrape_news_for_coin_url(url)
42
+ doc = Nokogiri::HTML(open(COIN_MARKET_CAP_URL + url + "/#social"))
43
+ binding.pry
44
+ twitter = doc.css("div#social .col-sm-6")[0].css(".twitter-timeline").attr("href").value
45
+ rediit = doc.css("div#social .col-sm-6")[1].css(".reddit-timeline")
46
+ end
47
+
48
+ def self.scrape_new_price_for_coin(url)
49
+ doc = Nokogiri::HTML(open(COIN_MARKET_CAP_URL + url))
50
+ doc.css(".details-panel-item--price__value").text.to_f
51
+ end
52
+
53
+
54
+ end
@@ -0,0 +1,34 @@
1
+ class String
2
+ # colorization
3
+ def colorize(color_code)
4
+ "\e[#{color_code}m#{self}\e[0m"
5
+ end
6
+
7
+ def black
8
+ colorize(30)
9
+ end
10
+
11
+ def red
12
+ colorize(31)
13
+ end
14
+
15
+ def green
16
+ colorize(32)
17
+ end
18
+
19
+ def yellow
20
+ colorize(33)
21
+ end
22
+
23
+ def blue
24
+ colorize(34)
25
+ end
26
+
27
+ def pink
28
+ colorize(35)
29
+ end
30
+
31
+ def light_blue
32
+ colorize(36)
33
+ end
34
+ end
@@ -0,0 +1,101 @@
1
+ class Satoshi::Ticker
2
+ require "timeout"
3
+
4
+ @@stop_bool = false
5
+ @@input = " "
6
+ @@coin_array = []
7
+
8
+ # def self.ticker_for_coin(coin)
9
+ # puts "press control + c to stop"
10
+ # puts "-------------------------"
11
+ # puts "-------------------------"
12
+ # #Timeout::timeout(20) do
13
+ # self.get_and_display_price(coin)
14
+ # self.input = gets.chomp.to_s
15
+ # case self.input
16
+ # when "exit"
17
+ # Satoshi::Cli.exit
18
+ # when "search"
19
+ # self.stop_bool = true
20
+ # when "stop"
21
+ # self.stop_bool = true
22
+ # Satoshi::Cli.info_menu(coin)
23
+ # else
24
+ # self.ticker_for_coin(coin)
25
+ # end
26
+ # #end
27
+ # end
28
+
29
+ def self.get_and_display_price(coin)
30
+ Thread.new do
31
+ while @@stop_bool == false
32
+ puts "-------------------------" if self.coin_array[0] == coin
33
+ new_price = Satoshi::Scraper.scrape_new_price_for_coin(coin.info_link).to_f
34
+ string = "#{coin.name} $#{new_price}"
35
+ if new_price > coin.last_price
36
+ ##green
37
+ string = string.green
38
+ elsif new_price < coin.last_price
39
+ ##gray
40
+ string = string.red
41
+ else
42
+ string = string.black
43
+ end
44
+ puts string
45
+ coin.last_price = new_price
46
+ sleep(5)
47
+ end
48
+ end
49
+ end
50
+
51
+ def self.loop_on_new_tread_for_ticker_array
52
+ Thread.new do
53
+ self.coin_array.each{ |coin| self.get_and_display_price(coin)}
54
+ end
55
+ end
56
+
57
+ def self.ticker_for_coin_array(coin_called_from)
58
+ puts "Enter stop, search ,or exit to stop ticker".red
59
+ puts "-------------------------"
60
+ puts "-------------------------"
61
+ #Timeout::timeout(20) do
62
+ self.loop_on_new_tread_for_ticker_array
63
+ self.input = gets.chomp.to_s
64
+ case self.input
65
+ when "exit"
66
+ Satoshi::Cli.exit
67
+ when "search"
68
+ Satoshi::Cli.first_prompt_for_coins
69
+ when "stop"
70
+ self.stop_bool = true
71
+ Satoshi::Cli.info_menu(coin_called_from)
72
+ else
73
+ self.ticker_for_coin_array(coin_called_from)
74
+ end
75
+ #end
76
+ end
77
+
78
+ def self.stop_bool=(bool)
79
+ @@stop_bool = bool
80
+ end
81
+
82
+ def self.stop_bool
83
+ self.stop_bool
84
+ end
85
+
86
+ def self.input=(text)
87
+ @@input = text
88
+ end
89
+
90
+ def self.input
91
+ @@input
92
+ end
93
+
94
+ def self.coin_array=(array)
95
+ @@coin_array = array
96
+ end
97
+
98
+ def self.coin_array
99
+ @@coin_array
100
+ end
101
+ end
@@ -0,0 +1,3 @@
1
+ module Satoshi
2
+ VERSION = "0.1.0"
3
+ end
data/lib/satoshi.rb ADDED
@@ -0,0 +1,16 @@
1
+
2
+ require 'pry'
3
+ require "nokogiri"
4
+ require 'open-uri'
5
+ require "catpix"
6
+
7
+ module Satoshi
8
+ # Your code goes here...
9
+ end
10
+
11
+ require_relative "satoshi/cli"
12
+ require_relative "satoshi/scraper"
13
+ require_relative "satoshi/coin"
14
+ require_relative "satoshi/graph.rb"
15
+ require_relative "satoshi/ticker.rb"
16
+ require_relative "satoshi/string_ext.rb"
data/satoshi.gemspec ADDED
@@ -0,0 +1,41 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "satoshi/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "satoshi"
8
+ spec.version = Satoshi::VERSION
9
+ spec.authors = ["harryFBloch"]
10
+ spec.email = ["harryfbloch@gmail.com"]
11
+
12
+ spec.summary = %q{ Write a short summary, because RubyGems requires one.}
13
+ spec.description = %q{ Write a longer description or delete this line.}
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+ #
21
+ # spec.metadata["homepage_uri"] = spec.homepage
22
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
23
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
24
+ # else
25
+ # raise "RubyGems 2.0 or newer is required to protect against " \
26
+ # "public gem pushes."
27
+ # end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "bin"
35
+ spec.executables = "satoshi"
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.16"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: satoshi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - harryFBloch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: " Write a longer description or delete this line."
56
+ email:
57
+ - harryfbloch@gmail.com
58
+ executables:
59
+ - satoshi
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".DS_Store"
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - CODE_OF_CONDUCT.md
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - bin/console
74
+ - bin/satoshi
75
+ - bin/setup
76
+ - lib/.DS_Store
77
+ - lib/satoshi.rb
78
+ - lib/satoshi/cli.rb
79
+ - lib/satoshi/coin.rb
80
+ - lib/satoshi/graph.png
81
+ - lib/satoshi/graph.rb
82
+ - lib/satoshi/scraper.rb
83
+ - lib/satoshi/string_ext.rb
84
+ - lib/satoshi/ticker.rb
85
+ - lib/satoshi/version.rb
86
+ - satoshi.gemspec
87
+ homepage:
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.7.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Write a short summary, because RubyGems requires one.
111
+ test_files: []