reddit-ruby 1.0.8 → 1.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/Gemfile.lock +3 -3
- data/lib/reddit.rb +2 -1
- data/lib/reddit/cli.rb +17 -16
- data/lib/reddit/post.rb +20 -0
- data/lib/reddit/scraper.rb +3 -13
- data/lib/reddit/version.rb +1 -1
- data/reddit.gemspec +2 -2
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 849504009e7932ba671b0d79e528ce1231a68944
|
4
|
+
data.tar.gz: f94ff358e3ec904787f1c69d2f79908c1edd068c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a926c062d990ac65f112c8aa87acb40595e2fcc84418df7f8e2f3d142d81497b13144805caea89397bb66fb0065bed57062c08d6e413418dfc5f6e548e88b2e
|
7
|
+
data.tar.gz: cb25c2633fe581e890a24ec7119f4ad4c4871f801e7cf05245f13e095b87aafd21730402229bf9f68fd01c3a4e4d88efc2bb37b84d24eb52b1b20cd3c09f5012
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
reddit-ruby (1.0.
|
4
|
+
reddit-ruby (1.0.9)
|
5
5
|
colorize
|
6
6
|
nokogiri
|
7
7
|
|
@@ -13,7 +13,7 @@ GEM
|
|
13
13
|
diff-lcs (1.3)
|
14
14
|
method_source (0.9.0)
|
15
15
|
mini_portile2 (2.3.0)
|
16
|
-
nokogiri (1.8.
|
16
|
+
nokogiri (1.8.2)
|
17
17
|
mini_portile2 (~> 2.3.0)
|
18
18
|
pry (0.11.3)
|
19
19
|
coderay (~> 1.1.0)
|
@@ -23,7 +23,7 @@ GEM
|
|
23
23
|
rspec-core (~> 3.7.0)
|
24
24
|
rspec-expectations (~> 3.7.0)
|
25
25
|
rspec-mocks (~> 3.7.0)
|
26
|
-
rspec-core (3.7.
|
26
|
+
rspec-core (3.7.1)
|
27
27
|
rspec-support (~> 3.7.0)
|
28
28
|
rspec-expectations (3.7.0)
|
29
29
|
diff-lcs (>= 1.2.0, < 2.0)
|
data/lib/reddit.rb
CHANGED
data/lib/reddit/cli.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
class Reddit::CLI
|
2
2
|
def call
|
3
3
|
@subreddit = ARGV[0] || "ruby"
|
4
|
+
Reddit::Scraper.scrape(@subreddit)
|
5
|
+
@posts = Reddit::Post.all
|
4
6
|
puts "Here's the current hot list on r/#{@subreddit}"
|
5
|
-
show_posts
|
7
|
+
show_posts
|
8
|
+
|
6
9
|
menu
|
7
10
|
end
|
8
11
|
|
@@ -22,7 +25,6 @@ class Reddit::CLI
|
|
22
25
|
puts ""
|
23
26
|
puts "> Enter the number of the post you'd like more info on:"
|
24
27
|
input = STDIN.gets.chomp.downcase
|
25
|
-
|
26
28
|
if input.to_i > 0
|
27
29
|
show_post(input.to_i-1)
|
28
30
|
elsif input == "list"
|
@@ -37,32 +39,31 @@ class Reddit::CLI
|
|
37
39
|
|
38
40
|
def get_score_text(index)
|
39
41
|
post = @posts[index.to_i]
|
40
|
-
upvotes = post
|
41
|
-
if post
|
42
|
-
score = post
|
42
|
+
upvotes = post.upvotes
|
43
|
+
if post.upvotes.to_i == 1
|
44
|
+
score = post.upvotes.to_i >= 0 ? 'upvote' : 'downvote'
|
43
45
|
else
|
44
|
-
score = post
|
46
|
+
score = post.upvotes.to_i >= 0 ? 'upvotes' : 'downvotes'
|
45
47
|
end
|
46
48
|
return "#{upvotes} #{score}"
|
47
49
|
end
|
48
50
|
|
49
|
-
def show_posts
|
50
|
-
@posts = Reddit::Scraper.scrape(subreddit)
|
51
|
+
def show_posts
|
51
52
|
@posts.each_with_index do |post, i|
|
52
53
|
upvotes = get_score_text(i)
|
53
54
|
index = "#{i + 1}"
|
54
|
-
puts "#{index.bold}. #{upvotes} - #{post
|
55
|
+
puts "#{index.bold}. #{upvotes} - #{post.title} by #{post.author.bold}"
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
58
59
|
def show_post(index)
|
59
60
|
post = @posts[index.to_i]
|
60
61
|
puts ""
|
61
|
-
puts "Title: #{post
|
62
|
-
puts "Author: #{post
|
63
|
-
puts "Score: #{post
|
64
|
-
puts "Comments: #{post
|
65
|
-
puts "Posted: #{post
|
62
|
+
puts "Title: #{post.title}"
|
63
|
+
puts "Author: #{post.author}"
|
64
|
+
puts "Score: #{post.upvotes}"
|
65
|
+
puts "Comments: #{post.comments}"
|
66
|
+
puts "Posted: #{post.timestamp}"
|
66
67
|
puts ""
|
67
68
|
input = nil
|
68
69
|
while input != "exit"
|
@@ -73,7 +74,7 @@ class Reddit::CLI
|
|
73
74
|
puts ""
|
74
75
|
input = STDIN.gets.chomp.downcase
|
75
76
|
if input.to_i == 1
|
76
|
-
openInBrowser(post
|
77
|
+
openInBrowser(post.url)
|
77
78
|
elsif input.to_i == 2
|
78
79
|
show_posts
|
79
80
|
break
|
@@ -84,4 +85,4 @@ class Reddit::CLI
|
|
84
85
|
end
|
85
86
|
end
|
86
87
|
end
|
87
|
-
end
|
88
|
+
end
|
data/lib/reddit/post.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
class Reddit::Post
|
2
|
+
attr_accessor :title, :author, :timestamp, :comments, :upvotes, :url
|
3
|
+
|
4
|
+
@@post = []
|
5
|
+
|
6
|
+
def initialize(title, author, timestamp, comments, upvotes, url)
|
7
|
+
@title = title
|
8
|
+
@author = author
|
9
|
+
@timestamp = timestamp
|
10
|
+
@comments = comments
|
11
|
+
@upvotes = upvotes
|
12
|
+
@url = url
|
13
|
+
|
14
|
+
@@post << self
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.all
|
18
|
+
@@post
|
19
|
+
end
|
20
|
+
end
|
data/lib/reddit/scraper.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
class Reddit::Scraper
|
2
|
-
attr_accessor :title, :author, :timestamp, :comments, :upvotes, :url
|
3
2
|
def self.scrape(subreddit)
|
4
3
|
url = "https://www.reddit.com/r/#{subreddit}"
|
5
4
|
doc = Nokogiri::HTML(open(url, 'User-Agent' => 'ruby-reddit'))
|
6
|
-
posts = []
|
7
5
|
postsList = doc.css('#siteTable > div.thing.link').first(10)
|
8
6
|
postsList.each do |post|
|
9
7
|
title = post.css('.title a.title').text.strip
|
@@ -12,16 +10,8 @@ class Reddit::Scraper
|
|
12
10
|
comments = post.attr('data-comments-count')
|
13
11
|
upvotes = post.attr('data-score')
|
14
12
|
url = post.css('a.comments').attr('href')
|
15
|
-
|
16
|
-
|
17
|
-
author: author,
|
18
|
-
timestamp: timestamp,
|
19
|
-
comments: comments,
|
20
|
-
upvotes: upvotes,
|
21
|
-
url: url,
|
22
|
-
}
|
23
|
-
posts << newPost
|
13
|
+
|
14
|
+
Reddit::Post.new(title, author, timestamp, comments, upvotes, url)
|
24
15
|
end
|
25
|
-
posts
|
26
16
|
end
|
27
|
-
end
|
17
|
+
end
|
data/lib/reddit/version.rb
CHANGED
data/reddit.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["Logan McAnsh"]
|
9
9
|
spec.email = ["logan@mcan.sh"]
|
10
10
|
|
11
|
-
spec.summary = "Get the current hot posts from
|
12
|
-
spec.description = "Get the current hot posts from
|
11
|
+
spec.summary = "Get the current hot posts from any subreddit"
|
12
|
+
spec.description = "Get the current hot posts from any subreddit"
|
13
13
|
spec.homepage = "https://github.com/mcansh/ruby-reddit-cli-app"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reddit-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Logan McAnsh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,7 +94,7 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description: Get the current hot posts from
|
97
|
+
description: Get the current hot posts from any subreddit
|
98
98
|
email:
|
99
99
|
- logan@mcan.sh
|
100
100
|
executables:
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- bin/setup
|
114
114
|
- lib/reddit.rb
|
115
115
|
- lib/reddit/cli.rb
|
116
|
+
- lib/reddit/post.rb
|
116
117
|
- lib/reddit/scraper.rb
|
117
118
|
- lib/reddit/version.rb
|
118
119
|
- license.markdown
|
@@ -139,8 +140,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
140
|
version: '0'
|
140
141
|
requirements: []
|
141
142
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
143
|
+
rubygems_version: 2.6.13
|
143
144
|
signing_key:
|
144
145
|
specification_version: 4
|
145
|
-
summary: Get the current hot posts from
|
146
|
+
summary: Get the current hot posts from any subreddit
|
146
147
|
test_files: []
|