rsscache 0.2.2 → 0.3.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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data/lib/rsscache.rb +56 -55
- data.tar.gz.sig +0 -0
- metadata +35 -31
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3df82ccc1d24e4e666502ebd898c00c61128f20917f96a169f466cc593b5944f
|
4
|
+
data.tar.gz: 1ad412e71d760f5409feaa2f2f42a6df6316b71491e3951de3aa691b635c477b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fb8b0761eaeb24ca6c3807a005a4b9e21d26a099d3e33e3e6f79e36f6cdd1bd6f270bb9ba4b0f2275f752bcff217a62505d882d6f79ad36dd37fa02d36533a5
|
7
|
+
data.tar.gz: 83ad0da6b90ec7f4feb6f9485baa594310bad384df5a330e17175ac78a2a28bc728b16e6be7e8afbc99bb33afb1e58073c2b6c12fdd2e653663e800fc6266d0d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/rsscache.rb
CHANGED
@@ -1,38 +1,39 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
|
3
3
|
# file: rsscache.rb
|
4
4
|
|
5
5
|
require 'dynarex'
|
6
6
|
require 'open-uri'
|
7
7
|
require 'simple-rss'
|
8
|
-
require 'fileutils'
|
9
8
|
require 'timeout'
|
9
|
+
require 'rxfreadwrite'
|
10
10
|
|
11
11
|
|
12
12
|
class RSScache
|
13
|
-
|
13
|
+
include RXFReadWriteModule
|
14
|
+
|
14
15
|
attr_reader :err_report, :dx
|
15
16
|
|
16
|
-
def initialize(rsslist=nil, filepath: '.', debug:
|
17
|
+
def initialize(rsslist=nil, filepath: '.', debug: false)
|
17
18
|
|
18
19
|
rsslist ||= File.join(filepath, 'rsscache.xml')
|
19
20
|
@dx = open_dynarex(rsslist)
|
20
21
|
@filepath = filepath
|
21
22
|
@cache_filepath = File.join(filepath, 'rsscache')
|
22
|
-
|
23
|
-
|
23
|
+
FileX.mkdir_p @cache_filepath
|
24
|
+
|
24
25
|
@err_report = []
|
25
26
|
@debug = debug
|
26
27
|
|
27
28
|
end
|
28
|
-
|
29
|
-
# Import a list of URLs into the Dynarex document.
|
29
|
+
|
30
|
+
# Import a list of URLs into the Dynarex document.
|
30
31
|
# URLs which already exist are ignored.
|
31
32
|
#
|
32
33
|
def import(raw_s)
|
33
|
-
|
34
|
-
s, _ =
|
35
|
-
|
34
|
+
|
35
|
+
s, _ = RXFReader.read(raw_s)
|
36
|
+
|
36
37
|
s.strip.lines.each do |raw_url|
|
37
38
|
|
38
39
|
url = raw_url.chomp
|
@@ -45,24 +46,24 @@ class RSScache
|
|
45
46
|
puts 'new URL found' if @debug
|
46
47
|
@dx.create url: url
|
47
48
|
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
49
|
+
|
50
|
+
end
|
51
|
+
|
51
52
|
save()
|
52
53
|
end
|
53
54
|
|
54
55
|
# refresh each RSS feed
|
55
56
|
#
|
56
57
|
def refresh
|
57
|
-
|
58
|
+
|
58
59
|
@err_report = []
|
59
60
|
|
60
61
|
puts '@dx.to_xml' + @dx.to_xml(pretty: true) if @debug
|
61
|
-
|
62
|
+
|
62
63
|
@dx.all.each do |feed|
|
63
|
-
|
64
|
+
|
64
65
|
puts 'feed:' + feed.inspect if @debug
|
65
|
-
|
66
|
+
|
66
67
|
if feed.next_refresh.empty? or \
|
67
68
|
Time.now >= Time.parse(feed.next_refresh) then
|
68
69
|
|
@@ -70,7 +71,7 @@ class RSScache
|
|
70
71
|
|
71
72
|
feed.refresh_rate = if feed.refresh_rate.empty? then
|
72
73
|
|
73
|
-
10
|
74
|
+
10
|
74
75
|
|
75
76
|
else
|
76
77
|
|
@@ -91,7 +92,7 @@ class RSScache
|
|
91
92
|
|
92
93
|
end
|
93
94
|
end
|
94
|
-
|
95
|
+
|
95
96
|
puts '@dx: ' + @dx.to_xml(pretty: true) if @debug
|
96
97
|
save()
|
97
98
|
|
@@ -102,18 +103,18 @@ class RSScache
|
|
102
103
|
def save()
|
103
104
|
|
104
105
|
@dx.save File.join(@filepath, 'rsscache.xml')
|
105
|
-
|
106
|
+
FileX.write File.join(@filepath, 'rsscache.txt'), @dx.to_s
|
106
107
|
|
107
108
|
end
|
108
109
|
|
109
|
-
|
110
|
+
|
110
111
|
private
|
111
|
-
|
112
|
+
|
112
113
|
def raw_doc(s)
|
113
|
-
|
114
|
-
heading = '<?dynarex schema="rsscache[title]/feed(uid, title, ' +
|
114
|
+
|
115
|
+
heading = '<?dynarex schema="rsscache[title]/feed(uid, title, ' +
|
115
116
|
'url, refresh_rate, next_refresh, filename)"?>'
|
116
|
-
|
117
|
+
|
117
118
|
raw_dx=<<EOF
|
118
119
|
#{heading}
|
119
120
|
title: RSS Feeds to be cached
|
@@ -122,32 +123,32 @@ title: RSS Feeds to be cached
|
|
122
123
|
|
123
124
|
#{s.strip.lines.map {|x| 'url: ' + x }.join }
|
124
125
|
EOF
|
125
|
-
|
126
|
+
|
126
127
|
end
|
127
|
-
|
128
|
+
|
128
129
|
def fetch(url, timeout: 2)
|
129
130
|
|
130
131
|
puts 'inside fetch: url: ' + url.inspect if @debug
|
131
|
-
|
132
|
+
|
132
133
|
begin
|
133
134
|
Timeout::timeout(timeout){
|
134
135
|
|
135
|
-
buffer = open(url).read.force_encoding("utf-8")
|
136
|
+
buffer = URI.open(url).read.force_encoding("utf-8")
|
136
137
|
return [buffer, 200]
|
137
138
|
}
|
138
139
|
rescue Timeout::Error => e
|
139
140
|
['connection timed out', 408]
|
140
141
|
rescue OpenURI::HTTPError => e
|
141
142
|
['400 bad request', 400]
|
142
|
-
end
|
143
|
-
|
143
|
+
end
|
144
|
+
|
144
145
|
end
|
145
|
-
|
146
|
+
|
146
147
|
def open_dynarex(raw_s)
|
147
148
|
|
148
|
-
s, _ =
|
149
|
+
s, _ = RXFReader.read(raw_s)
|
149
150
|
puts 'inside open_dynarex s: ' + s.inspect if @debug
|
150
|
-
|
151
|
+
|
151
152
|
case s
|
152
153
|
when /^<?dynarex/
|
153
154
|
Dynarex.new.import s
|
@@ -156,19 +157,19 @@ EOF
|
|
156
157
|
else
|
157
158
|
Dynarex.new.import raw_doc(s)
|
158
159
|
end
|
159
|
-
|
160
|
+
|
160
161
|
end
|
161
162
|
|
162
|
-
# checks for any updates and save the
|
163
|
+
# checks for any updates and save the
|
163
164
|
# latest RSS file to the cache if there are updates
|
164
|
-
#
|
165
|
+
#
|
165
166
|
def updates?(feed)
|
166
167
|
|
167
168
|
if @debug then
|
168
|
-
puts 'inside updates?'
|
169
|
+
puts 'inside updates?'
|
169
170
|
puts 'feed: ' + feed.inspect
|
170
171
|
end
|
171
|
-
|
172
|
+
|
172
173
|
# fetch the feeds from the web
|
173
174
|
begin
|
174
175
|
buffer, code = fetch(feed.url)
|
@@ -192,39 +193,39 @@ EOF
|
|
192
193
|
end
|
193
194
|
|
194
195
|
if feed.filename.empty? then
|
195
|
-
|
196
|
+
|
196
197
|
filename = feed.url[6..-1].gsub(/\W+/,'').\
|
197
198
|
reverse.slice(0,40).reverse.downcase + '.xml'
|
198
199
|
feed.filename = filename
|
199
200
|
|
200
201
|
end
|
201
|
-
|
202
|
+
|
202
203
|
rssfile = File.join(@cache_filepath, feed.filename)
|
203
204
|
|
204
|
-
if
|
205
|
+
if FileX.exists? rssfile then
|
205
206
|
|
206
207
|
begin
|
207
|
-
rss_cache = SimpleRSS.parse
|
208
|
+
rss_cache = SimpleRSS.parse FileX.read(rssfile)
|
208
209
|
rescue
|
209
210
|
puts 'RSScache::updates?: err: 200 SimpleRSS warning for feed ' \
|
210
|
-
+ feed.url + ' ' + ($!).inspect
|
211
|
-
|
212
|
-
return false
|
211
|
+
+ feed.url + ' ' + ($!).inspect
|
212
|
+
FileX.rm rssfile
|
213
|
+
return false
|
213
214
|
end
|
214
215
|
new_rss_items = rss.items - rss_cache.items
|
215
|
-
(
|
216
|
-
|
216
|
+
(FileX.write rssfile, rss.source; return true) if new_rss_items.any?
|
217
|
+
|
217
218
|
else
|
218
219
|
|
219
|
-
|
220
|
+
FileX.write rssfile, rss.source
|
220
221
|
feed.title = rss.title if feed.title.empty?
|
221
222
|
|
222
223
|
return true
|
223
|
-
|
224
|
+
|
224
225
|
end
|
225
|
-
|
226
|
+
|
226
227
|
return false
|
227
|
-
end
|
228
|
-
|
229
|
-
|
228
|
+
end
|
229
|
+
|
230
|
+
|
230
231
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsscache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,27 +10,32 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjExMTE4MTk1NDM3WhcN
|
15
|
+
MjIxMTE4MTk1NDM3WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZX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+
VOZ/0X3SqdOgrhagTMsjDnz7ssiP/H6hIAoFBhF7D3X+Vavo6wMhSwGMoeFmQh67
|
32
|
+
CUipnJc6MBLlq8AxZcTYhulLOxTjefUxpbPxLV+pubf9xyG4rjkpv7lMap6wENLS
|
33
|
+
KzCP36ihBrIbQ6QFi1stEPDDXMNiIYbT4liyv1Ij0VUfnhZ8XtdlTrDzTeTQ2JjA
|
34
|
+
RAxFbgUVr0H2AyzRphwLN5UUUGYhsZOS4G+ObMbXYFHTDBlJBj0GIYi7yt48E6FE
|
35
|
+
G9akldSLDKgsN9vmwihdlnktMrNa8HUDxodpx5FFzXDsza/qaExLHJA4hPkbgeiC
|
36
|
+
4DQl3q4AK/bNTpTtJNtNQxts
|
32
37
|
-----END CERTIFICATE-----
|
33
|
-
date:
|
38
|
+
date: 2022-03-11 00:00:00.000000000 Z
|
34
39
|
dependencies:
|
35
40
|
- !ruby/object:Gem::Dependency
|
36
41
|
name: dynarex
|
@@ -38,20 +43,20 @@ dependencies:
|
|
38
43
|
requirements:
|
39
44
|
- - "~>"
|
40
45
|
- !ruby/object:Gem::Version
|
41
|
-
version: '1.
|
46
|
+
version: '1.9'
|
42
47
|
- - ">="
|
43
48
|
- !ruby/object:Gem::Version
|
44
|
-
version: 1.
|
49
|
+
version: 1.9.8
|
45
50
|
type: :runtime
|
46
51
|
prerelease: false
|
47
52
|
version_requirements: !ruby/object:Gem::Requirement
|
48
53
|
requirements:
|
49
54
|
- - "~>"
|
50
55
|
- !ruby/object:Gem::Version
|
51
|
-
version: '1.
|
56
|
+
version: '1.9'
|
52
57
|
- - ">="
|
53
58
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
59
|
+
version: 1.9.8
|
55
60
|
- !ruby/object:Gem::Dependency
|
56
61
|
name: simple-rss
|
57
62
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,7 +66,7 @@ dependencies:
|
|
61
66
|
version: '1.3'
|
62
67
|
- - ">="
|
63
68
|
- !ruby/object:Gem::Version
|
64
|
-
version: 1.3.
|
69
|
+
version: 1.3.3
|
65
70
|
type: :runtime
|
66
71
|
prerelease: false
|
67
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -71,9 +76,9 @@ dependencies:
|
|
71
76
|
version: '1.3'
|
72
77
|
- - ">="
|
73
78
|
- !ruby/object:Gem::Version
|
74
|
-
version: 1.3.
|
79
|
+
version: 1.3.3
|
75
80
|
description:
|
76
|
-
email:
|
81
|
+
email: digital.robertson@gmail.com
|
77
82
|
executables: []
|
78
83
|
extensions: []
|
79
84
|
extra_rdoc_files: []
|
@@ -98,10 +103,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
103
|
- !ruby/object:Gem::Version
|
99
104
|
version: '0'
|
100
105
|
requirements: []
|
101
|
-
|
102
|
-
rubygems_version: 2.6.13
|
106
|
+
rubygems_version: 3.2.22
|
103
107
|
signing_key:
|
104
108
|
specification_version: 4
|
105
|
-
summary: This gem helps reduce
|
109
|
+
summary: This gem helps reduce unnecessary requests to webservers by caching RSS feeds
|
106
110
|
where the RSS feeds are updated infrequently
|
107
111
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|