reddits 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1cefb30706c4b5c2c7487ff701a877ad3b8aae5d
4
+ data.tar.gz: 28a9b7b5168e7f1c4402fd56ebcc6e2f0e63d93a
5
+ SHA512:
6
+ metadata.gz: 01adb63d7a22c840fff47bd4919648239ced2dcb79f724cd239eb539aba8068a092c0613b3f84275c991430c09d0ace96509376d738bb653bec47889cb048031
7
+ data.tar.gz: 1a1ac21c69879daab9671d799525ed3d6882e344fafbeddbcfba01e84280ad28bf87daed9d3ac43e60736bbb8fae4aeaa57765bfe6f1f5e3ca1213557c4fa4f8
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in reddits.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 David Lewitan
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.md ADDED
@@ -0,0 +1,39 @@
1
+ # Reddits
2
+
3
+ see what's new on reddit and take a little break!
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'reddits'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install reddits
20
+
21
+ ## Usage
22
+
23
+ once gem is required the method 'reddits' will be exposed.
24
+ just type: reddits
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+
30
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/StreamedLine/reddits.
35
+
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "reddits"
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
data/bin/reddits ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/reddits.rb"
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/cli.rb ADDED
@@ -0,0 +1,93 @@
1
+ class Cli
2
+ attr_accessor :theData
3
+
4
+ def initialize
5
+ @theData = TheData.new
6
+ end
7
+
8
+ def run
9
+ get_categories
10
+ select_categories
11
+
12
+ get_selected_category
13
+ select_specific_post
14
+
15
+ display_post
16
+ end
17
+
18
+ def list(array)
19
+ array.each_with_index do |category, index|
20
+ if index.even?
21
+ puts "#{index+1}. #{category[:name]}".colorize(:background => :red, :color => :white)
22
+ else
23
+ puts "#{index+1}. #{category[:name]}".colorize(:background => :light_black, :color => :white)
24
+ end
25
+ end
26
+ end
27
+
28
+ def get_categories
29
+ @theData.get_categories
30
+ end
31
+
32
+ def select_categories
33
+ list(@theData.all_categories)
34
+ selection = nil
35
+ while !selection or selection == "" or !selection.to_i.between?(1, @theData.all_categories.count)
36
+ puts "please select a category"
37
+ selection = gets.chomp
38
+ if selection.upcase == 'LIST'
39
+ list(@theData.all_categories)
40
+ selection = nil
41
+ next
42
+ elsif selection.upcase == 'Q'
43
+ exit
44
+ end
45
+ end
46
+ @theData.select_category(@theData.all_categories[selection.to_i-1])
47
+ end
48
+
49
+ def get_selected_category
50
+ @theData.get_selected_category
51
+ end
52
+
53
+ def select_specific_post
54
+ list(@theData.category)
55
+ selection = nil
56
+ while !selection or selection == "" or !selection.to_i.between?(1, @theData.category.count)
57
+ puts "please select a post"
58
+ selection = gets.chomp
59
+ if selection.upcase == 'LIST'
60
+ list(@theData.category)
61
+ selection = nil
62
+ next
63
+ elsif selection.upcase == 'Q'
64
+ exit
65
+ end
66
+ end
67
+ @theData.select_specific_post(@theData.category[selection.to_i-1])
68
+ end
69
+
70
+ def display_post
71
+ puts "\n#{"Title:".colorize(:color => :light_white)} #{@theData.post[:title].colorize(:color => :light_green)}"
72
+ puts "#{"Author:".colorize(:color => :light_white)} #{@theData.post[:author].colorize(:color => :green)}"
73
+ puts "#{"Posted on:".colorize(:color => :light_white)} #{@theData.post[:time].colorize(:color => :yellow)}"
74
+ puts "#{"Link:".colorize(:color => :light_white)} #{@theData.post[:link].colorize(:color => :light_blue)}"
75
+ puts ""
76
+ display_in_browser
77
+ end
78
+
79
+ def display_in_browser
80
+ link = @theData.post[:link]
81
+ puts "Type b to display in browser or any key to quit".colorize(:color => :cyan)
82
+ browser = STDIN.gets.chomp
83
+ if browser.upcase == 'B'
84
+ begin
85
+ Launchy.open(link)
86
+ rescue
87
+ puts "Couldn't access browser. Link will be copied to clipboard instead.".colorize(:red)
88
+ Clipboard.copy(link)
89
+ puts "#{link.colorize(:light_blue)} copied to cliboard!"
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,3 @@
1
+ module Reddits
2
+ VERSION = "0.1.0"
3
+ end
data/lib/reddits.rb ADDED
@@ -0,0 +1,21 @@
1
+ require_relative "reddits/version.rb"
2
+ require "open-uri"
3
+ require "nokogiri"
4
+ require "colorize"
5
+ require "launchy"
6
+ require "clipboard"
7
+ require "pry"
8
+
9
+ require_relative "./cli.rb"
10
+ require_relative "./theData.rb"
11
+ require_relative "./scraper.rb"
12
+
13
+ Cli.new.run
14
+
15
+ def reddits
16
+ Cli.new.run
17
+ end
18
+
19
+ # module Reddits
20
+ # # Your code goes here...
21
+ # end
data/lib/scraper.rb ADDED
@@ -0,0 +1,16 @@
1
+ class Scraper
2
+ @@BasePath = "https://reddit.com"
3
+ @@html = nil
4
+
5
+ def self.scrape_categories
6
+ @@html = Nokogiri::HTML(open(@@BasePath, 'User-Agent' => 'NoobyDooby'))
7
+ category_list = @@html.css('#header ul.tabmenu li a')
8
+ end
9
+
10
+ def self.scrape_selected_category(link)
11
+ puts "link = #{link}"
12
+ @@html = Nokogiri::HTML(open(link, 'User-Agent' => 'NoobyDooby'))
13
+
14
+ post_list = @@html.css('.thing.link')
15
+ end
16
+ end
data/lib/theData.rb ADDED
@@ -0,0 +1,42 @@
1
+ class TheData
2
+ attr_accessor :all_categories, :category_link, :category, :post
3
+
4
+ def initialize
5
+ @post = {}
6
+ get_categories
7
+ end
8
+
9
+ def get_categories
10
+ @all_categories = Scraper.scrape_categories.collect do |category|
11
+ next if category.text == 'wiki' or category.text == 'gilded' or category.text == 'promoted'
12
+ {:name => category.text, :link => category['href']}
13
+ end.compact
14
+ end
15
+
16
+ def select_category(selection)
17
+ puts "category = #{selection[:link]}"
18
+ @category_link = selection[:link]
19
+ end
20
+
21
+ def get_selected_category
22
+ @category = Scraper.scrape_selected_category(@category_link).collect do |post|
23
+ {:name => post.css('div.entry').inner_text.split('submitted')[0], :post => post}
24
+ end
25
+ end
26
+
27
+ def select_specific_post(selection)
28
+ add_post_attributes(selection)
29
+ end
30
+
31
+ def add_post_attributes(selection)
32
+ selection = selection[:post]
33
+ @post[:title] = selection.css('a.title').text
34
+ @post[:author] = selection.css('a.author').text
35
+ @post[:link] = selection.css('a.title')[0]['href']
36
+ @post[:time] = "#{selection.css('time')[0]['title']}; #{selection.css('time')[0].inner_text}"
37
+
38
+ if @post[:link][0] == '/'
39
+ @post[:link] = "https://reddit.com" + @post[:link]
40
+ end
41
+ end
42
+ end
data/reddits.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'reddits/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "reddits"
8
+ spec.version = Reddits::VERSION
9
+ spec.authors = ["David Lewitan"]
10
+ spec.email = ["dovidlwtn@gmail.com"]
11
+
12
+ spec.summary = "Scrapes reddits landing page."
13
+ spec.homepage = "https://github.com/StreamedLine/redditScraper"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.13"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "pry"
35
+ spec.add_dependency "nokogiri"
36
+ spec.add_dependency "colorize"
37
+ spec.add_dependency "clipboard"
38
+ spec.add_dependency "launchy"
39
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reddits
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Lewitan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-16 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
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: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: colorize
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: clipboard
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
+ - !ruby/object:Gem::Dependency
98
+ name: launchy
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - dovidlwtn@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - bin/console
124
+ - bin/reddits
125
+ - bin/setup
126
+ - lib/cli.rb
127
+ - lib/reddits.rb
128
+ - lib/reddits/version.rb
129
+ - lib/scraper.rb
130
+ - lib/theData.rb
131
+ - reddits.gemspec
132
+ homepage: https://github.com/StreamedLine/redditScraper
133
+ licenses:
134
+ - MIT
135
+ metadata:
136
+ allowed_push_host: https://rubygems.org
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.6.8
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Scrapes reddits landing page.
157
+ test_files: []