stock_info 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7d2aa9d2adf0d345b95baac59daf04046176b81
4
- data.tar.gz: c7b99c55c21869793d2e71a1edafb875c97ee045
3
+ metadata.gz: 476a3a1026da6b7478795475012c06dd0b30c9f0
4
+ data.tar.gz: f7d79d9b713ae7b4b0ac0485e988ba0da206b2b3
5
5
  SHA512:
6
- metadata.gz: d1f2041a7ad54038f398d0c0a77ae144a69530f3c2dcd0d566b6631c7a6c4ae0ff4bf4de9fd970014db20edf36de8ea4649ec6b7f5ae3b88ad4b13f62ecc343b
7
- data.tar.gz: aed8e382818cc9c3574e2196977acbee1355418cb5f1058ea6467e8d1c4c3bbd65e729776a50a1455ecc3a4b672fc4e31a004955f29b7d91823c070b468b2ecd
6
+ metadata.gz: e659a227c1c0dbf1569ebf2173d128e97378afe83446161f74b9d9915122b8171b20f2225174fd8add8467414a86f95e5c1310310d30962d6953174ab3db705c
7
+ data.tar.gz: 4061642252a6bd222ada67d27b7f0716a9366a82b6911469ec257fe7b008f801307d19f1390ee382103f9380d77eeb389d9b70b51329fb7337b3f13e31508bc2
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
+ source 'https://rubygems.org'
1
2
 
2
- source "https://rubygems.org"
3
-
4
- git_source(:github) {|repo_name| "https://github.com/decentralvision/stock_info" }
3
+ git_source(:github) { |_repo_name| 'https://github.com/decentralvision/stock_info' }
5
4
 
6
5
  # Specify your gem's dependencies in stock_info.gemspec
7
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stock_info (0.1.1)
4
+ stock_info (0.1.2)
5
5
  nokogiri (~> 1.10)
6
6
 
7
7
  GEM
data/NOTES.md CHANGED
@@ -1,17 +1 @@
1
- Can't build gem into executable.
2
-
3
- Give a list of trending tickers and their % change : https://finance.yahoo.com/trending-tickers
4
- Scrape news articles for a given stock ticker symbol https://finviz.com/quote.ashx?t="ticker symbol"
5
-
6
1
  Things to work on:
7
-
8
- Referencing with namespace StockInfo::Stock is this correct?
9
-
10
- DRY code
11
-
12
- Get rid of system error from opening browser
13
-
14
- Can't pull data from : short_doc = Nokogiri::HTML(open("https://www.nakedshortreport.com/company/#{symbol}"))
15
-
16
- Why?
17
-
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "stock_info"
3
+ require 'bundler/setup'
4
+ require 'stock_info'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "stock_info"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'bundler/setup'
3
3
  require_relative '../lib/stock_info'
4
- StockInfo::CLI.new.call
4
+ StockInfo::CLI.new.call
@@ -1,36 +1,37 @@
1
1
  # Our CLI controller
2
2
  class StockInfo::CLI
3
- def call
3
+ def call
4
+ trending_tickers
5
+ menu
6
+ goodbye
7
+ end
8
+
9
+ def trending_tickers
10
+ puts "Loading today's trending stocks..."
11
+ StockInfo::Stock.print_trending
12
+ end
13
+
14
+ def menu
15
+ input = nil
16
+ while input != 'exit'
17
+ puts 'Enter the ticker symbol of a stock you would like more info on.'
18
+ puts "Other commands: 'exit' - exits stock-info, 'trending' - shows trending stocks."
19
+ input = gets.strip.downcase
20
+ if input == 'trending'
4
21
  trending_tickers
5
- menu
6
- goodbye
22
+ elsif StockInfo::Stock.check_symbol(input.upcase) == true
23
+ stock = StockInfo::Stock.new(input.upcase)
24
+ stock.print_info
25
+ puts 'View recent news articles related to this stock? (yes/no)'
26
+ news_bool = gets.strip[0].downcase
27
+ input = StockInfo::News.news_menu(stock) if news_bool == 'y'
28
+ elsif input != 'exit'
29
+ puts 'Please input a command or ticker symbol'
30
+ end
7
31
  end
