comment_seeker 0.0.0 → 0.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: adc11c829aac6356b50ed13aa5d174623145a392
4
- data.tar.gz: cf1910c9b110c0febddd98b2aad9e07ff102354e
3
+ metadata.gz: b9c604080330c41f6484b960f6492bd9b0471850
4
+ data.tar.gz: 17cd88e5fe9cf96f7d596a92be8061c3391aafec
5
5
  SHA512:
6
- metadata.gz: 907fad9d922c69fa51e52874da4a9850158a713989a966425458452185aaa9623629800092ebe817c77973d078378d5ebade0bcd877090b50ad414df8445a8f5
7
- data.tar.gz: 8c6f968ef99294169bd970df3d2e469322423641407ae2813ab95b760cea0a28440ac127a91d9ede65d1c2bd50749224608f100578602f6228fd4482cb567737
6
+ metadata.gz: 6c7de06bfb71b1d745836f366f47c19c1e8380721c832a1c9974ab62ec943c8b9fa62b5ecce87fe62aca0977b99aa90aa3b71720b30ca5a946a2916e83ebd9f7
7
+ data.tar.gz: 3358b1db96e7cd82cc85279a956870cef9fb1c04e0af99a2e566e5678a50fdfb8f23c3933d2a11f0c0344f2b112a3bb5157cf6e8832cc29a6f98e0cf603c4fbb
@@ -2,33 +2,38 @@ require 'mechanize'
2
2
 
3
3
  class CommentSeeker
4
4
 
5
+ def initialize
6
+ @comment_search_pattern = CommentSearch.new.pattern
7
+ end
8
+
5
9
  def seek(query)
6
10
  commentable_pages = []
11
+
7
12
  # Create a new instance of Mechanize and grab our page
8
13
  uri = "https://www.google.fr/search?q=" + CGI.escape(query)
9
14
  agent = Mechanize.new
10
15
  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|
16
+ result_links(result_page).each do |link|
15
17
  page = link.click
16
18
  commentable_pages << page if is_commentable?(page)
17
19
  end
18
20
  end
21
+ commentable_pages
19
22
  end
20
23
 
21
- def comment_search_pattern
22
- patterns = [
23
- "Laisser un commentaire",
24
- "Ecrire un commentaire",
25
- "Post Comment"
26
- ]
27
- Regexp.union(patterns)
24
+ private
25
+
26
+ attr_reader :comment_search_pattern
27
+
28
+ def result_links(result_page)
29
+ result_page.links.find_all { |l| l.attributes.parent.name == 'h3' }
28
30
  end
29
-
31
+
30
32
  def is_commentable?(page)
31
33
  content = page.parser
32
34
  content.at('body').text =~ comment_search_pattern
33
35
  end
36
+
34
37
  end
38
+
39
+ require_relative 'comment_seeker/comment_search'
@@ -0,0 +1,26 @@
1
+ class CommentSearch
2
+
3
+ attr_reader :pattern
4
+
5
+ def initialize
6
+ patterns = [
7
+ "Ecrire un commentaire",
8
+ "Laisser un commentaire",
9
+ "Publier un commentaire",
10
+ "Envoyer un commentaire",
11
+ "Ajouter un commentaire",
12
+ "Postez le commentaire",
13
+ "Réagir",
14
+ "Je commente",
15
+ "Vos réactions",
16
+ "Commentez cet article",
17
+ "Se connecter et publier",
18
+ "Réagir à cet article",
19
+ "Laisser une réponse",
20
+ "Leave a reply",
21
+ "Facebook comment",
22
+ "Post comment"
23
+ ]
24
+ @pattern = Regexp.new(Regexp.union(patterns).source, Regexp::IGNORECASE)
25
+ end
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comment_seeker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Baptiste Goulain
@@ -9,7 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2013-10-26 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mechanize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.7'
13
27
  description: A simple gem to query a keyword and retrieve pages on which you could
14
28
  add comments.
15
29
  email: jibai31@gmail.com
@@ -18,9 +32,9 @@ extensions: []
18
32
  extra_rdoc_files: []
19
33
  files:
20
34
  - lib/comment_seeker.rb
21
- homepage: http://rubygems.org/gems/comment_seeker
22
- licenses:
23
- - none
35
+ - lib/comment_seeker/comment_search.rb
36
+ homepage: https://github.com/jibai31/comment_seeker
37
+ licenses: []
24
38
  metadata: {}
25
39
  post_install_message:
26
40
  rdoc_options: []