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 +4 -4
- data/Gemfile +2 -3
- data/Gemfile.lock +1 -1
- data/NOTES.md +0 -16
- data/Rakefile +2 -2
- data/bin/console +3 -3
- data/bin/{stock-info → stock_info} +1 -1
- data/lib/stock_info/cli.rb +33 -32
- data/lib/stock_info/news.rb +41 -39
- data/lib/stock_info/stock.rb +55 -49
- data/lib/stock_info/version.rb +1 -1
- data/lib/stock_info.rb +5 -5
- data/stock_info.gemspec +16 -17
- metadata +9 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 476a3a1026da6b7478795475012c06dd0b30c9f0
|
|
4
|
+
data.tar.gz: f7d79d9b713ae7b4b0ac0485e988ba0da206b2b3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e659a227c1c0dbf1569ebf2173d128e97378afe83446161f74b9d9915122b8171b20f2225174fd8add8467414a86f95e5c1310310d30962d6953174ab3db705c
|
|
7
|
+
data.tar.gz: 4061642252a6bd222ada67d27b7f0716a9366a82b6911469ec257fe7b008f801307d19f1390ee382103f9380d77eeb389d9b70b51329fb7337b3f13e31508bc2
|
data/Gemfile
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
source 'https://rubygems.org'
|
|
1
2
|
|
|
2
|
-
|
|
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
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
|
|
2
|
-
task :
|
|
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
|
|
4
|
-
require
|
|
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
|
|
13
|
+
require 'irb'
|
|
14
14
|
IRB.start(__FILE__)
|
data/lib/stock_info/cli.rb
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
# Our CLI controller
|
|
2
2
|
class StockInfo::CLI
|
|
3
|
-
|
|
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
|
-
|
|
6
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
data/lib/stock_info/news.rb
CHANGED
|
@@ -1,43 +1,45 @@
|
|
|
1
|
-
class StockInfo::
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
data/lib/stock_info/stock.rb
CHANGED
|
@@ -1,53 +1,59 @@
|
|
|
1
1
|
class StockInfo::Stock
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
data/lib/stock_info/version.rb
CHANGED
data/lib/stock_info.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
require_relative
|
|
2
|
-
require_relative
|
|
3
|
-
require_relative
|
|
4
|
-
require_relative
|
|
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
|
|
3
|
+
require 'stock_info/version'
|
|
5
4
|
|
|
6
5
|
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name =
|
|
6
|
+
spec.name = 'stock_info'
|
|
8
7
|
spec.version = StockInfo::VERSION
|
|
9
|
-
spec.authors = [
|
|
10
|
-
spec.email = [
|
|
8
|
+
spec.authors = ['Tom Kunkel']
|
|
9
|
+
spec.email = ['36858744+decentralvision@users.noreply.github.com']
|
|
11
10
|
|
|
12
|
-
spec.summary =
|
|
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 =
|
|
15
|
-
spec.license =
|
|
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(
|
|
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
|
|
23
|
-
spec.executables
|
|
24
|
-
spec.require_paths = [
|
|
21
|
+
spec.bindir = 'bin'
|
|
22
|
+
spec.executables << 'stock_info'
|
|
23
|
+
spec.require_paths = ['lib']
|
|
25
24
|
|
|
26
|
-
spec.add_development_dependency
|
|
27
|
-
spec.add_development_dependency
|
|
28
|
-
spec.add_development_dependency
|
|
29
|
-
spec.add_dependency
|
|
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.
|
|
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:
|
|
28
|
+
name: pry
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
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: '
|
|
40
|
+
version: '0.12'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
42
|
+
name: rake
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
45
|
- - "~>"
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '0
|
|
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
|
|
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
|
-
-
|
|
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/
|
|
88
|
+
- bin/stock_info
|
|
89
89
|
- lib/stock_info.rb
|
|
90
90
|
- lib/stock_info/cli.rb
|
|
91
91
|
- lib/stock_info/news.rb
|