npr_stories 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/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +30 -0
- data/Rakefile +6 -0
- data/bin/npr_stories +5 -0
- data/bin/setup +8 -0
- data/lib/npr_stories.rb +9 -0
- data/lib/npr_stories/cli.rb +73 -0
- data/lib/npr_stories/program.rb +17 -0
- data/lib/npr_stories/scraper.rb +33 -0
- data/lib/npr_stories/story.rb +25 -0
- data/lib/npr_stories/version.rb +3 -0
- data/npr_stories.gemspec +24 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5427d63869ae562d3f7e6236794fcf4179c62b42
|
4
|
+
data.tar.gz: a3d8fdcf7d8b4897ab1d56c1a258cc4109b0eff7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 66e7d3ee211dc90ea0916712c365a3b61286ed98b0b079c64cbbcd0f77c7e20ae1381d827d6c9a55bac205ca0945ea8771f0b179430ad0f148e21eb91eb06a3a
|
7
|
+
data.tar.gz: ec3ddd2af5ee7b067a8bd25d259390d106adc368aeed528beb5d57c6e97b493a616b520f5ba3a3d9f68eb5ddec5b9cdc5173d762f4a0223792f5de7f6904d239
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at tracetrace@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Tracy
|
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,30 @@
|
|
1
|
+
# NprStories
|
2
|
+
|
3
|
+
This gem allows you to access the NPR API and see the latest stories by radio program. If you're interested in a particular story, you can have it open up in the browser for you.
|
4
|
+
|
5
|
+
[Video walkthrough](https://www.youtube.com/watch?v=2RJbifcIaFc) and
|
6
|
+
[Project Blog Post](http://www.tracyctran.com/code/2016/03/21/npr-api-cli-gem-oo-assessment/)
|
7
|
+
|
8
|
+
## Installation - Publishing to RubyGems soon, but until then...
|
9
|
+
|
10
|
+
Clone this repo...
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
To run :
|
19
|
+
|
20
|
+
$ bin/npr_stories
|
21
|
+
|
22
|
+
## Contributing
|
23
|
+
|
24
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bacitracin/npr_stories.
|
25
|
+
|
26
|
+
|
27
|
+
## License
|
28
|
+
|
29
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
30
|
+
|
data/Rakefile
ADDED
data/bin/npr_stories
ADDED
data/bin/setup
ADDED
data/lib/npr_stories.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'pry'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
require_relative "./npr_stories/version"
|
6
|
+
require_relative "./npr_stories/cli"
|
7
|
+
require_relative "./npr_stories/program"
|
8
|
+
require_relative "./npr_stories/story"
|
9
|
+
require_relative "./npr_stories/scraper"
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class NprStories::CLI
|
2
|
+
|
3
|
+
def call
|
4
|
+
puts "Welcome to NPR!"
|
5
|
+
NprStories::Scraper.new.scrape_programs
|
6
|
+
choose_program
|
7
|
+
end
|
8
|
+
|
9
|
+
def list_programs
|
10
|
+
puts "Information on the following NPR programs is available:"
|
11
|
+
puts "----------------------------------------------------------------"
|
12
|
+
NprStories::Program.all.each_with_index do |program, index|
|
13
|
+
puts "#{index + 1}. #{program.program_title}"
|
14
|
+
end
|
15
|
+
puts "----------------------------------------------------------------"
|
16
|
+
end
|
17
|
+
|
18
|
+
def choose_program
|
19
|
+
program_choice = nil
|
20
|
+
until program_choice == 'exit'
|
21
|
+
list_programs
|
22
|
+
puts "Select a program by number to see recent stories or type 'exit' to leave program"
|
23
|
+
program_choice = gets.strip.downcase
|
24
|
+
|
25
|
+
if program_choice == 'exit'
|
26
|
+
puts "Now exiting the program. See you later!"
|
27
|
+
|
28
|
+
elsif program_choice.to_i <= NprStories::Program.all.size
|
29
|
+
program = NprStories::Program.all[program_choice.to_i - 1]
|
30
|
+
@program_stories = NprStories::Scraper.new.scrape_stories(program) # create a new scraper & pull the stories for that program
|
31
|
+
puts "Here are the recent stories from #{program.program_title}:"
|
32
|
+
puts "----------------------------------------------------------------"
|
33
|
+
@program_stories.each_with_index do |story, index|
|
34
|
+
puts "#{index + 1}. #{story.story_title}"
|
35
|
+
end #each_with_index loop
|
36
|
+
puts "----------------------------------------------------------------"
|
37
|
+
choose_story
|
38
|
+
else
|
39
|
+
puts "Sorry I didn't get that. Please try again."
|
40
|
+
end #close if
|
41
|
+
end # close until loop
|
42
|
+
end
|
43
|
+
|
44
|
+
def choose_story
|
45
|
+
story_choice = nil
|
46
|
+
until story_choice == 'exit'
|
47
|
+
puts "Choose a story to see more details or go back to main menu with 'exit'"
|
48
|
+
story_choice = gets.strip.downcase
|
49
|
+
if story_choice == 'exit'
|
50
|
+
puts "Now exiting back to the main menu..."
|
51
|
+
|
52
|
+
elsif story_choice.to_i <= @program_stories.size
|
53
|
+
story = @program_stories[story_choice.to_i - 1]
|
54
|
+
puts "#{story_choice}. #{story.story_title}"
|
55
|
+
puts "Program: #{story.program_title}"
|
56
|
+
puts "Date: #{story.story_date}"
|
57
|
+
puts "Teaser: #{story.teaser}"
|
58
|
+
puts "Url: #{story.story_url}"
|
59
|
+
puts "----------------------------------------------------------------"
|
60
|
+
|
61
|
+
puts "Would you like to read this story in the browser?"
|
62
|
+
answer = gets.strip.downcase
|
63
|
+
if answer.include?('y')
|
64
|
+
system('open', "#{story.story_url}")
|
65
|
+
end
|
66
|
+
story_choice = nil
|
67
|
+
else
|
68
|
+
puts "Sorry please try again."
|
69
|
+
end # if loop
|
70
|
+
end # until
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class NprStories::Program
|
2
|
+
|
3
|
+
attr_accessor :program_title, :search_id, :additional_info, :stories
|
4
|
+
|
5
|
+
@@programs = [] #all programs
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@stories = [] #all stories for this program
|
9
|
+
@@programs << self
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.all
|
13
|
+
@@programs
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class NprStories::Scraper
|
2
|
+
|
3
|
+
# apiKey is not connected to to my account
|
4
|
+
BASE_URL = 'http://api.npr.org/query?apiKey=MDIyODk1NDk0MDE0NTYxNzg5NTdkYjVhZA000&id='
|
5
|
+
|
6
|
+
#scrape_programs - head over to NPR programs page, scrape data & instantiate new Program objects
|
7
|
+
#scrape stories - grabs/creates the stories for a particular programs
|
8
|
+
|
9
|
+
def scrape_programs
|
10
|
+
doc = Nokogiri::XML(open('http://api.npr.org/list?id=3004'))
|
11
|
+
programs = doc.xpath('*//item')
|
12
|
+
programs.each do |program|
|
13
|
+
new_program = NprStories::Program.new
|
14
|
+
new_program.program_title = program.search('title').text
|
15
|
+
new_program.search_id = program.attributes["id"].value.to_i
|
16
|
+
new_program.additional_info = program.search('additionalInfo').text
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def scrape_stories(program) #returns a list of story hashes for the show entered
|
21
|
+
api_query = "#{BASE_URL + program.search_id.to_s}"
|
22
|
+
doc = Nokogiri::XML(open(api_query))
|
23
|
+
@program_stories = doc.xpath('*//story') # @progam_stories is a Nokogiri::XML::NodeSet of stories
|
24
|
+
@program_stories.each do |nokogiri_story|
|
25
|
+
new_story = NprStories::Story.new
|
26
|
+
new_story.set_attributes_from_web(nokogiri_story)
|
27
|
+
program.stories << new_story # add new story to program's stories array
|
28
|
+
end
|
29
|
+
program.stories
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class NprStories::Story
|
2
|
+
|
3
|
+
attr_accessor :story_title, :program_title, :story_date, :teaser, :story_url, :program
|
4
|
+
@@stories = [] # All stories, all programs
|
5
|
+
|
6
|
+
def save
|
7
|
+
@@stories << self
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.all
|
11
|
+
@@stories
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_attributes_from_web(nokogiri_story)#nokogiri story object node?? thing
|
15
|
+
self.story_title = nokogiri_story.search('title').first.text
|
16
|
+
# new_story.program = ##### add in stoy's relationship to program object
|
17
|
+
self.program_title = nokogiri_story.search('program')[0].text
|
18
|
+
self.story_date = nokogiri_story.search('storyDate')[0].text
|
19
|
+
self.teaser = nokogiri_story.search('teaser')[0].text
|
20
|
+
self.story_url = nokogiri_story.search('link')[0].text
|
21
|
+
self.save
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
end
|
data/npr_stories.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'npr_stories/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "npr_stories"
|
8
|
+
spec.version = NprStories::VERSION
|
9
|
+
spec.authors = ["Tracy"]
|
10
|
+
spec.email = ["tracetrace@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Read recent NPR stories form the command line}
|
13
|
+
spec.homepage = "https://github.com/bacitracin/npr-stories-gem"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: npr_stories
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tracy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-16 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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
|
+
description:
|
56
|
+
email:
|
57
|
+
- tracetrace@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/npr_stories
|
71
|
+
- bin/setup
|
72
|
+
- lib/npr_stories.rb
|
73
|
+
- lib/npr_stories/cli.rb
|
74
|
+
- lib/npr_stories/program.rb
|
75
|
+
- lib/npr_stories/scraper.rb
|
76
|
+
- lib/npr_stories/story.rb
|
77
|
+
- lib/npr_stories/version.rb
|
78
|
+
- npr_stories.gemspec
|
79
|
+
homepage: https://github.com/bacitracin/npr-stories-gem
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.5.1
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Read recent NPR stories form the command line
|
103
|
+
test_files: []
|