weneedfeed 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +13 -3
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +4 -2
- data/README.md +10 -1
- data/lib/weneedfeed/controllers/show_feed.rb +1 -0
- data/lib/weneedfeed/item.rb +28 -0
- data/lib/weneedfeed/page.rb +4 -0
- data/lib/weneedfeed/page_schema.rb +1 -0
- data/lib/weneedfeed/schema.rb +1 -0
- data/lib/weneedfeed/scraping.rb +4 -0
- data/lib/weneedfeed/version.rb +1 -1
- data/templates/show_feed.xml.erb +3 -0
- data/weneedfeed.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b2041bae9e09565e1b72a4799f8a57034ad73c139de460dc0d187a5b94dbbe2
|
4
|
+
data.tar.gz: 292b45f698fb86f8cd5632687210ab6c09cd74a6d6ad340bb6eb7b989ffc4e3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dc45d743eb961d6a18983b8c20340b1e4c2085c7ed1c348332bddb51c211aa2c5067211e789f9cdd192eb3b161602d63f304adc8421ade49210ce11396a0031
|
7
|
+
data.tar.gz: 60f284ba462f92130a3de4702e33ae3d73418a3057459b40656e75f0a27e8ad9bc8b67946b1137b590f38250d5dec695cdfe41cad58f96947cf0dc0885c2839b
|
data/.github/workflows/test.yml
CHANGED
@@ -7,14 +7,24 @@ on:
|
|
7
7
|
- master
|
8
8
|
|
9
9
|
jobs:
|
10
|
-
|
11
|
-
runs-on: ubuntu-
|
10
|
+
rspec:
|
11
|
+
runs-on: ubuntu-20.04
|
12
12
|
steps:
|
13
13
|
- uses: actions/checkout@v2
|
14
|
+
- uses: ruby/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
bundler-cache: true
|
17
|
+
ruby-version: 2.7.2
|
18
|
+
- run: bundle exec rspec --force-color
|
19
|
+
rubocop:
|
20
|
+
runs-on: ubuntu-20.04
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v2
|
23
|
+
with:
|
24
|
+
ref: ${{ github.event.pull_request.head.sha }}
|
14
25
|
- uses: ruby/setup-ruby@v1
|
15
26
|
with:
|
16
27
|
bundler-cache: true
|
17
28
|
ruby-version: 2.7.2
|
18
29
|
- uses: r7kamura/rubocop-problem-matchers-action@v1
|
19
30
|
- run: bundle exec rubocop --parallel
|
20
|
-
- run: bundle exec rspec --force-color
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
weneedfeed (0.
|
4
|
+
weneedfeed (0.9.0)
|
5
5
|
activesupport
|
6
6
|
builder
|
7
7
|
faraday
|
8
8
|
faraday_middleware
|
9
9
|
hibana (>= 0.2)
|
10
|
+
mimemagic
|
10
11
|
nokogiri
|
11
12
|
rack-capture (>= 0.4.0)
|
12
13
|
thor
|
@@ -44,6 +45,7 @@ GEM
|
|
44
45
|
tilt
|
45
46
|
i18n (1.8.5)
|
46
47
|
concurrent-ruby (~> 1.0)
|
48
|
+
mimemagic (0.3.5)
|
47
49
|
mini_portile2 (2.4.0)
|
48
50
|
minitest (5.14.2)
|
49
51
|
multipart-post (2.1.1)
|
@@ -106,7 +108,7 @@ GEM
|
|
106
108
|
addressable (>= 2.3.6)
|
107
109
|
crack (>= 0.3.2)
|
108
110
|
hashdiff (>= 0.4.0, < 2.0.0)
|
109
|
-
zeitwerk (2.4.
|
111
|
+
zeitwerk (2.4.2)
|
110
112
|
|
111
113
|
PLATFORMS
|
112
114
|
ruby
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ gem install weneedfeed
|
|
27
27
|
|
28
28
|
## Schema
|
29
29
|
|
30
|
-
|
30
|
+
Weneedfeed requires `weneedfeed.yml` that describes URLs and selectors.
|
31
31
|
|
32
32
|
### Example
|
33
33
|
|
@@ -39,6 +39,7 @@ pages:
|
|
39
39
|
url: http://example.com/1
|
40
40
|
item_selector: li
|
41
41
|
item_description_selector: p:nth-child(3)
|
42
|
+
item_image_selector: img
|
42
43
|
item_link_selector: a
|
43
44
|
item_time_selector: time
|
44
45
|
item_title_selector: p:nth-child(2)
|
@@ -47,6 +48,7 @@ pages:
|
|
47
48
|
description: Example feed with XPath
|
48
49
|
url: http://example.com/2
|
49
50
|
item_selector: //li
|
51
|
+
item_image_selector: .//img
|
50
52
|
item_description_selector: .//p[3]
|
51
53
|
item_link_selector: .//a
|
52
54
|
item_time_selector: .//time
|
@@ -109,6 +111,13 @@ CSS or XPath selector to find element with description information in each item.
|
|
109
111
|
- optional
|
110
112
|
- Used for `<description>` in `<item>`.
|
111
113
|
|
114
|
+
### `item_image_selector`
|
115
|
+
|
116
|
+
CSS or XPath selector to find `<img>`element in each item.
|
117
|
+
|
118
|
+
- optional
|
119
|
+
- Used for `<enclosure>` in `<item>`.
|
120
|
+
|
112
121
|
### `item_time_selector`
|
113
122
|
|
114
123
|
CSS or XPath selector to find element with datetime information in each item.
|
@@ -13,6 +13,7 @@ module Weneedfeed
|
|
13
13
|
scraping = ::Weneedfeed::Scraping.new(
|
14
14
|
description: page_schema.description,
|
15
15
|
item_description_selector: page_schema.item_description_selector,
|
16
|
+
item_image_selector: page_schema.item_image_selector,
|
16
17
|
item_link_selector: page_schema.item_link_selector,
|
17
18
|
item_time_selector: page_schema.item_time_selector,
|
18
19
|
item_title_selector: page_schema.item_title_selector,
|
data/lib/weneedfeed/item.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'mimemagic'
|
4
|
+
|
3
5
|
module Weneedfeed
|
4
6
|
class Item
|
5
7
|
class << self
|
@@ -16,6 +18,7 @@ module Weneedfeed
|
|
16
18
|
end
|
17
19
|
|
18
20
|
# @param [String, nil] description_selector
|
21
|
+
# @param [String, nil] image_selector
|
19
22
|
# @param [String, nil] link_selector
|
20
23
|
# @param [Nokogiri::Node] node
|
21
24
|
# @param [String] time_selector
|
@@ -23,6 +26,7 @@ module Weneedfeed
|
|
23
26
|
# @param [String] url
|
24
27
|
def initialize(
|
25
28
|
description_selector:,
|
29
|
+
image_selector:,
|
26
30
|
link_selector:,
|
27
31
|
node:,
|
28
32
|
time_selector:,
|
@@ -30,6 +34,7 @@ module Weneedfeed
|
|
30
34
|
url:
|
31
35
|
)
|
32
36
|
@description_selector = description_selector
|
37
|
+
@image_selector = image_selector
|
33
38
|
@link_selector = link_selector
|
34
39
|
@node = node
|
35
40
|
@time_selector = time_selector
|
@@ -44,6 +49,29 @@ module Weneedfeed
|
|
44
49
|
@node.at(@description_selector)&.inner_html
|
45
50
|
end
|
46
51
|
|
52
|
+
# @return [String, nil]
|
53
|
+
def image_mime_type
|
54
|
+
return unless image_url
|
55
|
+
|
56
|
+
::MimeMagic.by_path(image_url)&.type
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [String, nil]
|
60
|
+
def image_path_or_url
|
61
|
+
return unless @image_selector
|
62
|
+
|
63
|
+
@node.at(@image_selector)&.[]('src')
|
64
|
+
end
|
65
|
+
|
66
|
+
def image_url
|
67
|
+
return unless image_path_or_url
|
68
|
+
|
69
|
+
::URI.join(
|
70
|
+
@url,
|
71
|
+
image_path_or_url
|
72
|
+
).to_s
|
73
|
+
end
|
74
|
+
|
47
75
|
# @return [String]
|
48
76
|
def link
|
49
77
|
::URI.join(
|
data/lib/weneedfeed/page.rb
CHANGED
@@ -13,6 +13,7 @@ module Weneedfeed
|
|
13
13
|
|
14
14
|
# @param [String, nil] description
|
15
15
|
# @param [String, nil] item_description_selector
|
16
|
+
# @param [String, nil] item_image_selector
|
16
17
|
# @param [String] item_link_selector
|
17
18
|
# @param [String, nil] item_time_selector
|
18
19
|
# @param [String] item_title_selector
|
@@ -23,6 +24,7 @@ module Weneedfeed
|
|
23
24
|
def initialize(
|
24
25
|
description:,
|
25
26
|
item_description_selector:,
|
27
|
+
item_image_selector:,
|
26
28
|
item_link_selector:,
|
27
29
|
item_time_selector:,
|
28
30
|
item_title_selector:,
|
@@ -33,6 +35,7 @@ module Weneedfeed
|
|
33
35
|
)
|
34
36
|
@description = description
|
35
37
|
@item_description_selector = item_description_selector
|
38
|
+
@item_image_selector = item_image_selector
|
36
39
|
@item_link_selector = item_link_selector
|
37
40
|
@item_time_selector = item_time_selector
|
38
41
|
@item_title_selector = item_title_selector
|
@@ -47,6 +50,7 @@ module Weneedfeed
|
|
47
50
|
@node.search(@item_selector).map do |node|
|
48
51
|
::Weneedfeed::Item.new(
|
49
52
|
description_selector: @item_description_selector,
|
53
|
+
image_selector: @item_image_selector,
|
50
54
|
link_selector: @item_link_selector,
|
51
55
|
node: node,
|
52
56
|
time_selector: @item_time_selector,
|
data/lib/weneedfeed/schema.rb
CHANGED
@@ -27,6 +27,7 @@ module Weneedfeed
|
|
27
27
|
description: hash['description'],
|
28
28
|
id: hash['id'],
|
29
29
|
item_description_selector: hash['item_description_selector'],
|
30
|
+
item_image_selector: hash['item_image_selector'],
|
30
31
|
item_link_selector: hash['item_link_selector'],
|
31
32
|
item_time_selector: hash['item_time_selector'],
|
32
33
|
item_title_selector: hash['item_title_selector'],
|
data/lib/weneedfeed/scraping.rb
CHANGED
@@ -16,6 +16,7 @@ module Weneedfeed
|
|
16
16
|
|
17
17
|
# @param [String, nil] description
|
18
18
|
# @param [String, nil] item_description_selector
|
19
|
+
# @param [String, nil] item_image_selector
|
19
20
|
# @param [String] item_link_selector
|
20
21
|
# @param [String, nil] item_time_selector
|
21
22
|
# @param [String] item_title_selector
|
@@ -25,6 +26,7 @@ module Weneedfeed
|
|
25
26
|
def initialize(
|
26
27
|
description:,
|
27
28
|
item_description_selector:,
|
29
|
+
item_image_selector:,
|
28
30
|
item_link_selector:,
|
29
31
|
item_time_selector:,
|
30
32
|
item_title_selector:,
|
@@ -34,6 +36,7 @@ module Weneedfeed
|
|
34
36
|
)
|
35
37
|
@description = description
|
36
38
|
@item_description_selector = item_description_selector
|
39
|
+
@item_image_selector = item_image_selector
|
37
40
|
@item_link_selector = item_link_selector
|
38
41
|
@item_time_selector = item_time_selector
|
39
42
|
@item_title_selector = item_title_selector
|
@@ -48,6 +51,7 @@ module Weneedfeed
|
|
48
51
|
description: @description,
|
49
52
|
node: parsed_body,
|
50
53
|
item_description_selector: @item_description_selector,
|
54
|
+
item_image_selector: @item_image_selector,
|
51
55
|
item_selector: @item_selector,
|
52
56
|
item_link_selector: @item_link_selector,
|
53
57
|
item_time_selector: @item_time_selector,
|
data/lib/weneedfeed/version.rb
CHANGED
data/templates/show_feed.xml.erb
CHANGED
@@ -18,6 +18,9 @@
|
|
18
18
|
<description><![CDATA[<%= item.description %>]]></description>
|
19
19
|
<content:encoded><![CDATA[<%= item.description %>]]></content:encoded>
|
20
20
|
<guid isPermaLink="true"><%= item.link %></guid>
|
21
|
+
<% if item.image_url %>
|
22
|
+
<enclosure url="<%= item.image_url %>" length="0" type="<%= item.image_mime_type %>"/>
|
23
|
+
<% end %>
|
21
24
|
</item>
|
22
25
|
<% end %>
|
23
26
|
</channel>
|
data/weneedfeed.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_runtime_dependency 'faraday'
|
31
31
|
spec.add_runtime_dependency 'faraday_middleware'
|
32
32
|
spec.add_runtime_dependency 'hibana', '>= 0.2'
|
33
|
+
spec.add_runtime_dependency 'mimemagic'
|
33
34
|
spec.add_runtime_dependency 'nokogiri'
|
34
35
|
spec.add_runtime_dependency 'rack-capture', '>= 0.4.0'
|
35
36
|
spec.add_runtime_dependency 'thor'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weneedfeed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mimemagic
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: nokogiri
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|