internet-wisdom 0.1.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 137e1597ef456e8c42af6d982c2df5269a41647d
4
+ data.tar.gz: f36247fcfeda8c45ded485c60a6a21bc974d8d5e
5
+ SHA512:
6
+ metadata.gz: 286f2c68913ccc062d5a9ac262c06ee20b0c3e4208200ab6780fcfa38600dc5e8da1bbaf71295dfc485637d3025af4a2198b5ffc9b38a36d37aaf465391cee66
7
+ data.tar.gz: 334be18e040db5e4dde2106159eb33f9b2e5cb2c9e2a18431b13cac5db105e16dbf5c08bb21662b8d63e1fd54dc9ae8887ac46e9d295c1a19c2a346a27c581dc
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at tommyskies@hotmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in internet_wisdom.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Tom Johns
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,37 @@
1
+ # InternetWisdom
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'internet-wisdom'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install internet-wisdom
18
+
19
+ ## Usage
20
+
21
+ Run: `internet-wisdom` after installing the gem.
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ 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).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/internet_wisdom. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
32
+
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
37
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "internet_wisdom"
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
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ require "internet_wisdom"
4
+
5
+ InternetWisdom::CLI.new.call
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
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'internet_wisdom/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "internet-wisdom"
8
+ spec.version = InternetWisdom::VERSION
9
+ spec.authors = ["Tom Johns"]
10
+ spec.email = ["tommyskies@hotmail.com"]
11
+
12
+ spec.summary = %q{Internet Wisdom!}
13
+ spec.description = %q{Bits of wisdom from the internet}
14
+ spec.homepage = "https://github.com/tjnz/internet_wisdom"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($\)
18
+ spec.executables = ["internet-wisdom"]
19
+ spec.require_paths = ["lib", "lib/internet_wisdom"]
20
+ spec.required_ruby_version = '>= 1.9.2'
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "pry", ">= 0"
26
+
27
+ spec.add_dependency "launchy", "~> 2.4", ">=2.4.3"
28
+ spec.add_dependency "nokogiri", "~> 1.6", ">= 1.6.7.2"
29
+
30
+
31
+ end
@@ -0,0 +1,14 @@
1
+ require "open-uri"
2
+ require "pry"
3
+ require "nokogiri"
4
+ require "launchy"
5
+
6
+ # requires all files recursively inside a directory from current dir
7
+ # @param _dir can be relative path like '/lib' or "../lib"
8
+ def require_all(_dir)
9
+ Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), _dir)) + "/**/*.rb"].each do |file|
10
+ require file
11
+ end
12
+ end
13
+
14
+ require_all("../lib")
@@ -0,0 +1,74 @@
1
+ class InternetWisdom::CLI
2
+
3
+ BORDER_TOP = "------------------------"
4
+ BORDER_BOT = "------------------------\n"
5
+ INSTRUCTIONS = "Type 'f' to follow a link, 'filter' to apply a site filter, 'help' for help, 'exit' to quit or press 'Enter' to get a new post\n"
6
+
7
+ attr_reader :manager, :current_post, :cur_site, :cur_site_index
8
+
9
+ def call
10
+ @manager = InternetWisdom::SiteManager.new
11
+ @cur_site_index = -1
12
+ puts "\nWELCOME TO INTERNET WISDOM!!!"
13
+ puts INSTRUCTIONS
14
+ get_wisdom
15
+ end
16
+
17
+ def get_wisdom
18
+ cur_site_index < 0 ? @cur_site = manager.sites.sample : @cur_site = manager.sites[cur_site_index]
19
+ display_post(cur_site.get_post)
20
+ end
21
+
22
+ def display_post(post)
23
+ puts BORDER_TOP
24
+ @current_post = post.hash
25
+ post.hash.each do |k, v|
26
+ puts "#{v}"
27
+ end
28
+ puts BORDER_BOT
29
+ get_input
30
+ end
31
+
32
+ def filter_sites
33
+ puts "\nEnter a number below to apply a site filter"
34
+ puts "0. Randomly selects a site (default)"
35
+ manager.sites.each.with_index(1) { |s, i| puts "#{i}. #{s.name}" }
36
+ input = gets.strip.to_i
37
+ if input >= 0 && input <= manager.sites.length
38
+ @cur_site_index = input - 1
39
+ puts "\n"
40
+ input < 1 ? (puts "Choosing wisdom from randomly chosen sites") : (puts "Choosing wisdom from #{manager.sites[cur_site_index].name}")
41
+ get_wisdom
42
+ else
43
+ puts "Invalid entry, try again"
44
+ filter_sites
45
+ end
46
+ end
47
+
48
+ def get_input
49
+ input = nil
50
+ while input != "exit"
51
+ input = gets.strip
52
+ case input
53
+ when 'f'
54
+ Launchy.open(current_post[:link]) if !current_post[:link].nil?
55
+ when 'filter'
56
+ filter_sites
57
+ when 'help'
58
+ display_instructions
59
+ when ""
60
+ get_wisdom
61
+ else
62
+ puts "Command not recognized, type 'help' for instructions" if input != "exit"
63
+ end
64
+ end
65
+ puts "Goodbye"
66
+ exit
67
+ end
68
+
69
+ def display_instructions
70
+ puts INSTRUCTIONS
71
+ get_input
72
+ end
73
+
74
+ end
@@ -0,0 +1,9 @@
1
+ class InternetWisdom::Post
2
+
3
+ attr_accessor :hash
4
+
5
+ def initialize(hash)
6
+ @hash = hash
7
+ end
8
+
9
+ end
@@ -0,0 +1,27 @@
1
+ class InternetWisdom::Site
2
+
3
+ attr_accessor :name, :posts, :is_random, :refresh_method, :page_index
4
+ attr_reader :cur_index
5
+
6
+ def initialize(name, israndom=false)
7
+ @name = name
8
+ @is_random = israndom
9
+ @cur_index = 0
10
+ end
11
+
12
+ def get_post
13
+ if cur_index >= posts.length
14
+ is_random ? refresh! : @cur_index = 0
15
+ end
16
+ @cur_index += 1
17
+ posts[cur_index - 1]
18
+ end
19
+
20
+ def refresh!
21
+ puts "#{name} is refreshing!"
22
+ refresh_method.call(self)
23
+ @cur_index = 0
24
+ self
25
+ end
26
+
27
+ end
@@ -0,0 +1,65 @@
1
+ class InternetWisdom::SiteManager
2
+
3
+ attr_accessor :sites
4
+
5
+ def initialize
6
+ @sites = []
7
+ #debug_scrape
8
+ create_sites
9
+ end
10
+
11
+ def debug_scrape
12
+ puts "DEBUG MODE: Enter a url you wish to scrape"
13
+ url = gets.strip
14
+ doc = Nokogiri::HTML(open(url))
15
+ binding.pry
16
+ end
17
+
18
+ def create_sites
19
+ @sites = [
20
+ create_funtweets,
21
+ create_brainy_quote
22
+ ]
23
+ end
24
+
25
+ def create_funtweets
26
+ funtweets = InternetWisdom::Site.new("FunTweets.com", true)
27
+ funtweets.refresh_method = Proc.new do |site|
28
+ doc = Nokogiri::HTML(open("http://funtweets.com/random"))
29
+ site.posts = doc.search(".tweet").collect do |tweet|
30
+ arr = tweet.search(".tweet-text").text.delete("\r\t").split("\n")
31
+ h = {
32
+ :author => arr[1].strip,
33
+ :text => arr[2].strip,
34
+ :link => "https://twitter.com/#{arr[1].strip}"
35
+ }
36
+ InternetWisdom::Post.new(h)
37
+ end
38
+ end
39
+ funtweets.refresh!
40
+ end
41
+
42
+ def create_brainy_quote
43
+ brainy = InternetWisdom::Site.new("BrainyQuotes.com", true)
44
+ brainy.refresh_method = Proc.new do |site|
45
+ site.page_index = (1..39).to_a.sample
46
+ doc = Nokogiri::HTML(open("http://www.brainyquote.com/quotes/topics/topic_funny#{site.page_index}.html"))
47
+ site.posts = doc.search(".masonryitem").collect do |quote|
48
+ h = {
49
+ :author => quote.search("div.bq-aut a").text,
50
+ :text => quote.search("span.bqQuoteLink a").text,
51
+ :link => "http://www.brainyquote.com#{quote.search("div.bq-aut a").attribute("href").value}"
52
+ }
53
+ InternetWisdom::Post.new(h)
54
+ end
55
+ end
56
+ brainy.refresh!
57
+ end
58
+
59
+
60
+ def refresh_site(site)
61
+ site.refresh!
62
+ end
63
+
64
+
65
+ end
@@ -0,0 +1,3 @@
1
+ module InternetWisdom
2
+ VERSION = "0.1.2"
3
+ end
data/notes.md ADDED
@@ -0,0 +1,21 @@
1
+ Internet wisdom
2
+
3
+ -welcomes
4
+ -show menu cmds
5
+ -retrieve 'wisdom' from the internet
6
+
7
+ 1. Test bin - OK
8
+ 2. Create CLI (tested ok!)
9
+ 3. Create models
10
+ 4. Scrape
11
+ 5. Test!
12
+
13
+
14
+ MODELS
15
+
16
+ Site manager:
17
+ Site
18
+ Posts
19
+ :name, :author, :post, anything
20
+
21
+ refresh! = grab updated info and build it
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe InternetWisdom do
4
+ it 'has a version number' do
5
+ expect(InternetWisdom::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful' do
9
+ expect(false).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'internet_wisdom'
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: internet-wisdom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Tom Johns
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-12 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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: launchy
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.4'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.4.3
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '2.4'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.4.3
89
+ - !ruby/object:Gem::Dependency
90
+ name: nokogiri
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.6'
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 1.6.7.2
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '1.6'
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 1.6.7.2
109
+ description: Bits of wisdom from the internet
110
+ email:
111
+ - tommyskies@hotmail.com
112
+ executables:
113
+ - internet-wisdom
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - ".gitignore"
118
+ - ".rspec"
119
+ - ".travis.yml"
120
+ - CODE_OF_CONDUCT.md
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/internet-wisdom
127
+ - bin/setup
128
+ - internet_wisdom.gemspec
129
+ - lib/internet_wisdom.rb
130
+ - lib/internet_wisdom/cli.rb
131
+ - lib/internet_wisdom/post.rb
132
+ - lib/internet_wisdom/site.rb
133
+ - lib/internet_wisdom/site_manager.rb
134
+ - lib/internet_wisdom/version.rb
135
+ - notes.md
136
+ - spec/internet_wisdom_spec.rb
137
+ - spec/spec_helper.rb
138
+ homepage: https://github.com/tjnz/internet_wisdom
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ - lib/internet_wisdom
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: 1.9.2
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.4.6
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Internet Wisdom!
163
+ test_files: []
164
+ has_rdoc: