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 +7 -0
- data/.gitmodules +3 -0
- data/.learn +8 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +59 -0
- data/LICENSE.md +21 -0
- data/README.md +5 -0
- data/Rakefile +6 -0
- data/bin/console +9 -0
- data/bin/setup +7 -0
- data/bin/wiki_on_this_day +5 -0
- data/lib/wiki_on_this_day/article.rb +11 -0
- data/lib/wiki_on_this_day/cli.rb +24 -0
- data/lib/wiki_on_this_day/homepage.rb +18 -0
- data/lib/wiki_on_this_day/printer.rb +41 -0
- data/lib/wiki_on_this_day/scraper.rb +9 -0
- data/lib/wiki_on_this_day/version.rb +3 -0
- data/lib/wiki_on_this_day.rb +21 -0
- data/spec/fixtures/vcr_cassettes/main_page_2015_12_15.yml +1511 -0
- data/spec/fixtures/vcr_cassettes/oliver_cromwell.yml +8249 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/wiki_on_this_day/wiki_on_this_day_spec.rb +58 -0
- data/wiki_on_this_day.gemspec +28 -0
- metadata +173 -0
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
data/.learn
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
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
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -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,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
|