tech_news 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/tech-news +6 -0
- data/lib/tech_news.rb +11 -0
- data/lib/tech_news/article.rb +28 -0
- data/lib/tech_news/cli.rb +46 -0
- data/lib/tech_news/version.rb +3 -0
- data/spec.md +9 -0
- data/tech_news.gemspec +37 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b1121fe255c23bda7a35b013432e7d0c722b6ff9
|
4
|
+
data.tar.gz: 649baa559bdf07b310f1f555f17de0e31f5aa753
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2e9f5173b06513dd8fec56800aefaca42021271cc0625100e1e69f7f2392d687d8c3bfef6076d96ca88aec7e672baafa983155eb9d46005a03cfdc9e0fbd92fd
|
7
|
+
data.tar.gz: c8c7a9c3e81f45cbf4a8cf9cd53765dba66fa725166cc5a9907072ab9af3f737997a0f47801a6aa3808ac935bd8a576e4aba4a4e225d8aeb9f6b3fa9ac66fd15
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# TechNews
|
2
|
+
|
3
|
+
Welcome to TechNews! This Ruby Gem provides a CLI to view the latest technology-related articles on Google News.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'tech_news'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install tech_news
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Type the command below and follow the prompts on the screen.
|
24
|
+
|
25
|
+
$ ./bin/tech-news
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/'robinpahlman-117785'/tech_news.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "tech_news"
|
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
data/bin/tech-news
ADDED
data/lib/tech_news.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class TechNews::Article
|
2
|
+
|
3
|
+
attr_accessor :title, :url, :articles
|
4
|
+
|
5
|
+
def self.all
|
6
|
+
@@all = self.save
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.save #scrape_articles
|
10
|
+
articles = []
|
11
|
+
articles << self.scrape_google
|
12
|
+
articles.flatten!
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.scrape_google # go to Google Technology News, find and scrape articles, instantiate an article
|
16
|
+
data = []
|
17
|
+
doc = Nokogiri::HTML(open("https://news.google.com/news/headlines/section/topic/TECHNOLOGY?ned=us&hl=en"))
|
18
|
+
title_array = doc.css("a.nuEeue").select {|element| element['aria-level'] == "2"}
|
19
|
+
title_array.each do |element|
|
20
|
+
article = self.new
|
21
|
+
article.title = element.children.text
|
22
|
+
article.url = element.attributes['href'].value
|
23
|
+
data << article
|
24
|
+
end
|
25
|
+
data
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# CLI Controller
|
2
|
+
class TechNews::CLI
|
3
|
+
|
4
|
+
def call
|
5
|
+
list_articles
|
6
|
+
menu
|
7
|
+
goodbye
|
8
|
+
end
|
9
|
+
|
10
|
+
def list_articles
|
11
|
+
puts " "
|
12
|
+
puts "The Latest in Tech News:"
|
13
|
+
puts " "
|
14
|
+
@articles = TechNews::Article.all
|
15
|
+
@articles.each.with_index(1) do |article, i|
|
16
|
+
puts "#{i}. #{article.title}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def menu
|
21
|
+
input = nil
|
22
|
+
while input != "exit"
|
23
|
+
puts " "
|
24
|
+
puts "Enter the number of the article you'd like to read, type list to see the list of articles again, or type exit:"
|
25
|
+
puts " "
|
26
|
+
input = gets.strip.downcase
|
27
|
+
|
28
|
+
if input.to_i > 0
|
29
|
+
the_article = @articles[input.to_i - 1]
|
30
|
+
puts ""
|
31
|
+
`open #{the_article.url}`
|
32
|
+
puts "#{input}. #{the_article.title}"
|
33
|
+
# puts "#{the_article.url}"
|
34
|
+
puts " "
|
35
|
+
elsif input == "list"
|
36
|
+
list_articles
|
37
|
+
else
|
38
|
+
puts "Not sure what you want, type list or exit." unless input == "exit"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def goodbye
|
44
|
+
puts "Check in again for more tech articles!"
|
45
|
+
end
|
46
|
+
end
|
data/spec.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Specifications for the CLI Assessment
|
2
|
+
|
3
|
+
Specs:
|
4
|
+
- [x] Have a CLI for interfacing with the application
|
5
|
+
Set up CLI in lib/tech_news/cli.rb. TechNews::CLI.list_articles lists the articles, the #menu method asks for and handles user input, and the #goodbye method outputs a goodbye message when the user exits the program. These methods are encapsulated in the #call method, which in its turn is called by the executable file bin/tech-news to run the program.
|
6
|
+
- [x] Pull data from an external source
|
7
|
+
Scraped Google News Technology section with Nokogiri for tech-related articles, selecting individual articles' title and URL.
|
8
|
+
- [x] Implement both list and detail views
|
9
|
+
The CLI lists 20 articles by title from Google News, and then asks the user to select the number of the article they would like to read. Upon the user's selection, the CLI returns the selected article's title and URL.
|
data/tech_news.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tech_news/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tech_news"
|
8
|
+
spec.version = TechNews::VERSION
|
9
|
+
spec.authors = ["'Robin Pahlman'"]
|
10
|
+
spec.email = ["'robin.pahlman@gmail.com'"]
|
11
|
+
|
12
|
+
spec.summary = %q{"TechNews lists the latest tech articles on Google News".}
|
13
|
+
#spec.description = %q{TODO: Write a longer description or delete this line.}
|
14
|
+
spec.homepage = "https://github.com/aut0maat10/tech-news-cli-app"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
# if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
# else
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
# "public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "bin"
|
29
|
+
spec.executables = "tech-news"
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec"
|
35
|
+
spec.add_development_dependency "pry"
|
36
|
+
spec.add_dependency "nokogiri"
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tech_news
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "'Robin Pahlman'"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-05 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '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:
|
84
|
+
email:
|
85
|
+
- "'robin.pahlman@gmail.com'"
|
86
|
+
executables:
|
87
|
+
- tech-news
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- bin/tech-news
|
98
|
+
- lib/tech_news.rb
|
99
|
+
- lib/tech_news/article.rb
|
100
|
+
- lib/tech_news/cli.rb
|
101
|
+
- lib/tech_news/version.rb
|
102
|
+
- spec.md
|
103
|
+
- tech_news.gemspec
|
104
|
+
homepage: https://github.com/aut0maat10/tech-news-cli-app
|
105
|
+
licenses: []
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.6.13
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: '"TechNews lists the latest tech articles on Google News".'
|
127
|
+
test_files: []
|