comment_seeker 0.0.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/comment_seeker.rb +34 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: adc11c829aac6356b50ed13aa5d174623145a392
4
+ data.tar.gz: cf1910c9b110c0febddd98b2aad9e07ff102354e
5
+ SHA512:
6
+ metadata.gz: 907fad9d922c69fa51e52874da4a9850158a713989a966425458452185aaa9623629800092ebe817c77973d078378d5ebade0bcd877090b50ad414df8445a8f5
7
+ data.tar.gz: 8c6f968ef99294169bd970df3d2e469322423641407ae2813ab95b760cea0a28440ac127a91d9ede65d1c2bd50749224608f100578602f6228fd4482cb567737
@@ -0,0 +1,34 @@
1
+ require 'mechanize'
2
+
3
+ class CommentSeeker
4
+
5
+ def seek(query)
6
+ commentable_pages = []
7
+ # Create a new instance of Mechanize and grab our page
8
+ uri = "https://www.google.fr/search?q=" + CGI.escape(query)
9
+ agent = Mechanize.new
10
+ agent.get(uri) do |result_page|
11
+ # Find all the links on the page
12
+ result_links = result_page.links.find_all { |l| l.attributes.parent.name == 'h3' }
13
+
14
+ result_links.each do |link|
15
+ page = link.click
16
+ commentable_pages << page if is_commentable?(page)
17
+ end
18
+ end
19
+ end
20
+
21
+ def comment_search_pattern
22
+ patterns = [
23
+ "Laisser un commentaire",
24
+ "Ecrire un commentaire",
25
+ "Post Comment"
26
+ ]
27
+ Regexp.union(patterns)
28
+ end
29
+
30
+ def is_commentable?(page)
31
+ content = page.parser
32
+ content.at('body').text =~ comment_search_pattern
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: comment_seeker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jean-Baptiste Goulain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple gem to query a keyword and retrieve pages on which you could
14
+ add comments.
15
+ email: jibai31@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/comment_seeker.rb
21
+ homepage: http://rubygems.org/gems/comment_seeker
22
+ licenses:
23
+ - none
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.0.3
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Find pages where you can add comments
45
+ test_files: []