8
- def trending_tickers
9
- puts "Loading today's trending stocks..."
10
- StockInfo::Stock.print_trending
11
- end
12
- def menu
13
- input = nil
14
- while input != 'exit'
15
- puts "Enter the ticker symbol of a stock you would like more info on."
16
- puts "Other commands: 'exit' - exits stock-info, 'trending' - shows trending stocks."
17
- input = gets.strip.downcase
18
- if input == 'trending'
19
- trending_tickers
20
- elsif StockInfo::Stock.check_symbol(input.upcase) == true
21
- stock = StockInfo::Stock.new(input.upcase)
22
- stock.print_info
23
- puts "View recent news articles related to this stock? (yes/no)"
24
- news_bool = gets.strip[0].downcase
25
- if news_bool == 'y'
26
- StockInfo::Stock::News.news_menu(stock)
27
- end
28
- elsif input != 'exit'
29
- puts 'Please input a command or ticker symbol'
30
- end
31
- end
32
- end
33
- def goodbye
34
- puts "Goodbye and good luck!"
35
- end
36
- end
32
+ end
33
+
34
+ def goodbye
35
+ puts 'Goodbye and good luck!'
36
+ end
37
+ end
@@ -1,43 +1,45 @@
1
- class StockInfo::Stock::News
2
- attr_accessor :symbol, :title, :source, :link
3
- def self.get_news(symbol)
4
- news = []
5
- doc = Nokogiri::HTML(open("https://finviz.com/quote.ashx?t=#{symbol}"))
6
- i=0
7
- 10.times do
8
- article = self.new
9
- article.symbol = symbol
10
- sources = doc.css("table#news-table.fullview-news-outer tr span") - doc.css("table#news-table.fullview-news-outer tr span.body-table-news-gain")
11
- article.title = doc.css("table#news-table.fullview-news-outer tr")[i].css(".tab-link-news").text
12
- article.source = sources[i].text
13
- article.link = doc.css("table#news-table.fullview-news-outer tr td a")[i].attribute("href").value
14
- news << article
15
- i+=1
16
- end
17
- news
18
- end
19
- def self.news_menu(stock)
20
- input = nil
21
- while input != 'menu' && input != 'exit'
22
- stock.print_news
23
- puts "Enter the number of an article you would like to open in your web browser, or 'menu' to return to the main menu"
24
- input = gets.strip
25
- if input.to_i > 0 && input.to_i <= 10
26
- self.open_url(stock.news[(input.to_i) -1].link)
27
- elsif input.downcase != 'menu' && input.downcase != 'exit'
28
- puts "Enter the number of an article or 'menu'"
29
- end
30
- end
1
+ class StockInfo::News
2
+ attr_accessor :symbol, :title, :source, :link
3
+
4
+ def self.get_news(stock)
5
+ symbol = stock.symbol
6
+ stock.news.clear
7
+ doc = Nokogiri::HTML(open("https://finviz.com/quote.ashx?t=#{symbol}"))
8
+ i = 0
9
+ 10.times do
10
+ article = new
11
+ article.symbol = symbol
12
+ sources = doc.css('table#news-table.fullview-news-outer tr span') - doc.css('table#news-table.fullview-news-outer tr span.body-table-news-gain')
13
+ article.title = doc.css('table#news-table.fullview-news-outer tr')[i].css('.tab-link-news').text
14
+ article.source = sources[i].text
15
+ article.link = doc.css('table#news-table.fullview-news-outer tr td a')[i].attribute('href').value
16
+ stock.news << article
17
+ i += 1
31
18
  end
19
+ end
32
20
 
33
- def self.open_url(link)
34
- if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
35
- system "start #{link}"
36
- elsif RbConfig::CONFIG['host_os'] =~ /darwin/
37
- system "open #{link}"
38
- elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
39
- system "xdg-open #{link}"
40
- end
21
+ def self.news_menu(stock)
22
+ input = nil
23
+ stock.print_news
24
+ while input != 'menu' && input != 'exit'
25
+ puts "Enter the number of an article you would like to open in your web browser, 'menu' to return to the main menu, 'refresh' to check for recent news, or 'exit' to exit."
26
+ input = gets.strip
27
+ if input.to_i > 0 && input.to_i <= 10
28
+ open_url(stock.news[input.to_i - 1].link)
29
+ elsif input.casecmp('refresh').zero?
30
+ stock.print_news
31
+ end
32
+ end
33
+ 'exit' if input == 'exit'
34
+ end
41
35
 
36
+ def self.open_url(link)
37
+ if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
38
+ system "start #{link} -s"
39
+ elsif RbConfig::CONFIG['host_os'] =~ /darwin/
40
+ system "open #{link} -s"
41
+ elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
42
+ system "xdg-open #{link} 2> /dev/null"
42
43
  end
