check_the_facts 0.0.1 → 0.0.9
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 +4 -4
- data/bin/check_the_facts +1 -1
- data/bin/console +6 -0
- data/check_the_facts.gemspec +4 -3
- data/{environment.rb → config/environment.rb} +0 -0
- data/lib/article.rb +3 -0
- data/lib/cli.rb +121 -0
- data/lib/scraper.rb +64 -0
- data/spec.md +7 -0
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edfb594ae2b9c62ae4cbf1f4c3d139d9f1ac8caf
|
4
|
+
data.tar.gz: af81c912295e6365c3a1d34117a8f72a2c6bad1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e02a45a6f5969219c9c429b3bd18b29eb0ec3e52fb2502fb76dc9ab01d1824299237d2219664f2e1bdb7c1cd2bdde6ab72dfe5af8103a9ddff5324a0383aa569
|
7
|
+
data.tar.gz: b2cfb28e1980bd5c7a3752416461d00d1cc91441bf4133c009c476add42aa6bf549bc8a7e47d043bc184caa3e997c0720d8555fdbe48c0db6b9836ec876c6746
|
data/bin/check_the_facts
CHANGED
data/bin/console
ADDED
data/check_the_facts.gemspec
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'check_the_facts'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.9'
|
4
4
|
s.date = '2016-09-30'
|
5
5
|
s.summary = "Check the Facts"
|
6
6
|
s.description = "A Snopes Scraper and CLI"
|
7
7
|
s.authors = ["David Kennell"]
|
8
|
-
s.email = 'davidkennell0@gmail.
|
9
|
-
|
8
|
+
s.email = 'davidkennell0@gmail.co
|
9
|
+
m'
|
10
|
+
s.files = Dir['Gemfile', 'Gemfile.lock', 'Notes', 'environment.rb', 'check_the_facts.gemspec', 'README.md', 'spec.md', 'bin/*', 'lib/*', 'config/*'] & `git ls-files -z`.split("\0")
|
10
11
|
s.executables = ["check_the_facts"]
|
11
12
|
s.homepage = 'http://rubygems.org/gems/check_the_facts'
|
12
13
|
s.license = 'MIT'
|
File without changes
|
data/lib/article.rb
ADDED
data/lib/cli.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
class CLI
|
2
|
+
attr_accessor :scraper
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@scraper = Scraper.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def start
|
9
|
+
puts " "
|
10
|
+
puts " Welcome to..."
|
11
|
+
puts "---=====<<<Check The Facts!>>>=====---"
|
12
|
+
puts " A Snopes Scraper and CLI"
|
13
|
+
puts " "
|
14
|
+
puts "Please choose the article you would like to read"
|
15
|
+
puts "more about by entering the corresponding number."
|
16
|
+
puts " "
|
17
|
+
i = 0
|
18
|
+
@scraper.articles.each do |article|
|
19
|
+
i += 1
|
20
|
+
puts "#{i}. " + article.title
|
21
|
+
end
|
22
|
+
puts " "
|
23
|
+
puts "Enter an article number or type 'exit' to exit: "
|
24
|
+
print "> "
|
25
|
+
input = gets.chomp("Enter a number >> ")
|
26
|
+
select_article(input)
|
27
|
+
end
|
28
|
+
|
29
|
+
def select_article(last_input)
|
30
|
+
if last_input.to_i == 0
|
31
|
+
if last_input == "exit\n"
|
32
|
+
puts "Bye for now!"
|
33
|
+
exit
|
34
|
+
else
|
35
|
+
puts "Please only enter a number or 'exit.' "
|
36
|
+
puts "Press any key to continue..."
|
37
|
+
STDIN.getch
|
38
|
+
print ''
|
39
|
+
start
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
elsif last_input.to_i < 31
|
44
|
+
puts " "
|
45
|
+
puts "---------Article Title---------"
|
46
|
+
puts scraper.articles[last_input.to_i - 1].title
|
47
|
+
puts "------Article Information------"
|
48
|
+
puts "What would you like to know about this article?"
|
49
|
+
puts "1: Claim"
|
50
|
+
puts "2: Accuracy"
|
51
|
+
puts "3: Origin"
|
52
|
+
puts "4: Author"
|
53
|
+
puts "5: Author Bio"
|
54
|
+
puts "6: Full Artice"
|
55
|
+
puts "7: Return to All Articles"
|
56
|
+
print "> "
|
57
|
+
input = gets.chomp
|
58
|
+
second_layer(last_input, input)
|
59
|
+
else
|
60
|
+
puts "Sorry, I don't think we have that article."
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def second_layer(last_input, input)
|
65
|
+
case input
|
66
|
+
when "1"
|
67
|
+
puts scraper.articles[last_input.to_i - 1].claim
|
68
|
+
puts "Press any key to continue..."
|
69
|
+
STDIN.getch
|
70
|
+
print ''
|
71
|
+
select_article(last_input)
|
72
|
+
when "2"
|
73
|
+
print "Accuracy: "
|
74
|
+
puts scraper.articles[last_input.to_i - 1].accuracy
|
75
|
+
puts "Press any key to continue..."
|
76
|
+
STDIN.getch
|
77
|
+
print ''
|
78
|
+
select_article(last_input)
|
79
|
+
when "3"
|
80
|
+
puts scraper.articles[last_input.to_i - 1].origin
|
81
|
+
puts "Press any key to continue..."
|
82
|
+
STDIN.getch
|
83
|
+
print ''
|
84
|
+
select_article(last_input)
|
85
|
+
when "4"
|
86
|
+
puts scraper.articles[last_input.to_i - 1].author
|
87
|
+
puts "Press any key to continue..."
|
88
|
+
STDIN.getch
|
89
|
+
print ''
|
90
|
+
select_article(last_input)
|
91
|
+
|
92
|
+
when "5"
|
93
|
+
puts "Accuracy of Claim:"
|
94
|
+
puts scraper.articles[last_input.to_i - 1].author_bio
|
95
|
+
puts "Press any key to continue..."
|
96
|
+
STDIN.getch
|
97
|
+
print ''
|
98
|
+
select_article(last_input)
|
99
|
+
|
100
|
+
when "6"
|
101
|
+
puts "Full Article:"
|
102
|
+
puts scraper.articles[last_input.to_i - 1].full_article
|
103
|
+
puts "Press any key to continue..."
|
104
|
+
STDIN.getch
|
105
|
+
print ''
|
106
|
+
select_article(last_input)
|
107
|
+
|
108
|
+
when "7"
|
109
|
+
start
|
110
|
+
else
|
111
|
+
puts "Please only enter a number.' "
|
112
|
+
puts "Press any key to continue..."
|
113
|
+
STDIN.getch
|
114
|
+
print ''
|
115
|
+
start
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
end
|
121
|
+
|
data/lib/scraper.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
class Scraper
|
2
|
+
attr_accessor :doc, :articles
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@doc = Nokogiri::HTML(open("http://www.snopes.com/category/facts/"))
|
6
|
+
create_articles
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_articles
|
10
|
+
@articles = []
|
11
|
+
article_objects = @doc.css("h4")
|
12
|
+
article_objects.each do |object|
|
13
|
+
new_article = Article.new
|
14
|
+
new_article.title = object.css("a").text
|
15
|
+
new_article.url = object.css("a").attribute("href").value
|
16
|
+
article = Nokogiri::HTML(open("http://www.snopes.com" + new_article.url))
|
17
|
+
new_article.origin = get_origin(article)
|
18
|
+
new_article.claim = get_claim(article)
|
19
|
+
new_article.author = get_author(article)
|
20
|
+
new_article.author_bio = get_author_bio(article)
|
21
|
+
new_article.accuracy = get_accuracy(article)
|
22
|
+
new_article.full_article = get_full_article(article)
|
23
|
+
|
24
|
+
@articles << new_article
|
25
|
+
end
|
26
|
+
@articles = @articles[0..9]
|
27
|
+
# articles.each do |a|
|
28
|
+
# puts a.full_article
|
29
|
+
# end
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_origin(article)
|
33
|
+
origin = article.css("#fact_check_origin").first.parent
|
34
|
+
origin.text
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_claim(article)
|
38
|
+
claim = article.css("span.green-label").first.parent
|
39
|
+
claim.text
|
40
|
+
#This works because it return the FIRST XML element in an
|
41
|
+
#array of span.green-label elements.
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_author(article)
|
45
|
+
author = article.css(".author-name")
|
46
|
+
author.text.strip
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_author_bio(article)
|
50
|
+
author_bio = article.css(".author-bio p")
|
51
|
+
author_bio.text.strip
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_accuracy(article)
|
55
|
+
accuracy = article.css("div.claim-old")
|
56
|
+
accuracy.text.strip.downcase.capitalize
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_full_article(article)
|
60
|
+
full_article = article.css(".article-text")
|
61
|
+
full_article.text.gsub(/\s{2,}/, "\n").gsub("if(window.proper_display) { proper_display('snopes_featured_1'); }", "").gsub("if(window.proper_display) { proper_display('snopes_content_1'); }", "")
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/spec.md
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: check_the_facts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Kennell
|
@@ -11,7 +11,9 @@ cert_chain: []
|
|
11
11
|
date: 2016-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Snopes Scraper and CLI
|
14
|
-
email:
|
14
|
+
email: |-
|
15
|
+
davidkennell0@gmail.co
|
16
|
+
m
|
15
17
|
executables:
|
16
18
|
- check_the_facts
|
17
19
|
extensions: []
|
@@ -22,8 +24,13 @@ files:
|
|
22
24
|
- Notes
|
23
25
|
- README.md
|
24
26
|
- bin/check_the_facts
|
27
|
+
- bin/console
|
25
28
|
- check_the_facts.gemspec
|
26
|
-
- environment.rb
|
29
|
+
- config/environment.rb
|
30
|
+
- lib/article.rb
|
31
|
+
- lib/cli.rb
|
32
|
+
- lib/scraper.rb
|
33
|
+
- spec.md
|
27
34
|
homepage: http://rubygems.org/gems/check_the_facts
|
28
35
|
licenses:
|
29
36
|
- MIT
|