wiki_on_this_day 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 844454951715ec45de43b8e4a0977cfbe3b67b32
4
+ data.tar.gz: 0eab23e97c0132e1978a92ddcabd3b191afe8128
5
+ SHA512:
6
+ metadata.gz: d456d4785ed2e1d6fc15001f0a5154ecb7a7d92b14e5a3c8f08497044e250264f2b8b8d3de016375db837dbe0bbf11814ddee0a0183e7d30a08d58cdd462246a
7
+ data.tar.gz: 2b7db444a5f406eaa7eb0ee94e9f780014858aedc53eaa87c3d7e5911bc2bce338f765a74f00d4c4176620f1a8f4c9c21c561097107726ea8d56e1d0abd1c345
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "examples/now-playing-cli-gem"]
2
+ path = examples/now-playing-cli-gem
3
+ url = git@github.com:learn-co-curriculum/now-playing-cli-gem.git
data/.learn ADDED
@@ -0,0 +1,8 @@
1
+ tags:
2
+ - cli
3
+ - gem
4
+ - oo
5
+ languages:
6
+ - ruby
7
+ resources:
8
+ live_assessment: true
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify dependencies in wiki_on_this_day.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ wiki_on_this_day (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.3.8)
10
+ coderay (1.1.0)
11
+ crack (0.4.2)
12
+ safe_yaml (~> 1.0.0)
13
+ diff-lcs (1.2.5)
14
+ hashdiff (0.2.3)
15
+ method_source (0.8.2)
16
+ mini_portile (0.6.2)
17
+ nokogiri (1.6.6.2)
18
+ mini_portile (~> 0.6.0)
19
+ pry (0.10.3)
20
+ coderay (~> 1.1.0)
21
+ method_source (~> 0.8.1)
22
+ slop (~> 3.4)
23
+ rake (10.4.2)
24
+ rspec (3.4.0)
25
+ rspec-core (~> 3.4.0)
26
+ rspec-expectations (~> 3.4.0)
27
+ rspec-mocks (~> 3.4.0)
28
+ rspec-core (3.4.0)
29
+ rspec-support (~> 3.4.0)
30
+ rspec-expectations (3.4.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.4.0)
33
+ rspec-mocks (3.4.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.4.0)
36
+ rspec-support (3.4.0)
37
+ safe_yaml (1.0.4)
38
+ slop (3.6.0)
39
+ vcr (3.0.0)
40
+ webmock (1.22.3)
41
+ addressable (>= 2.3.6)
42
+ crack (>= 0.3.2)
43
+ hashdiff
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ bundler (~> 1.10)
50
+ nokogiri (~> 1.6)
51
+ pry (~> 0.10)
52
+ rake (~> 10.0)
53
+ rspec (~> 3.0)
54
+ vcr (~> 3.0)
55
+ webmock (~> 1.0)
56
+ wiki_on_this_day!
57
+
58
+ BUNDLED WITH
59
+ 1.10.6
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Edward John Karabinus
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # wiki_on_this_day
2
+
3
+ This gem scrapes the English-language Wikipedia homepage (at https://en.wikipedia.org) to obtain the various article abstracts from the "On This Day" historical section of the homepage. To install, head over to RubyGems.org to obtain the latest version of this gem (under the name "wiki_on_this_day"). Upon gem installation, type wiki_on_this_day to access the command-line interface with the scraped information. After viewing the list of daily abstracts, you may request more information about any particular event by typing its year (Typing anything else will quit the program; restart and try again in this case.)
4
+
5
+ Do not hesitate to fork this repository and improve wiki_on_this_day; I welcome any pull requests with bug fixes, display improvements, or more features.
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,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'wiki_on_this_day'
5
+
6
+ # Add fixtures and/or initialization code here to aid in gem development.
7
+
8
+ require 'irb'
9
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'wiki_on_this_day'
4
+
5
+ WikiOnThisDay::CLI.new
@@ -0,0 +1,11 @@
1
+ class WikiOnThisDay::Scraper::Article < WikiOnThisDay::Scraper
2
+
3
+ def initialize(link_url)
4
+ super(link_url)
5
+ end
6
+
7
+ def article_abstract
8
+ self.html_doc.css('div#mw-content-text > p').first.text
9
+ end
10
+
11
+ end
@@ -0,0 +1,24 @@
1
+ class WikiOnThisDay::CLI
2
+
3
+ attr_reader :todays_page
4
+
5
+ def initialize
6
+ @todays_page = WikiOnThisDay::Scraper::Homepage.new
7
+ print_controller = WikiOnThisDay::Printer.new(self.todays_page.html_doc, self.todays_page.on_this_day)
8
+ print_controller.print
9
+ print "To learn more about one of these events, enter the year as displayed above. To exit, enter anything else: "
10
+ input = gets.strip
11
+ more_information(input)
12
+ end
13
+
14
+ def more_information(year)
15
+ self.todays_page.on_this_day.each do |key, value|
16
+ if value[:year] == year
17
+ puts ''
18
+ puts WikiOnThisDay::Scraper::Article.new(value[:link_url]).article_abstract
19
+ puts ''
20
+ end
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,18 @@
1
+ class WikiOnThisDay::Scraper::Homepage < WikiOnThisDay::Scraper
2
+
3
+ def initialize
4
+ super('https://en.wikipedia.org/wiki/Main_Page')
5
+ end
6
+
7
+ def on_this_day
8
+ events_hash = {}
9
+ self.html_doc.css('div#mp-otd div#mp-otd-img + ul li').each do |event|
10
+ events_hash[event.css('b a').text] = {}
11
+ events_hash[event.css('b a').text][:year] = event.css('a').first.text
12
+ events_hash[event.css('b a').text][:text] = event.children.text.split(/ – /)[1]
13
+ events_hash[event.css('b a').text][:link_url] = 'https://en.wikipedia.org' + event.css('b a')[0]["href"]
14
+ end
15
+ events_hash
16
+ end
17
+
18
+ end
@@ -0,0 +1,41 @@
1
+ # require 'catpix'
2
+
3
+ class WikiOnThisDay::Printer
4
+
5
+ attr_reader :html_doc, :events_hash
6
+
7
+ def initialize(html_doc, events_hash)
8
+ @html_doc = html_doc
9
+ @events_hash = events_hash
10
+ end
11
+
12
+ # def on_this_day_image
13
+ # open('https:' + self.html_doc.css('div#mp-otd-img img').attribute('src').value) { |file|
14
+ # image_of_the_day = Tempfile.new("image_of_the_day")
15
+ # image_of_the_day << file.read
16
+ # image_of_the_day.rewind
17
+ # Catpix::print_image image_of_the_day.path,
18
+ # :limit_x => 0.5,
19
+ # :limit_y => 0,
20
+ # :center_x => true,
21
+ # :center_y => false,
22
+ # :bg => "white",
23
+ # :bg_fill => true,
24
+ # :resolution => "high"
25
+ # image_of_the_day.close
26
+ # }
27
+ # end
28
+
29
+ def print
30
+ @events_hash.each do |key, value|
31
+ puts value[:year]
32
+ abstract = value [:text]
33
+ if /\W\(pictured\)/.match(abstract)
34
+ puts abstract.gsub(/\W\(pictured\)/, '')
35
+ else
36
+ puts abstract
37
+ end
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,9 @@
1
+ class WikiOnThisDay::Scraper
2
+
3
+ attr_reader :html_doc
4
+
5
+ def initialize(page_url)
6
+ @html_doc = Nokogiri::HTML(open(page_url))
7
+ end
8
+
9
+ end
@@ -0,0 +1,3 @@
1
+ module WikiOnThisDay
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,21 @@
1
+ require 'wiki_on_this_day/version'
2
+ require 'wiki_on_this_day/scraper'
3
+ require 'wiki_on_this_day/homepage'
4
+ require 'wiki_on_this_day/printer'
5
+ require 'wiki_on_this_day/cli'
6
+ require 'wiki_on_this_day/article'
7
+
8
+ require 'open-uri'
9
+ require 'nokogiri'
10
+ # require 'catpix'
11
+ require 'pry'
12
+ require 'rspec'
13
+ require 'bundler'
14
+ require 'rake'
15
+ require 'vcr'
16
+ # require 'rmagick'
17
+ # require 'tco'
18
+ # require 'terminfo'
19
+
20
+ module WikiOnThisDay
21
+ end