stock_scraper 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
+ SHA1:
3
+ metadata.gz: b5849b13142ef03ded2328928971d07cc40f6ce7
4
+ data.tar.gz: 580f159700e2531850131fa9e91b6b9eb7eb1279
5
+ SHA512:
6
+ metadata.gz: 88a70deb47f06d8c42108b064ff7f8df858556c904c14da8aeef950984bdd32d5f66a8ca41e19fe2f43fd229f3eadf984a7b3a60efcace73d04636a004f3dfcf
7
+ data.tar.gz: 56074dfb1227a65bc0f2d2304c4e58ea54ece5f961439036d464c38c69a93526a610874cf0a60c893358dd5781fd9eab111993d49362cb0d434aee61696f926c
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,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.7
5
+ before_install: gem install bundler -v 1.16.1
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 stock_scraper.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ stock_scraper (0.1.0)
5
+ nokogiri
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ method_source (0.9.0)
13
+ nokogiri (1.5.6)
14
+ pry (0.11.3)
15
+ coderay (~> 1.1.0)
16
+ method_source (~> 0.9.0)
17
+ rake (10.4.2)
18
+ rspec (3.7.0)
19
+ rspec-core (~> 3.7.0)
20
+ rspec-expectations (~> 3.7.0)
21
+ rspec-mocks (~> 3.7.0)
22
+ rspec-core (3.7.1)
23
+ rspec-support (~> 3.7.0)
24
+ rspec-expectations (3.7.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.7.0)
27
+ rspec-mocks (3.7.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.7.0)
30
+ rspec-support (3.7.0)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 1.16)
37
+ pry
38
+ rake (~> 10.0)
39
+ rspec (~> 3.0)
40
+ stock_scraper!
41
+
42
+ BUNDLED WITH
43
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 TODO: Write your name
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/Notes.md ADDED
@@ -0,0 +1,32 @@
1
+ How to Build a CLI gem
2
+
3
+ 1. Plan your gem, imagine your interface
4
+ 2. Start with the project structure - google
5
+ 3. Start with the entry point - the file run
6
+ 4. Force that to build the CLI interface
7
+ 5. Stub out the interface
8
+ 6. Start making things real
9
+ 7. Discover objects
10
+ 8. Program
11
+
12
+ - A command line interface for scraping stocks from Yahoo! Finance
13
+
14
+ User types in stock_scraper
15
+
16
+ Show a list of stocks and values
17
+
18
+ 1. TSLA Tesla, Inc. - Last Price: 361.60 - Market Time: 1:21PM EDT
19
+
20
+ Which stock would you like to learn more about?
21
+
22
+ User types in "1" and gets the associated stock Information
23
+
24
+ Class construction of stock and its attributes...
25
+ What is a stock?
26
+ 1. A stock has an abbreviated symbol
27
+ 2. A stock has a name
28
+ 3. A stock has a last price
29
+
30
+ What is a price?
31
+ 1. A stock price has a market time
32
+ 2. A stock price has a change increment value
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # StockScraper
2
+
3
+ This Ruby Gem provides a CLI to view the trending stocks from Yahoo! Finance.
4
+ The information called upon is provided in real time.
5
+
6
+
7
+ ## Installation
8
+
9
+ $ gem install stock_scraper
10
+
11
+ ## Usage
12
+
13
+ Type in StockScraper and follow the on screen prompts.
14
+
15
+ ## Development
16
+
17
+ 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.
18
+
19
+ 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).
20
+
21
+ ## Contributing
22
+
23
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/stock_scraper.
24
+
25
+ ## License
26
+
27
+ 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,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 "stock_scraper"
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/stock_scraper ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # require './lib/stock_scraper'
4
+ require "bundler/setup"
5
+ require "stock_scraper"
6
+
7
+ StockScraper::CLI.new.call
@@ -0,0 +1,7 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'pry'
4
+
5
+ require_relative './stock_scraper/version'
6
+ require_relative './stock_scraper/cli'
7
+ require_relative './stock_scraper/stock'
@@ -0,0 +1,50 @@
1
+
2
+ class StockScraper::CLI
3
+
4
+ def call
5
+ list_stocks
6
+ menu
7
+ goodbye
8
+ end
9
+
10
+ def list_stocks
11
+ puts "Today's popular trending stocks are:"
12
+ update_stocks
13
+ @stocks.each.with_index(1) do |stock, i|
14
+ puts "#{i}. #{stock.name}"
15
+ end
16
+ end
17
+
18
+ def update_stocks
19
+ @stocks = StockScraper::Stock.scrape_yahoo
20
+ end
21
+
22
+ def menu
23
+ input = nil
24
+ while input != "exit"
25
+ puts "Enter the number of the stock you would like more information on or type list to see more stocks or type exit"
26
+ input = gets.strip.downcase
27
+ if input.to_i > 0 && input.to_i - 1 < @stocks.length
28
+ update_stocks
29
+ the_stock = @stocks[input.to_i - 1]
30
+ puts ""
31
+ puts "Stock Name: #{the_stock.name} - Symbol: #{the_stock.symbol}"
32
+ puts "Last Price: $#{the_stock.last_price} - Market Time: #{the_stock.market_time} - Change Percent: #{the_stock.change_percent}"
33
+ puts ""
34
+ elsif input == "list"
35
+ list_stocks
36
+ elsif input == "exit"
37
+ puts "Happy trading!"
38
+ elsif input.to_i >= @stocks.length - 1
39
+ puts "Not sure what stock you are requesting, type list or exit"
40
+ else
41
+ puts "you have found a vulnerability; hacking into the main frame!"
42
+ end
43
+ end
44
+ end
45
+
46
+ def goodbye
47
+ puts "See you tomorrow for more stock information"
48
+ end
49
+
50
+ end
@@ -0,0 +1,18 @@
1
+ class StockScraper::Stock
2
+ attr_accessor :symbol, :name, :last_price, :market_time, :change_percent
3
+
4
+ def self.scrape_yahoo
5
+ doc = Nokogiri::HTML(open("https://finance.yahoo.com/trending-tickers/"))
6
+ scraped_stocks = []
7
+ doc.css("tbody tr").each do |column|
8
+ stock_obj = self.new
9
+ stock_obj.symbol = column.css("td.data-col0")[0].children[0].values[2]
10
+ stock_obj.name = column.css("td.data-col0")[0].children[0].values[1]
11
+ stock_obj.last_price = column.css("td.data-col2")[0].children.inner_text
12
+ stock_obj.market_time = column.css("td.data-col3")[0].children.inner_text
13
+ stock_obj.change_percent = column.css("td.data-col5")[0].children.inner_text
14
+ scraped_stocks << stock_obj
15
+ end
16
+ scraped_stocks
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module StockScraper
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'pry'
4
+ require_relative './stock_scraper/version'
5
+ require_relative './stock_scraper/cli'
6
+ require_relative './stock_scraper/stock'
7
+
8
+
9
+ module StockScraper
10
+ # Your code goes here...
11
+ end
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "stock_scraper/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "stock_scraper"
8
+ spec.version = StockScraper::VERSION
9
+ spec.authors = ["hirokikato"]
10
+ spec.email = ["hirokikato1@gmail.com"]
11
+
12
+ spec.summary = %q{Scraper for stock data from Yahoo finance webpage}
13
+ spec.description = %q{Scrapes data and instantiates dynamic objects with information on stocks}
14
+ spec.homepage = "https://github.com/hkato4188/stock_scraper"
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"] = 'http://mygemserver.com'
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+ # review with tech coach
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(test|spec|features)/})
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.16"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ spec.add_development_dependency "pry", "~> 0"
38
+ spec.add_dependency "nokogiri", "~> 0"
39
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stock_scraper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - hirokikato
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-14 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
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Scrapes data and instantiates dynamic objects with information on stocks
84
+ email:
85
+ - hirokikato1@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - Notes.md
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - bin/stock_scraper
102
+ - config/environment.rb
103
+ - lib/stock_scraper.rb
104
+ - lib/stock_scraper/cli.rb
105
+ - lib/stock_scraper/stock.rb
106
+ - lib/stock_scraper/version.rb
107
+ - stock_scraper.gemspec
108
+ homepage: https://github.com/hkato4188/stock_scraper
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.5.2.3
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Scraper for stock data from Yahoo finance webpage
132
+ test_files: []