stocks-info 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bd661bc86e35aa8de5c5e85b5b9a91b2bd68966
4
- data.tar.gz: 635da3287fe52735389fa1899328a61b87902569
3
+ metadata.gz: 4cca95d5cd9fda66f1db56e301c0a0a80b1c0510
4
+ data.tar.gz: 9370a8ee3bbb9ed795cde08b046180522bce9e5a
5
5
  SHA512:
6
- metadata.gz: 89c9f9a0011f154fbd691b14d6a6ea34aecfefd917e3ccc72f081e39689f22eb7c1ff7315910696ae34f2842853a4696761866e158e8d101151d8a01c455ec35
7
- data.tar.gz: f4dec80fed359d006e02bea8b5df776f255fead59404e5fb395f7d0ebe711e85cc187bd284191d1609189dfc1765f8a5a395d6d3e4c069b99b4f4b8583020945
6
+ metadata.gz: 2622f19af17d1dc51280199c35e68521133d0594321ac264852927fc8b920f53f386cbeb550bc74e192f3a4fa937b21364af58100ea369d0fa0192977cd4610a
7
+ data.tar.gz: 6e8883612533ec545e03b0d8793e11516ae7b43fff526fb81477e53bfb1cced76007d21f76f54469cc6358a2f5ea659d54c2788309b803e58623d3dbd2969fc5
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "stocks-info"
4
+ require_relative "../lib/stocks-info"
5
5
 
6
- StocksInfo::CLI.new.call
6
+ StocksInfo::CLI.new.start
@@ -4,5 +4,5 @@ require "open-uri"
4
4
  require_relative "./stocks-info/version"
5
5
  require_relative "./stocks-info/cli"
6
6
  require_relative "./stocks-info/ticker"
7
- require_relative "./stocks-info/indices"
8
7
  require_relative "./stocks-info/stocktwits"
8
+ require_relative "./stocks-info/scraper"
@@ -1,30 +1,41 @@
1
1
  class StocksInfo::CLI
2
- attr_accessor :info
3
2
 
4
- def call
3
+ def start
5
4
  show_indices
6
5
  show_trending
7
6
  menu
8
7
  end
9
8
 
10
9
  def show_indices
11
- StocksInfo::Indices.new.market_info
10
+ puts "Here is how the market is doing today"
11
+ {"S&P500": "%5EGSPC", "DOW JONES": "%5EDJI", "NASDAQ": "%5EIXIC"}.each do |name, ticker|
12
+ index = StocksInfo::Ticker.new(ticker)
13
+ StocksInfo::Scraper.scrape(index)
14
+ puts "#{name}: #{index.price}, #{index.price_change}"
15
+ end
12
16
  end
13
17
 
14
18
  def show_trending
15
- StocksInfo::Stocktwits.show_trending
19
+ message = "Trending on Stocktwits:"
20
+ StocksInfo::Scraper.scrape_trending
21
+ StocksInfo::Stocktwits.trending_tickers.each do |ticker|
22
+ message += " #{ticker}"
23
+ end
24
+ puts message
16
25
  end
17
26
 
18
27
  def menu
19
28
  puts "What ticker would you like info or price on?"
20
29
  input = nil
21
30
  while input != "exit"
22
- puts "Type ticker-news for latest news, ticker-price for price info, ticker-twits to open stocktwits page, or exit to exit."
31
+ puts "Type ticker-news for latest news, ticker-price for price info, ticker-twits to open stocktwits page, or exit to exit. Ex: aapl-price"
23
32
  input = gets.strip
24
- if input.end_with?("-news")
25
- show_news(input.gsub("-news", ""))
33
+ if !StocksInfo::Ticker.valid_ticker?("#{input.gsub("-news", "").gsub("-price", "")}")
34
+ puts "That is not a valid ticker."
35
+ elsif input.end_with?("-news")
36
+ show_news(StocksInfo::Ticker.new(input.gsub("-news", "")))
26
37
  elsif input.end_with?("-price")
27
- show_price(input.gsub("-price", ""))
38
+ show_price(StocksInfo::Ticker.new(input.gsub("-price", "")))
28
39
  elsif input.end_with?("-twits")
29
40
  open_twits(input.gsub("-twits", ""))
30
41
  elsif input == "exit"
@@ -36,16 +47,35 @@ class StocksInfo::CLI
36
47
  end
37
48
 
38
49
  def show_news(ticker)
39
- StocksInfo::Ticker.new(ticker).show_news
50
+ StocksInfo::Scraper.scrape(ticker)
51
+ puts "Latest News for #{ticker.name}:"
52
+ ticker.news.each_with_index do |title, index|
53
+ puts "#{index + 1}. #{title.text}"
54
+ ticker.links << title.attribute("href").value
55
+ end
56
+ puts "Do you want to view any of these articles? Type its number or else type no"
57
+ input = nil
58
+ while input != "no"
59
+ input= gets.strip
60
+ if input == "no"
61
+ puts "exiting to main menu"
62
+ elsif input.to_i <= ticker.links.length && input.to_i > 0 #strings will convert to 0
63
+ system("open https://finance.yahoo.com#{ticker.links[input.to_i - 1]}")
64
+ else puts "That is not a valid article."
65
+ end
66
+ end
67
+ ticker.links.clear
40
68
  end
41
69
 
42
70
  def show_price(ticker)
43
- StocksInfo::Ticker.new(ticker).show_price
71
+ StocksInfo::Scraper.scrape(ticker)
72
+ puts ticker.name
73
+ puts ticker.price
74
+ puts ticker.price_change
44
75
  end
45
76
 
46
77
  def open_twits(ticker)
47
- StocksInfo::Stocktwits.new(ticker).open_twits
78
+ system("open #{StocksInfo::Stocktwits.new(ticker).url}")
48
79
  end
49
80
 
50
-
51
81
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stocks-info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Chi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-08 00:00:00.000000000 Z
11
+ date: 2018-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -63,7 +63,8 @@ files:
63
63
  - lib/stocks-info.rb
64
64
  - lib/stocks-info/cli.rb
65
65
  homepage: http://rubygems.org/gems/stocks-info
66
- licenses: []
66
+ licenses:
67
+ - MIT
67
68
  metadata: {}
68
69
  post_install_message:
69
70
  rdoc_options: []