curation 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/curation.gemspec +26 -0
- data/lib/curation.rb +111 -0
- data/lib/curation/version.rb +3 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0f56e1c572c081875ce6e71608496d64a3d34ef84837c60e15c06e358ab0af44
|
4
|
+
data.tar.gz: e7b3899aee83e21bad48c59b68d15d792cebdf9c84b95c24012d4329a3de08cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a71487cae498b7f04e028f7e6f71793e08047bddefc28e8e3700167c5bf1734cccdd5972a997cd30b07d9c69a2ebb86c4e744e9c32f63a3f0b7c75ba23bf92ef
|
7
|
+
data.tar.gz: b33659760a649ff74aff8fcb821b28d073d4324ce671f1cb737107d4515043de5916d7315a385dfa0cb2517de177aa39f745f3aaad95149339cb4cd116b8cb52
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
data/Gemfile.lock
ADDED
@@ -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
|
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -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).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -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__)
|
data/bin/setup
ADDED
data/curation.gemspec
ADDED
@@ -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
|
data/lib/curation.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require "curation/version"
|
2
|
+
|
3
|
+
module Curation
|
4
|
+
class Error < StandardError; end
|
5
|
+
|
6
|
+
class Page
|
7
|
+
attr_reader :url, :title, :text, :image
|
8
|
+
|
9
|
+
BLACKLIST = [
|
10
|
+
'head', 'script', 'style', 'iframe', 'nav', 'noscript', 'header', 'footer', 'aside',
|
11
|
+
'.navigation', '.top-menu-container', '.navbar', '.navbar-header', '.breadcrumb',
|
12
|
+
'#breadcrumbs', '[typeof="v:Breadcrumb"]', '.skip-link', '.search', '.search-form',
|
13
|
+
'.categories', '.post-categories', '.datas', '.post-datas', '.twitter-media',
|
14
|
+
'.instagram-media', '.widget', '.related-post-tags', '.social-list', '.top-scroll',
|
15
|
+
'.comments', '.signature', '.publicite', '.footer', '.Footer', '.footer-copyright',
|
16
|
+
'[itemprop*="author"]', '[style*="display:none;"]', '[style*="display:none"]',
|
17
|
+
'[style*="display: none;"]', '[style*="display: none"]', '[aria-hidden="true"]'
|
18
|
+
]
|
19
|
+
|
20
|
+
def initialize(url)
|
21
|
+
@url = url
|
22
|
+
end
|
23
|
+
|
24
|
+
def title
|
25
|
+
if json_ld.any?
|
26
|
+
json_ld.each do |ld|
|
27
|
+
return ld['headline'] if ld.has_key? 'headline'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
metainspector.best_title
|
31
|
+
end
|
32
|
+
|
33
|
+
def image
|
34
|
+
@image = find_image
|
35
|
+
@image = @image.gsub('http://', 'https://')
|
36
|
+
@image
|
37
|
+
end
|
38
|
+
|
39
|
+
def text
|
40
|
+
if json_ld.any?
|
41
|
+
json_ld.each do |ld|
|
42
|
+
next unless ld['@type'] == 'NewsArticle'
|
43
|
+
return ld['text'] if ld.has_key? 'text'
|
44
|
+
return ld['articleBody'] if ld.has_key? 'articleBody'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
text = ''
|
48
|
+
h = html.dup
|
49
|
+
BLACKLIST.each do |tag|
|
50
|
+
h.css(tag).remove
|
51
|
+
end
|
52
|
+
nodes = h.css('p')
|
53
|
+
nodes.xpath('//style').remove
|
54
|
+
text = nodes.to_html
|
55
|
+
text.gsub!('<br><br>', '<br>')
|
56
|
+
text
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
|
61
|
+
def find_image
|
62
|
+
if json_ld.any?
|
63
|
+
json_ld.each do |ld|
|
64
|
+
if ld.has_key? 'image'
|
65
|
+
image_data = ld['image']
|
66
|
+
return image_data if image_data.is_a? String
|
67
|
+
return image_data.first if image_data.is_a? Array
|
68
|
+
return image_data['url'] if image_data.is_a? Hash
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
metainspector.images.best
|
73
|
+
end
|
74
|
+
|
75
|
+
def html
|
76
|
+
@html ||= Nokogiri::HTML data
|
77
|
+
rescue
|
78
|
+
puts "Nokogiri error"
|
79
|
+
end
|
80
|
+
|
81
|
+
def json_ld
|
82
|
+
unless @json_ld
|
83
|
+
@json_ld = []
|
84
|
+
begin
|
85
|
+
options = html.css('[type="application/ld+json"]')
|
86
|
+
options.each do |option|
|
87
|
+
string = option.inner_text
|
88
|
+
hash = JSON.parse(string)
|
89
|
+
@json_ld << hash
|
90
|
+
end
|
91
|
+
rescue
|
92
|
+
puts "JSON LD error"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
@json_ld
|
96
|
+
end
|
97
|
+
|
98
|
+
def data
|
99
|
+
require 'open-uri'
|
100
|
+
URI.open url
|
101
|
+
rescue
|
102
|
+
puts "Impossible to open #{url}"
|
103
|
+
end
|
104
|
+
|
105
|
+
def metainspector
|
106
|
+
@metainspector ||= MetaInspector.new url
|
107
|
+
rescue
|
108
|
+
puts "MetaInspector error"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: curation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arnaud Levy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-20 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: []
|