reddit-ruby 1.0.5
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +47 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/reddit +6 -0
- data/bin/setup +8 -0
- data/lib/reddit.rb +7 -0
- data/lib/reddit/cli.rb +81 -0
- data/lib/reddit/scraper.rb +26 -0
- data/lib/reddit/version.rb +3 -0
- data/license.markdown +21 -0
- data/readme.markdown +37 -0
- data/reddit.gemspec +29 -0
- data/spec.markdown +7 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aa26e5b0523f4ab877b0ef814ef9c4b52bc041c8
|
4
|
+
data.tar.gz: 552895b33a1032328f351dcbdd5e573ba209e766
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 988ada44dec5558632dc9af09ef1406c005ba6f531834efb0289a9c3f066ef8d8217f9b0253cf8e7ccb012a8c7a1a3c7ce78935712523ca69b5509e145de2a4d
|
7
|
+
data.tar.gz: 7462c47a4336acf4ffe22e6d3b3f2c06bcd770439c9aa5294dc777e7097fc95d0590dbab5a7ecee1dd7078a06a442760c84d0d11670cdb4f0a9a2738e8dd2944
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
reddit-ruby (1.0.5)
|
5
|
+
colorize
|
6
|
+
nokogiri
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
coderay (1.1.2)
|
12
|
+
colorize (0.8.1)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
method_source (0.9.0)
|
15
|
+
mini_portile2 (2.3.0)
|
16
|
+
nokogiri (1.8.1)
|
17
|
+
mini_portile2 (~> 2.3.0)
|
18
|
+
pry (0.11.3)
|
19
|
+
coderay (~> 1.1.0)
|
20
|
+
method_source (~> 0.9.0)
|
21
|
+
rake (10.5.0)
|
22
|
+
rspec (3.7.0)
|
23
|
+
rspec-core (~> 3.7.0)
|
24
|
+
rspec-expectations (~> 3.7.0)
|
25
|
+
rspec-mocks (~> 3.7.0)
|
26
|
+
rspec-core (3.7.0)
|
27
|
+
rspec-support (~> 3.7.0)
|
28
|
+
rspec-expectations (3.7.0)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.7.0)
|
31
|
+
rspec-mocks (3.7.0)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.7.0)
|
34
|
+
rspec-support (3.7.0)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
bundler (~> 1.16)
|
41
|
+
pry
|
42
|
+
rake (~> 10.0)
|
43
|
+
reddit-ruby!
|
44
|
+
rspec (~> 3.0)
|
45
|
+
|
46
|
+
BUNDLED WITH
|
47
|
+
1.16.0
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "reddit"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/reddit
ADDED
data/bin/setup
ADDED
data/lib/reddit.rb
ADDED
data/lib/reddit/cli.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
class Reddit::CLI
|
2
|
+
def call
|
3
|
+
puts "Here's the current hot list on r/ruby"
|
4
|
+
show_posts
|
5
|
+
menu
|
6
|
+
end
|
7
|
+
|
8
|
+
def openInBrowser(url)
|
9
|
+
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
10
|
+
system "start #{url}"
|
11
|
+
elsif RbConfig::CONFIG['host_os'] =~ /darwin/
|
12
|
+
system "open #{url}"
|
13
|
+
elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
|
14
|
+
system "xdg-open #{url}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def menu
|
19
|
+
input = nil
|
20
|
+
while input != "exit"
|
21
|
+
puts "> Enter the number of the post you'd like more info on:"
|
22
|
+
input = gets.strip.downcase
|
23
|
+
|
24
|
+
if input.to_i > 0
|
25
|
+
show_post(input.to_i-1)
|
26
|
+
elsif input == "list"
|
27
|
+
show_posts
|
28
|
+
elsif input == "exit" || input == "q"
|
29
|
+
exit!
|
30
|
+
else
|
31
|
+
puts "> Not sure what you want, type list or exit."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_score_text(index)
|
37
|
+
post = @posts[index.to_i]
|
38
|
+
score = post[:upvotes].to_i >= 0 ? 'upvotes' : 'downvotes'
|
39
|
+
upvotes = post[:upvotes].to_i < 10 ? "0#{post[:upvotes]}" : "#{post[:upvotes]}"
|
40
|
+
return "#{upvotes} #{score}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def show_posts
|
44
|
+
Reddit::Scraper.scrape
|
45
|
+
@posts = Reddit::Scraper.scrape
|
46
|
+
@posts.each_with_index do |post, i|
|
47
|
+
upvotes = get_score_text(i)
|
48
|
+
index = "#{i + 1}"
|
49
|
+
puts "#{index.bold}. #{upvotes} - #{post[:title]} by #{post[:author].bold}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def show_post(index)
|
54
|
+
post = @posts[index.to_i]
|
55
|
+
puts ""
|
56
|
+
puts "Title: #{post[:title]}"
|
57
|
+
puts "Author: #{post[:author]}"
|
58
|
+
puts "Score: #{post[:upvotes]}"
|
59
|
+
puts "Comments: #{post[:comments]}"
|
60
|
+
puts "Posted: #{post[:timestamp]}"
|
61
|
+
puts ""
|
62
|
+
input = nil
|
63
|
+
while input != "exit"
|
64
|
+
puts "> Enter the option you'd like to perform:"
|
65
|
+
puts "1. Open in browser"
|
66
|
+
puts "2. Show hot posts"
|
67
|
+
puts "3. Exit"
|
68
|
+
input = gets.strip.downcase
|
69
|
+
if input.to_i == 1
|
70
|
+
openInBrowser(post[:url])
|
71
|
+
elsif input.to_i == 2
|
72
|
+
show_posts
|
73
|
+
break
|
74
|
+
elsif input.to_i == 3 || input == "exit" || input == "q"
|
75
|
+
exit!
|
76
|
+
else
|
77
|
+
puts "> Not sure what you want, type list or exit."
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Reddit::Scraper
|
2
|
+
attr_accessor :title, :author, :timestamp, :comments, :upvotes, :url
|
3
|
+
def self.scrape
|
4
|
+
doc = Nokogiri::HTML(open("https://www.reddit.com/r/ruby", 'User-Agent' => 'ruby-reddit'))
|
5
|
+
posts = []
|
6
|
+
postsList = doc.css('#siteTable > div.thing.link').first(10)
|
7
|
+
postsList.each do |post|
|
8
|
+
title = post.css('.title a.title').text.strip
|
9
|
+
author = post.css('.author').text.strip
|
10
|
+
timestamp = post.css('.live-timestamp').text.strip
|
11
|
+
comments = post.attr('data-comments-count')
|
12
|
+
upvotes = post.attr('data-score')
|
13
|
+
url = post.css('a.comments').attr('href')
|
14
|
+
newPost = {
|
15
|
+
title: title,
|
16
|
+
author: author,
|
17
|
+
timestamp: timestamp,
|
18
|
+
comments: comments,
|
19
|
+
upvotes: upvotes,
|
20
|
+
url: url,
|
21
|
+
}
|
22
|
+
posts << newPost
|
23
|
+
end
|
24
|
+
posts
|
25
|
+
end
|
26
|
+
end
|
data/license.markdown
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Logan McAnsh
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/readme.markdown
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Ruby Reddit
|
2
|
+
|
3
|
+
Show the current Hot posts on r/ruby
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
$ gem install ruby-reddit
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```bash
|
14
|
+
$ ruby-reddit
|
15
|
+
```
|
16
|
+
|
17
|
+
## Development
|
18
|
+
|
19
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
20
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
21
|
+
prompt that will allow you to experiment.
|
22
|
+
|
23
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
24
|
+
release a new version, update the version number in `version.rb`, and then run
|
25
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
26
|
+
git commits and tags, and push the `.gem` file to
|
27
|
+
[rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at
|
32
|
+
https://github.com/mcansh/ruby-reddit-cli-app.
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
The gem is available as open source under the terms of the
|
37
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
data/reddit.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "reddit/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "reddit-ruby"
|
7
|
+
spec.version = Reddit::VERSION
|
8
|
+
spec.authors = ["Logan McAnsh"]
|
9
|
+
spec.email = ["logan@mcan.sh"]
|
10
|
+
|
11
|
+
spec.summary = "Get the current hot posts from r/ruby"
|
12
|
+
spec.description = "Get the current hot posts from r/ruby"
|
13
|
+
spec.homepage = "https://github.com/mcansh/ruby-reddit-cli-app"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
spec.add_runtime_dependency "nokogiri"
|
28
|
+
spec.add_runtime_dependency "colorize"
|
29
|
+
end
|
data/spec.markdown
ADDED
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reddit-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Logan McAnsh
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: nokogiri
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: colorize
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Get the current hot posts from r/ruby
|
98
|
+
email:
|
99
|
+
- logan@mcan.sh
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- Gemfile.lock
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/reddit
|
112
|
+
- bin/setup
|
113
|
+
- lib/reddit.rb
|
114
|
+
- lib/reddit/cli.rb
|
115
|
+
- lib/reddit/scraper.rb
|
116
|
+
- lib/reddit/version.rb
|
117
|
+
- license.markdown
|
118
|
+
- readme.markdown
|
119
|
+
- reddit.gemspec
|
120
|
+
- spec.markdown
|
121
|
+
homepage: https://github.com/mcansh/ruby-reddit-cli-app
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.5.2
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Get the current hot posts from r/ruby
|
145
|
+
test_files: []
|