LoomioScraper 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 26f80f227f0b2648c5e24b967fc86a92d1713b39
4
+ data.tar.gz: eb50e1e0342329233337a0bc219757282ef1bfb8
5
+ SHA512:
6
+ metadata.gz: 603eadccb6b8e1d6a5e60d4b5383b2f24bd14f1ea2237bb266c763ca4aa4903a427f846489c293ec9ce045144cf6a4c50acf635d75b4cd04bdfdae80c8ac7625
7
+ data.tar.gz: 1580b085ff6aa250383fc94eab06762b9d6341daeb9518158ad2faee65088ee6b576672789977c7d4bb1135568afedd0c2e1b6bd96b8055e962588b9fed01068
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /*.gem
11
+ /script.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in LoomioScraper.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Yatish Mehta
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'LoomioScraper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "LoomioScraper"
8
+ spec.version = LoomioScraper::VERSION
9
+ spec.authors = ["RDimon2912"]
10
+ spec.email = ["rdimon2912@gmail.com"]
11
+
12
+ spec.summary = %q{Short summary}
13
+ spec.description = %q{Scraper loomio activity}
14
+ spec.homepage = "https://github.com/rockettron/LoomioScraper"
15
+
16
+ spec.license = "MIT"
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
22
+ f.match(%r{^(test|spec|features)/})
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency "nokogiri", "~> 1.6"
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.13"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ end
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # LoomioScraper
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/LoomioScraper`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ## Installation
6
+
7
+ On your macine must be install phantomjs:
8
+ ```
9
+ sudo apt-get install phantomjs
10
+ ```
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'LoomioScraper'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install LoomioScraper
25
+
26
+ ## Usage
27
+
28
+ You can parse Loomio Activity
29
+ ```ruby
30
+ > activity = LoomioScraper::Activity.new("https://www.loomio.org/d/gEZ5NO1W")
31
+ #=> page load finished
32
+ #=> #<LoomioScraper::Activity:0x00000001413a88..
33
+ > comments = activity.comments
34
+ #=> [{:id=>"1128958", :link=>"/u/yegormukha", :author_name=>"Yegor Mukha", :comment=>"Странные выводы дает автор статьи. \"...
35
+ > activity.to_hash
36
+ #=> {:comments=>[{:id=>"1128958", :link=>"/u/yegormukha", :author_name=>"Yegor Mukha", :comment=>"Странные выводы дает автор статьи. \"...
37
+ ```
38
+
39
+ ## Development
40
+
41
+ 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.
42
+
43
+ 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).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rockettron/LoomioScraper.
48
+
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 "LoomioScraper"
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/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,43 @@
1
+ require_relative "helper"
2
+
3
+ module LoomioScraper
4
+ class Comment < LoomioScraper::Scraper
5
+ def initialize(dom)
6
+ @dom = dom
7
+ @attributes = %w{
8
+ id
9
+ link
10
+ author_name
11
+ comment
12
+ }
13
+ end
14
+
15
+ def id
16
+ @id ||= @dom.at_css('div div')['id'].gsub("comment-", "")
17
+ end
18
+
19
+ def author_name
20
+ @author_name ||= @dom.at_css('.media-body h3').text.strip
21
+ end
22
+
23
+ def link
24
+ @link ||= @dom.at_css('.media-body a')['href']
25
+ end
26
+
27
+ def comment
28
+ @comment ||= @dom.at_css('.thread-item__body').text.strip
29
+ end
30
+ end
31
+
32
+ class Activity < LoomioScraper::Scraper
33
+ def initialize(*attr)
34
+ super(*attr)
35
+ @attributes = %w{ comments }
36
+ end
37
+
38
+ def comments
39
+ @comments ||= @dom.css(".activity-card__activity-list li").map { |comment| Comment.new(comment).to_hash }
40
+ end
41
+ end
42
+ end
43
+ #a = LoomioScraper::Activity.new("https://www.loomio.org/d/gEZ5NO1W")
@@ -0,0 +1,30 @@
1
+ module LoomioScraper
2
+ class Scraper
3
+
4
+ def initialize(url, *args)
5
+ @dom = Scraper.html_loader(url, *args)
6
+ @attributes = []
7
+ end
8
+
9
+ def self.html_loader(url, file = 'index.html')
10
+ # return Nokogiri::HTML(File.open('index.html').read)
11
+
12
+ dom = html = nil
13
+ pid ||= Process.spawn('phantomjs', "lib/LoomioScraper/script.js", url, file)
14
+ Process.waitpid(pid)
15
+
16
+ html ||= File.open(file).read
17
+ File.delete(file)
18
+ dom ||= Nokogiri::HTML(html)
19
+ end
20
+
21
+ def to_hash
22
+ @attributes.reduce({}) { |hash, attr| hash[attr.to_sym] = self.send(attr.to_sym); hash }
23
+ end
24
+
25
+ def attributes
26
+ @attributes
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,15 @@
1
+ var page = require('webpage').create();
2
+ var fs = require('fs');
3
+ var system = require('system');
4
+
5
+
6
+ var link = system.args[1];
7
+ var file = system.args[2] || "index.html";
8
+
9
+ page.open(link);
10
+
11
+ page.onLoadFinished = function() {
12
+ console.log("page load finished");
13
+ fs.write(file, page.content, 'w');
14
+ phantom.exit();
15
+ };
@@ -0,0 +1,3 @@
1
+ module LoomioScraper
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ require "nokogiri"
2
+ require "open-uri"
3
+ require "json"
4
+ require "LoomioScraper/version"
5
+ require "LoomioScraper/activity"
6
+
7
+ module LoomioScraper
8
+ # Your code goes here...
9
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: LoomioScraper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - RDimon2912
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Scraper loomio activity
56
+ email:
57
+ - rdimon2912@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE
65
+ - LoomioScraper.gemspec
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - lib/LoomioScraper.rb
71
+ - lib/LoomioScraper/activity.rb
72
+ - lib/LoomioScraper/helper.rb
73
+ - lib/LoomioScraper/script.js
74
+ - lib/LoomioScraper/version.rb
75
+ homepage: https://github.com/rockettron/LoomioScraper
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.5.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Short summary
99
+ test_files: []