43
- end
44
+ end
45
+ end
@@ -1,53 +1,59 @@
1
1
  class StockInfo::Stock
2
- attr_accessor :company, :symbol, :daily_change, :price, :news, :earnings, :rvol, :optionable, :short_ratio
3
- def initialize(symbol)
4
- @symbol = symbol
5
- self.get_info(symbol)
2
+ attr_accessor :company, :symbol, :daily_change, :price, :news, :earnings, :rvol, :optionable, :short_ratio
3
+ @@trending = []
4
+ def initialize(symbol)
5
+ @symbol = symbol
6
+ @news = []
7
+ get_info(symbol)
8
+ end
9
+
10
+ def self.check_symbol(symbol)
11
+ open("https://finviz.com/quote.ashx?t=#{symbol}").read
12
+ true
13
+ rescue StandardError => e
14
+ false
15
+ end
16
+
17
+ def get_info(symbol)
18
+ doc = Nokogiri::HTML(open("https://finviz.com/quote.ashx?t=#{symbol}"))
19
+ @company = doc.css('table.fullview-title tr')[1].text
20
+ @rvol = doc.css('table.snapshot-table2 td.snapshot-td2')[-14].text
21
+ @daily_change = doc.css('table.snapshot-table2 td.snapshot-td2')[-1].text
22
+ @price = doc.css('table.snapshot-table2 td.snapshot-td2')[-7].text
23
+ @optionable = doc.css('table.snapshot-table2 td.snapshot-td2')[-18].text
24
+ @short_ratio = doc.css('table.snapshot-table2 td.snapshot-td2')[22].text
25
+ @earnings = doc.css('table.snapshot-table2 td.snapshot-td2')[-10].text
26
+ @earnings = 'None (ETF)' if earnings == '-'
27
+ end
28
+
29
+ def print_news
30
+ StockInfo::News.get_news(self)
31
+ @news.each.with_index(1) do |article, i|
32
+ puts "#{i} | #{article.title} - #{article.source}"
6
33
  end
7
- def self.check_symbol(symbol)
8
- begin
9
- open("https://finviz.com/quote.ashx?t=#{symbol}").read
10
- true
11
- rescue => e
12
- false
13
- end
34
+ end
35
+
36
+ def print_info
37
+ puts "#{company} - Price: #{price} - Change: #{daily_change} - Relative Volume: #{rvol} - Earnings Date: #{earnings} - Optionable: #{optionable} - Short Ratio: #{short_ratio}"
38
+ end
39
+
40
+ def self.print_trending
41
+ trending.each do |stock|
42
+ puts "#{stock.symbol} - Price: #{stock.price} - Change: #{stock.daily_change} - Relative Volume: #{stock.rvol}"
14
43
  end
15
- def get_info(symbol)
16
- doc = Nokogiri::HTML(open("https://finviz.com/quote.ashx?t=#{symbol}"))
17
- self.company = doc.css('table.fullview-title tr')[1].text
18
- self.rvol = doc.css("table.snapshot-table2 td.snapshot-td2")[-14].text
19
- self.daily_change = doc.css("table.snapshot-table2 td.snapshot-td2")[-1].text
20
- self.price = doc.css("table.snapshot-table2 td.snapshot-td2")[-7].text
21
- self.optionable = doc.css("table.snapshot-table2 td.snapshot-td2")[-18].text
22
- self.short_ratio = doc.css("table.snapshot-table2 td.snapshot-td2")[22].text
23
- self.earnings = doc.css("table.snapshot-table2 td.snapshot-td2")[-10].text
24
- if self.earnings == '-'
25
- self.earnings = "None (ETF)"
26
- end
44
+ end
45
+
46
+ def self.trending
47
+ time = Time.now.localtime('-05:00')
48
+ unless (time.saturday? || time.sunday? || time.hour > 20 || time.hour < 4) && @@trending.any?
49
+ i = 0
50
+ doc = Nokogiri::HTML(open('https://finviz.com/screener.ashx?v=110&s=ta_mostactive'))
51
+ 10.times do
52
+ symbol = doc.css('tr.table-dark-row-cp a.screener-link-primary')[i].text
53
+ i += 1
54
+ @@trending << new(symbol)
55
+ end
27
56
  end
28
- def print_news
29
- self.news = News.get_news(self.symbol)
30
- self.news.each.with_index(1) do |article, i|
31
- puts "#{i} | #{article.title} - #{article.source}"
32
- end
33
- end
34
- def print_info
35
- puts "#{self.company} - Price: #{self.price} - Change: #{self.daily_change} - Relative Volume: #{self.rvol} - Earnings Date: #{self.earnings} - Optionable: #{self.optionable} - Short Ratio: #{self.short_ratio}"
36
- end
37
- def self.print_trending
38
- self.trending.each do |stock|
39
- puts "#{stock.symbol} - Price: #{stock.price} - Change: #{stock.daily_change} - Relative Volume: #{stock.rvol}"
40
- end
41
- end
42
- def self.trending
43
- trending = []
44
- i = 0
45
- doc = Nokogiri::HTML(open("https://finviz.com/screener.ashx?v=110&s=ta_mostactive"))
46
- 10.times do
47
- symbol = doc.css("tr.table-dark-row-cp a.screener-link-primary")[i].text
48
- i += 1
49
- trending << self.new(symbol)
50
- end
51
- trending
52
- end
53
- end
57
+ @@trending
58
+ end
59
+ end
@@ -1,3 +1,3 @@
1
1
  module StockInfo
2
- VERSION = "0.1.2"
2
+ VERSION = '0.1.3'.freeze
3
3
  end
data/lib/stock_info.rb CHANGED
@@ -1,8 +1,8 @@
1
- require_relative "./stock_info/version"
2
- require_relative "./stock_info/cli"
3
- require_relative "./stock_info/stock"
4
- require_relative "./stock_info/news"
1
+ require_relative './stock_info/version'
2
+ require_relative './stock_info/cli'
3
+ require_relative './stock_info/stock'
4
+ require_relative './stock_info/news'
5
5
 
6
6
  require 'nokogiri'
7
7
  require 'pry'
8
- require 'open-uri'
8
+ require 'open-uri'
data/stock_info.gemspec CHANGED
@@ -1,30 +1,29 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "stock_info/version"
3
+ require 'stock_info/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "stock_info"
6
+ spec.name = 'stock_info'
8
7
  spec.version = StockInfo::VERSION
9
- spec.authors = ["Tom Kunkel"]
10
- spec.email = ["36858744+decentralvision@users.noreply.github.com"]
8
+ spec.authors = ['Tom Kunkel']
9
+ spec.email = ['36858744+decentralvision@users.noreply.github.com']
11
10
 
12
- spec.summary = "Simple gem providing stock info from finviz.com"
11
+ spec.summary = 'Simple gem providing stock info from finviz.com'
13
12
  spec.description = "This CLI gem provides data and news articles from finviz.com, run the program with 'stock-info'. Commands are provided via prompts in the interface."
14
- spec.homepage = "https://github.com/decentralvision/stock-info"
15
- spec.license = "MIT"
13
+ spec.homepage = 'https://github.com/decentralvision/stock-info'
14
+ spec.license = 'MIT'
16
15
 
17
16
  # Specify which files should be added to the gem when it is released.
18
17
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
19
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
20
  end
22
- spec.bindir = "bin"
23
- spec.executables << "stock-info"
24
- spec.require_paths = ["lib"]
21
+ spec.bindir = 'bin'
22
+ spec.executables << 'stock_info'
23
+ spec.require_paths = ['lib']
25
24
 
26
- spec.add_development_dependency "bundler", "~> 1.16"
27
- spec.add_development_dependency "rake", "~> 10.0"
28
- spec.add_development_dependency "pry", "~> 0.12"
29
- spec.add_dependency "nokogiri", "~> 1.10"
25
+ spec.add_development_dependency 'bundler', '~> 1.16'
26
+ spec.add_development_dependency 'pry', '~> 0.12'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_dependency 'nokogiri', '~> 1.10'
30
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stock_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Kunkel
@@ -25,33 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.16'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '0.12'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '0.12'
41
41
  - !ruby/object:Gem::Dependency
42
- name: pry
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.12'
47
+ version: '10.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.12'
54
+ version: '10.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: nokogiri
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -71,7 +71,7 @@ description: This CLI gem provides data and news articles from finviz.com, run t
71
71
  email:
72
72
  - 36858744+decentralvision@users.noreply.github.com
73
73
  executables:
74
- - stock-info
74
+ - stock_info
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
@@ -85,7 +85,7 @@ files:
85
85
  - Rakefile
86
86
  - bin/console
87
87
  - bin/setup
88
- - bin/stock-info
88
+ - bin/stock_info
89
89
  - lib/stock_info.rb
90
90
  - lib/stock_info/cli.rb
91
91
  - lib/stock_info/news.rb