curation 1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2127e0e8cd5eecb8611891be3ba3ddf434dab8e1c172eb2b4f2aaffa7ffa21e4
4
+ data.tar.gz: d0b84333c2e85798b4ac9d809d5e7a49b1fab0f9d2de2a88109ca9305ffbb2e6
5
+ SHA512:
6
+ metadata.gz: b99857abd7cf08f321140261c00c613324209a2af09b668bc994a3a52704b2eef67d1986d6950a6347af5a093ef5e6174a5ddb486d7e6fe432de7402a33c01ab
7
+ data.tar.gz: 9dd921943b36746d21b55943ddb9105a6d20043a3de284d14da98bb0d5a97dce84f99649d2329f038393ae1b1c0c7d1e72f5a915f109955538c6d222e3388c9e
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at contact@arnaudlevy.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in curation.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ curation (0.1.0)
5
+ metainspector
6
+ nokogiri
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ domain_name (0.5.20190701)
14
+ unf (>= 0.0.5, < 1.0.0)
15
+ faraday (1.0.1)
16
+ multipart-post (>= 1.2, < 3)
17
+ faraday-cookie_jar (0.0.6)
18
+ faraday (>= 0.7.4)
19
+ http-cookie (~> 1.0.0)
20
+ faraday-encoding (0.0.5)
21
+ faraday
22
+ faraday-http-cache (2.2.0)
23
+ faraday (>= 0.8)
24
+ faraday_middleware (1.0.0)
25
+ faraday (~> 1.0)
26
+ fastimage (2.1.7)
27
+ http-cookie (1.0.3)
28
+ domain_name (~> 0.5)
29
+ metainspector (5.10.1)
30
+ addressable (~> 2.7.0)
31
+ faraday (~> 1.0.0)
32
+ faraday-cookie_jar (~> 0.0.6)
33
+ faraday-encoding (~> 0.0.5)
34
+ faraday-http-cache (~> 2.2.0)
35
+ faraday_middleware (~> 1.0.0)
36
+ fastimage (~> 2.1.7)
37
+ nesty (~> 1.0.2)
38
+ nokogiri (~> 1.10.9)
39
+ mini_portile2 (2.4.0)
40
+ multipart-post (2.1.1)
41
+ nesty (1.0.2)
42
+ nokogiri (1.10.10)
43
+ mini_portile2 (~> 2.4.0)
44
+ public_suffix (4.0.5)
45
+ rake (12.3.3)
46
+ unf (0.1.4)
47
+ unf_ext
48
+ unf_ext (0.0.7.7)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ curation!
55
+ rake (~> 12.0)
56
+
57
+ BUNDLED WITH
58
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Arnaud Levy
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.
@@ -0,0 +1,49 @@
1
+ # Curation
2
+
3
+ When you build content curation tools, you need to extract the content of pages (title, text, image...). This requires different strategies and some fine tuning to work efficiently.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'curation'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install curation
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ page = Curation::Page.new url
25
+ article = Article.new
26
+ article.title = page.title
27
+ article.text = page.text
28
+ article.image = page.image
29
+ article.save
30
+ ```
31
+
32
+ ## Development
33
+
34
+ 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.
35
+
36
+ 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).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/curation. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/curation/blob/master/CODE_OF_CONDUCT.md).
41
+
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
46
+
47
+ ## Code of Conduct
48
+
49
+ Everyone interacting in the Curation project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/curation/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "curation"
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(__FILE__)
@@ -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,26 @@
1
+ require_relative 'lib/curation/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "curation"
5
+ spec.version = Curation::VERSION
6
+ spec.authors = ["Arnaud Levy"]
7
+ spec.email = ["contact@arnaudlevy.com"]
8
+
9
+ spec.summary = 'Curation of content'
10
+ spec.description = %q{When you build content curation tools, you need to extract the content of pages (title, text, image...). This requires different strategies and some fine tuning to work efficiently.}
11
+ spec.homepage = "https://github.com/arnaudlevy/curation"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/arnaudlevy/curation"
17
+
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+ spec.add_dependency "metainspector"
25
+ spec.add_dependency "nokogiri"
26
+ end
@@ -0,0 +1,134 @@
1
+ require "curation/version"
2
+ require "metainspector"
3
+ require "open-uri"
4
+
5
+ module Curation
6
+ class Error < StandardError; end
7
+
8
+ class Page
9
+ attr_reader :url, :title, :text, :image
10
+
11
+ BLACKLIST = [
12
+ 'head', 'script', 'style', 'iframe', 'nav', 'noscript', 'header', 'footer', 'aside',
13
+ '.navigation', '.top-menu-container', '.navbar', '.navbar-header', '.breadcrumb',
14
+ '#breadcrumbs', '[typeof="v:Breadcrumb"]', '.skip-link', '.search', '.search-form',
15
+ '.categories', '.post-categories', '.datas', '.post-datas', '.twitter-media',
16
+ '.instagram-media', '.widget', '.related-post-tags', '.social-list', '.top-scroll',
17
+ '.comments', '.signature', '.publicite', '.footer', '.Footer', '.footer-copyright',
18
+ '[itemprop*="author"]', '[style*="display:none;"]', '[style*="display:none"]',
19
+ '[style*="display: none;"]', '[style*="display: none"]', '[aria-hidden="true"]'
20
+ ]
21
+
22
+ def initialize(url, html = nil)
23
+ @url = url
24
+ @html = html
25
+ end
26
+
27
+ def title
28
+ @title = find_title
29
+ end
30
+
31
+ def image
32
+ @image = find_image
33
+ @image = @image.to_s.gsub('http://', 'https://')
34
+ @image
35
+ end
36
+
37
+ def text
38
+ if json_ld.any?
39
+ json_ld.each do |ld|
40
+ next unless ld['@type'] == 'NewsArticle'
41
+ return ld['text'] if ld.has_key? 'text'
42
+ return ld['articleBody'] if ld.has_key? 'articleBody'
43
+ end
44
+ end
45
+ h = nokogiri.dup
46
+ BLACKLIST.each do |tag|
47
+ h.css(tag).remove
48
+ end
49
+ nodes = h.css('p')
50
+ nodes.xpath('//style').remove
51
+ text = nodes.to_html
52
+ text.gsub!('<br><br>', '<br>')
53
+ text
54
+ end
55
+
56
+ protected
57
+
58
+ def find_title
59
+ if json_ld.any?
60
+ json_ld.each do |ld|
61
+ return ld['headline'] if ld.has_key? 'headline'
62
+ end
63
+ end
64
+ [
65
+ metainspector.best_title,
66
+ metainspector.title,
67
+ nokogiri.css('[itemprop="headline"]').first.inner_text,
68
+ nokogiri.css('title').first.inner_text
69
+ ].each do |possibility|
70
+ return possibility unless possibility.blank?
71
+ end
72
+ return ''
73
+ end
74
+
75
+ def find_image
76
+ if json_ld.any?
77
+ json_ld.each do |ld|
78
+ if ld.has_key? 'image'
79
+ image_data = ld['image']
80
+ return image_data if image_data.is_a? String
81
+ if image_data.is_a? Array
82
+ first = image_data.first
83
+ return first if first.is_a? String
84
+ return first['url'] if first.is_a? Hash
85
+ end
86
+ return image_data['url'] if image_data.is_a? Hash
87
+ end
88
+ end
89
+ end
90
+ [
91
+ metainspector.images.best,
92
+ nokogiri.css('[property="og:image"]').first&.attributes["content"].value
93
+ ].each do |possibility|
94
+ return possibility unless possibility.blank?
95
+ end
96
+ return ''
97
+ end
98
+
99
+ def json_ld
100
+ unless @json_ld
101
+ @json_ld = []
102
+ begin
103
+ options = nokogiri.css('[type="application/ld+json"]')
104
+ options.each do |option|
105
+ string = option.inner_text
106
+ hash = JSON.parse(string)
107
+ @json_ld << hash
108
+ end
109
+ rescue
110
+ puts "JSON LD error"
111
+ end
112
+ end
113
+ @json_ld
114
+ end
115
+
116
+ def html
117
+ @html ||= URI.open url
118
+ rescue
119
+ puts "Impossible to open #{url}"
120
+ end
121
+
122
+ def nokogiri
123
+ @nokogiri ||= Nokogiri::HTML html
124
+ rescue
125
+ puts "Nokogiri error"
126
+ end
127
+
128
+ def metainspector
129
+ @metainspector ||= MetaInspector.new url, document: html
130
+ rescue
131
+ puts "MetaInspector error"
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,3 @@
1
+ module Curation
2
+ VERSION = "1.3"
3
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: curation
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.3'
5
+ platform: ruby
6
+ authors:
7
+ - Arnaud Levy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: metainspector
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: When you build content curation tools, you need to extract the content
42
+ of pages (title, text, image...). This requires different strategies and some fine
43
+ tuning to work efficiently.
44
+ email:
45
+ - contact@arnaudlevy.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - CODE_OF_CONDUCT.md
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - bin/console
58
+ - bin/setup
59
+ - curation.gemspec
60
+ - lib/curation.rb
61
+ - lib/curation/version.rb
62
+ homepage: https://github.com/arnaudlevy/curation
63
+ licenses:
64
+ - MIT
65
+ metadata:
66
+ homepage_uri: https://github.com/arnaudlevy/curation
67
+ source_code_uri: https://github.com/arnaudlevy/curation
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 2.3.0
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.0.3
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Curation of content
87
+ test_files: []