stockcli_app 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 152df1358345531febb0c71478003ff787b1ba04ac1f950e045481125b0c15fc
4
+ data.tar.gz: baf18f424f1911c19f4e94eae29956cb448e7c8d2ae71ed7c9474f91181c2918
5
+ SHA512:
6
+ metadata.gz: b36022c6d6c000506146444587692204e7f62882e38cfa7319fb45653d73fa68130b06c8e451531c2ae3e0fed6bd1ace4a3c74a01066cf27a736e1c1f3e56625
7
+ data.tar.gz: bf9c28381216a5295870a822d27ec25bea1d8edb52ce4596ca1f000a35dfe56a6d341dcdb886c7de4a513450977858583cf6e98e6e7242401663a1825efdcf4c
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in stockcli_app.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 'Anu Khambete'
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,49 @@
1
+ # StockcliApp
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/stockcli_app`. 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
+ The Stock CLI application provides the user a menu with 4 options :
8
+ (a) View a list of stocks
9
+ This provides the user with a list of companies and their stock price with the option
10
+ of learning more about a particular stock by entering the correct company symbol.
11
+
12
+ (b) View a list of companies in descending order of market cap
13
+ (c) View a list of stocks in descending order of volatility
14
+ (d) Quit the program
15
+
16
+ sample text
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'stockcli_app'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install stockcli_app
32
+
33
+ ## Usage
34
+
35
+ TODO: Write usage instructions here
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ 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).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/'anukhambete'/stockcli_app.
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "stockcli_app"
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/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/bin/stockcli_app ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require './lib/stockcli_app'
3
+
4
+ StockcliApp::CLI.new.call
@@ -0,0 +1,6 @@
1
+ require_relative './stockcli_app/version'
2
+ require_relative './stockcli_app/cli'
3
+
4
+ module StockcliApp
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,119 @@
1
+ #require_relative "../stockcli_app/scraper.rb"
2
+ require_relative "../stockcli_app/stock.rb"
3
+ require_relative "../stockcli_app/scraper.rb"
4
+ require 'nokogiri'
5
+ require 'pry'
6
+
7
+
8
+ class StockcliApp::CLI
9
+
10
+ # The cli should display 2 options List and quit and accept a valid input
11
+ # if list then display the list of stocks and symbols --> create method called display_list
12
+ # the display_list method should display the stocks and ask the user to enter a valid symbol
13
+ # the display_list method should use the @@all array from the Stock class to display the list of stocks
14
+ # the create_stocks method should us the scraper and stock classes to create instances of stocks
15
+ # The display_additional_info method adds information about the stock that is available through the stock url
16
+ # like index, PE ratio and eps and the output should include basic information about the stock (from)
17
+ # the main web page as well as the information scraped from the stock url
18
+ #
19
+
20
+ def create_stocks
21
+ outer_array = StockcliApp::Scraper.scrape_screener
22
+ StockcliApp::Stock.create_from_scraper_array(outer_array)
23
+ end
24
+
25
+
26
+ def display_list
27
+ puts " "
28
+ #binding.pry
29
+ StockcliApp::Stock.all.each do |stock|
30
+ puts stock.srno.ljust(5) + stock.symbol.ljust(10) + stock.name.ljust(25) + stock.price.rjust(5)
31
+ end
32
+ puts " "
33
+ end
34
+
35
+ def display_additional_info(stock_symbol)
36
+ stock = StockcliApp::Stock.all.find {|stock| stock.symbol == stock_symbol}
37
+ info = StockcliApp::Scraper.scrape_stock_info("https://finviz.com/" + stock.url) #Scraper.scrape_stock_info(url)
38
+ stock.add_stock_info(info)
39
+ puts "#{stock.name} belongs to the #{stock.sector} sector and has a marketcap of #{stock.mktcap.gsub("B"," Billion")}"
40
+ puts " "
41
+ puts "The major index/indices that include(s) it is/are #{stock.index.gsub("DJIA ","DJIA and ")}"
42
+ puts " "
43
+ puts "The Earnings per share is #{stock.eps}"
44
+ puts " "
45
+ end
46
+
47
+ def input_for_additional_info
48
+ puts "Enter a valid symbol for more information or enter 'quit' to return to the main menu"
49
+ puts " "
50
+ valid_symbols = StockcliApp::Stock.all.collect {|stock| stock.symbol}
51
+ input_symbol = gets.strip
52
+ if valid_symbols.include? input_symbol.upcase
53
+ display_additional_info(input_symbol.upcase)
54
+ elsif input_symbol == "quit"
55
+ puts "You are returning to the main menu"
56
+ puts " "
57
+ else
58
+ input_for_additional_info
59
+ end
60
+ end
61
+
62
+ def display_by_market_cap
63
+ array = []
64
+ array = StockcliApp::Stock.all.sort_by {|stock| stock.mktcap}.reverse
65
+ array.each {|stock| puts stock.name.ljust(25) + stock.mktcap.gsub("B", " Billion").rjust(1)}
66
+ puts " "
67
+ end
68
+
69
+ def display_by_vol
70
+ array = []
71
+ array = StockcliApp::Stock.all.sort_by {|stock| stock.change.gsub("%","").gsub("-","").to_f}.reverse
72
+ array.each {|stock| puts stock.name.ljust(25) + stock.change.rjust(2)}
73
+ puts " "
74
+ end
75
+
76
+ # The call method should
77
+ # (1) Main menu list options : (a) List of stocks (b) Top companies by mkt cap (c) Most volatile stock (d) quit
78
+ # (a) If the user picks a stock from the list a method to display additional information
79
+ # about the stock should be called and then go back to the main menu
80
+ # The symbol entered should be valid?
81
+ # (2) Call the appropriate method after the user makes their choice
82
+ # (3) Print an error message if the option is invalid and list the options again
83
+
84
+
85
+
86
+ def call
87
+ create_stocks unless !StockcliApp::Stock.all.empty?
88
+
89
+ puts "(a) To view the list of stocks enter --- list"
90
+ puts "(b) To view the list of companies in desc order of Market cap enter --- mkt"
91
+ puts "(c) To view the list of stocks in desc order of volatility enter --- vol"
92
+ puts "(b) To exit the program enter --- 'quit'"
93
+
94
+ input_1 = gets.strip
95
+ if["list", "mkt", "vol", "quit"].include? input_1.downcase
96
+ if input_1.downcase == "list"
97
+ display_list
98
+ input_for_additional_info
99
+ call
100
+
101
+ elsif input_1.downcase == "mkt"
102
+ display_by_market_cap
103
+ call
104
+
105
+ elsif input_1.downcase == "vol"
106
+ display_by_vol
107
+ call
108
+
109
+ elsif input_1.downcase == "quit"
110
+ puts "You have chosen to exit the app"
111
+ end
112
+
113
+ else
114
+ puts "Please enter a valid option"
115
+ call
116
+ end
117
+ end
118
+
119
+ end
@@ -0,0 +1,53 @@
1
+ require 'open-uri'
2
+ require 'pry'
3
+ require 'nokogiri'
4
+
5
+ # The Scraper class should have two methods
6
+ # The first method should be used to scrape the name, symbol, market cap
7
+ # The first method should return an array with arrays for each stock within it :
8
+ # This should be information collected from the main webpage about the 8 large companies
9
+ # url etc. from the main page for all the stocks
10
+ # The second method should scrape information about the individual stock
11
+ # The second method should scrape the EPS P/E ratio and the Index
12
+
13
+ class StockcliApp::Scraper
14
+
15
+ finviz = Nokogiri::HTML(open("https://finviz.com/screener.ashx?v=111&f=cap_mega,exch_nasd"))
16
+
17
+ def self.scrape_screener
18
+ array_main = []
19
+ finviz = Nokogiri::HTML(open("https://finviz.com/screener.ashx?v=111&f=cap_mega,exch_nasd"))
20
+ fin = finviz.css("div#screener-content").css("td").css("tr[valign=top]")
21
+
22
+ fin.each do |f|
23
+ temp = []
24
+
25
+ num = f.css("td")[0].text
26
+ symbol = f.css("td")[1].text
27
+ name = f.css("td")[2].text
28
+ url = f.css("td")[1].css("a").attribute("href").value
29
+
30
+ price = f.css("td")[8].text
31
+ mktcap = f.css("td")[6].text
32
+ sector = f.css("td")[3].text
33
+ change = f.css("td")[9].text
34
+
35
+ temp = [num, symbol, name, url, price, mktcap, sector, change]
36
+ array_main << temp
37
+ end
38
+ array_main
39
+ end
40
+
41
+ def self.scrape_stock_info(url)
42
+ stock_webpage = Nokogiri::HTML(open(url))
43
+ stock_addinfo_array = []
44
+ stock = stock_webpage.css("table.snapshot-table2 tr")
45
+ index = stock.css("td")[1].text
46
+ peratio = stock.css("td")[3].text
47
+ eps = stock.css("td")[5].text
48
+ stock_addinfo_array = [index, peratio, eps]
49
+ end
50
+
51
+
52
+
53
+ end
@@ -0,0 +1,43 @@
1
+ class StockcliApp::Stock
2
+
3
+ attr_accessor :srno, :name, :symbol, :url, :price, :mktcap, :sector, :index, :peratio, :eps, :change
4
+
5
+ @@all = []
6
+
7
+ # The instances of stocks should be initialized with an array that includes information that was scraped
8
+ # using the scraper class
9
+ # The initialized stock should contain information about the Sr no, name, symbol, url and marketcap
10
+
11
+ def initialize(array)
12
+ stock_array = array
13
+ @srno = stock_array[0]
14
+ @symbol = stock_array[1]
15
+ @name = stock_array[2]
16
+ @url = stock_array[3]
17
+ @price = stock_array[4]
18
+ @mktcap = stock_array[5]
19
+ @sector = stock_array[6]
20
+ @change = stock_array[7]
21
+ @@all << self
22
+ end
23
+
24
+ def self.create_from_scraper_array(outer_array)
25
+ outer_array.each do |inner_array|
26
+ stock = StockcliApp::Stock.new(inner_array)
27
+ end
28
+ end
29
+
30
+
31
+ def self.all
32
+ @@all
33
+ end
34
+
35
+ def add_stock_info(info)
36
+ array = info
37
+ @index = array[0]
38
+ @peratio = array[1]
39
+ @eps = array[2]
40
+ end
41
+
42
+
43
+ end
@@ -0,0 +1,3 @@
1
+ module StockcliApp
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,37 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "stockcli_app/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "stockcli_app"
8
+ spec.version = StockcliApp::VERSION
9
+ spec.authors = ["'Anu Khambete'"]
10
+ spec.email = ["'anukhambete@gmail.com'"]
11
+
12
+ spec.summary = %q{Stock screener CLI application.}
13
+ spec.description = %q{Refer to README.md.}
14
+ spec.homepage = "https://finviz.com/"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+ #else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ #end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stockcli_app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "'Anu Khambete'"
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-12 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
+ description: Refer to README.md.
42
+ email:
43
+ - "'anukhambete@gmail.com'"
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - bin/stockcli_app
56
+ - lib/stockcli_app.rb
57
+ - lib/stockcli_app/cli.rb
58
+ - lib/stockcli_app/scraper.rb
59
+ - lib/stockcli_app/stock.rb
60
+ - lib/stockcli_app/version.rb
61
+ - stockcli_app.gemspec
62
+ homepage: https://finviz.com/
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.7.7
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Stock screener CLI application.
86
+ test_files: []