culture_news_reader 1.0.0 → 1.1.0
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/lib/culture_news_reader/cli.rb +13 -26
- data/lib/culture_news_reader/scraper.rb +13 -12
- data/lib/culture_news_reader/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f79428cf884e507b224a9e80f4e8974b3e4340b
|
4
|
+
data.tar.gz: 1c3e1aafa820181530738aaef4056d0c55ae2d81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d94f91e9e14826b52f96ab19e57fbd09ff38488fc000f41224233b57b4f6d05e597dda4484d2a90262fbdf3f8a50524f3ce3e5977e6cabb5b5e3a0b025f5fdaa
|
7
|
+
data.tar.gz: a46a02c79fbd7ad7bf4b380c9e0fc96d5c53713c1580a20bd3ba86a887af8df80715831f385adb6937d5d3085ad39e61063f6a7842d0b2848054d4f1753e9c91
|
@@ -34,52 +34,39 @@ class CultureNewsReader::CLI
|
|
34
34
|
CultureNewsReader::Scraper.page(category)
|
35
35
|
list_articles(category)
|
36
36
|
#puts music
|
37
|
-
launcher(category
|
37
|
+
launcher(category)
|
38
38
|
elsif input.to_i == 4
|
39
39
|
category = CultureNewsReader::Category.all[input.to_i - 1]
|
40
40
|
CultureNewsReader::Scraper.trending_page(category)
|
41
41
|
list_articles(category)
|
42
|
+
launcher(category)
|
42
43
|
elsif input == "list"
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
# when "2"
|
50
|
-
# #CultureNewsReader::Article.all.clear
|
51
|
-
# style = CultureNewsReader::Scraper.page(@@categories[input.to_i - 1])
|
52
|
-
# list_articles
|
53
|
-
# launcher(style)
|
54
|
-
# when "3"
|
55
|
-
# #CultureNewsReader::Article.all.clear
|
56
|
-
# culture = CultureNewsReader::Scraper.page(@@categories[input.to_i - 1])
|
57
|
-
# list_articles
|
58
|
-
# launcher(culture)
|
59
|
-
# when "4"
|
60
|
-
# #CultureNewsReader::Article.all.clear
|
61
|
-
# list_articles
|
62
|
-
# launcher(trending)
|
44
|
+
list_categories
|
45
|
+
elsif input == "exit"
|
46
|
+
puts "Stay Faded"
|
47
|
+
else
|
48
|
+
puts "Invalid. Please try again."
|
49
|
+
end
|
63
50
|
end
|
64
51
|
end
|
65
52
|
|
66
|
-
def launcher(
|
53
|
+
def launcher(category)
|
67
54
|
input = nil
|
68
55
|
while input != "exit"
|
69
56
|
puts "Enter the article number you would like to preview, or type exit:"
|
70
57
|
input = gets.strip.downcase
|
71
58
|
if input == "exit"
|
72
59
|
return
|
73
|
-
elsif input.to_i <=
|
60
|
+
elsif input.to_i <= category.articles.length
|
74
61
|
puts "------------------------------------------------------------------------------"
|
75
|
-
puts "#{
|
62
|
+
puts "#{category.articles[input.to_i - 1].title}"
|
76
63
|
puts "------------------------------------------------------------------------------"
|
77
|
-
CultureNewsReader::Scraper.story(
|
64
|
+
puts CultureNewsReader::Scraper.story(category.articles[input.to_i - 1])
|
78
65
|
puts "------------------------------------------------------------------------------"
|
79
66
|
puts "Would you like to read this? Y/n"
|
80
67
|
y_or_n = gets.strip.downcase
|
81
68
|
if y_or_n == "y"
|
82
|
-
|
69
|
+
category.articles[input.to_i - 1].open
|
83
70
|
end
|
84
71
|
else
|
85
72
|
puts "Please try again"
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class CultureNewsReader::Scraper
|
2
|
-
THE_FADER_URL = 'http://www.thefader.com
|
2
|
+
THE_FADER_URL = 'http://www.thefader.com'
|
3
3
|
def self.page(category)
|
4
|
-
page = category.name.downcase
|
5
|
-
html = open(THE_FADER_URL +
|
4
|
+
page = "/" + category.name.downcase
|
5
|
+
html = open(THE_FADER_URL + page)
|
6
6
|
doc = Nokogiri::HTML(html)
|
7
7
|
stories = doc.css("div.card.pinned_post")
|
8
8
|
scraped_stories = stories.collect do |story|
|
@@ -14,13 +14,14 @@ class CultureNewsReader::Scraper
|
|
14
14
|
scraped_stories.shift
|
15
15
|
end
|
16
16
|
scraped_stories.each do |article|
|
17
|
-
|
18
|
-
category.add_article(
|
17
|
+
new_article = CultureNewsReader::Article.new(article)
|
18
|
+
category.add_article(new_article)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.trending_page(category)
|
23
|
-
page = category.name.downcase
|
23
|
+
page = "/" + category.name.downcase
|
24
|
+
|
24
25
|
html = open(THE_FADER_URL + page)
|
25
26
|
doc = Nokogiri::HTML(html)
|
26
27
|
stories = doc.css("div.featured_post")
|
@@ -33,18 +34,18 @@ class CultureNewsReader::Scraper
|
|
33
34
|
article
|
34
35
|
end
|
35
36
|
scraped_stories.delete_if {|a| a[:title] == "" && a[:description] == ""}
|
36
|
-
|
37
|
-
CultureNewsReader::Article.new(article)
|
37
|
+
scraped_stories.each do |article|
|
38
|
+
new_article = CultureNewsReader::Article.new(article)
|
39
|
+
category.add_article(new_article)
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
41
43
|
def self.story(article)
|
44
|
+
#binding.pry
|
42
45
|
html = open(article.link)
|
43
46
|
doc = Nokogiri::HTML(html)
|
44
|
-
|
45
|
-
preview
|
46
|
-
puts preview[1].strip
|
47
|
-
|
47
|
+
preview = doc.css(".paragraph_wrapper p:first").text.split("\n")
|
48
|
+
preview[1].strip
|
48
49
|
end
|
49
50
|
|
50
51
|
|