rsscache 0.2.1 → 0.3.0
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 +109 -70
- 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: d7b8a75b9f765464f14794c0c83f576de028b66d3bd676cfcad0cbe146b2544d
|
4
|
+
data.tar.gz: 955f0ce59bd22e3974b95df6a19cd59e1a7cdcaaa0b269e8db33cd706db64eef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2113381445334a113e6461dd977ee58b0a382811f1454fca0cab627431945e4af1f813127d9fcf5381eb7dd1e0700581193e7daa00eb6706cad5e4b77509b0e
|
7
|
+
data.tar.gz: 4f745332d263530b6087ab344b0bdedbeff9d5eb59203fe94a8d589c377839050657dbfa5bb0f5fdeafc659e55630690c2b00d2aaac71bb048e2549e0ab703da
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/rsscache.rb
CHANGED
@@ -1,36 +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
|
-
|
14
|
-
|
13
|
+
include RXFReadWrite
|
14
|
+
|
15
|
+
attr_reader :err_report, :dx
|
15
16
|
|
16
|
-
def initialize(rsslist,
|
17
|
+
def initialize(rsslist=nil, filepath: '.', debug: false)
|
17
18
|
|
19
|
+
rsslist ||= File.join(filepath, 'rsscache.xml')
|
18
20
|
@dx = open_dynarex(rsslist)
|
19
|
-
@
|
20
|
-
|
21
|
-
|
21
|
+
@filepath = filepath
|
22
|
+
@cache_filepath = File.join(filepath, 'rsscache')
|
23
|
+
FileX.mkdir_p @cache_filepath
|
24
|
+
|
22
25
|
@err_report = []
|
23
26
|
@debug = debug
|
24
27
|
|
25
28
|
end
|
26
|
-
|
27
|
-
# Import a list of URLs into the Dynarex document.
|
29
|
+
|
30
|
+
# Import a list of URLs into the Dynarex document.
|
28
31
|
# URLs which already exist are ignored.
|
29
32
|
#
|
30
33
|
def import(raw_s)
|
31
|
-
|
32
|
-
s, _ =
|
33
|
-
|
34
|
+
|
35
|
+
s, _ = RXFReader.read(raw_s)
|
36
|
+
|
34
37
|
s.strip.lines.each do |raw_url|
|
35
38
|
|
36
39
|
url = raw_url.chomp
|
@@ -43,24 +46,24 @@ class RSScache
|
|
43
46
|
puts 'new URL found' if @debug
|
44
47
|
@dx.create url: url
|
45
48
|
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
save()
|
50
53
|
end
|
51
54
|
|
52
55
|
# refresh each RSS feed
|
53
56
|
#
|
54
57
|
def refresh
|
55
|
-
|
58
|
+
|
56
59
|
@err_report = []
|
57
60
|
|
58
61
|
puts '@dx.to_xml' + @dx.to_xml(pretty: true) if @debug
|
59
|
-
|
62
|
+
|
60
63
|
@dx.all.each do |feed|
|
61
|
-
|
64
|
+
|
62
65
|
puts 'feed:' + feed.inspect if @debug
|
63
|
-
|
66
|
+
|
64
67
|
if feed.next_refresh.empty? or \
|
65
68
|
Time.now >= Time.parse(feed.next_refresh) then
|
66
69
|
|
@@ -68,7 +71,7 @@ class RSScache
|
|
68
71
|
|
69
72
|
feed.refresh_rate = if feed.refresh_rate.empty? then
|
70
73
|
|
71
|
-
10
|
74
|
+
10
|
72
75
|
|
73
76
|
else
|
74
77
|
|
@@ -89,104 +92,140 @@ class RSScache
|
|
89
92
|
|
90
93
|
end
|
91
94
|
end
|
95
|
+
|
92
96
|
puts '@dx: ' + @dx.to_xml(pretty: true) if @debug
|
93
|
-
|
97
|
+
save()
|
94
98
|
|
95
99
|
end
|
96
100
|
|
97
101
|
alias update refresh
|
98
102
|
|
99
|
-
def
|
103
|
+
def save()
|
104
|
+
|
105
|
+
@dx.save File.join(@filepath, 'rsscache.xml')
|
106
|
+
FileX.write File.join(@filepath, 'rsscache.txt'), @dx.to_s
|
100
107
|
|
101
|
-
if x.lines.length == 1 and File.exists?(x) and \
|
102
|
-
File.extname(x) == '.txt' then
|
103
|
-
Dynarex.new.import x
|
104
|
-
else
|
105
|
-
Dynarex.new x
|
106
|
-
end
|
107
108
|
end
|
108
109
|
|
109
|
-
def save_dynarex()
|
110
110
|
|
111
|
-
|
111
|
+
private
|
112
112
|
|
113
|
-
|
113
|
+
def raw_doc(s)
|
114
114
|
|
115
|
-
|
115
|
+
heading = '<?dynarex schema="rsscache[title]/feed(uid, title, ' +
|
116
|
+
'url, refresh_rate, next_refresh, filename)"?>'
|
116
117
|
|
117
|
-
|
118
|
+
raw_dx=<<EOF
|
119
|
+
#{heading}
|
120
|
+
title: RSS Feeds to be cached
|
118
121
|
|
119
|
-
|
122
|
+
--+
|
120
123
|
|
121
|
-
|
124
|
+
#{s.strip.lines.map {|x| 'url: ' + x }.join }
|
125
|
+
EOF
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
def fetch(url, timeout: 2)
|
122
130
|
|
131
|
+
puts 'inside fetch: url: ' + url.inspect if @debug
|
132
|
+
|
133
|
+
begin
|
134
|
+
Timeout::timeout(timeout){
|
135
|
+
|
136
|
+
buffer = URI.open(url).read.force_encoding("utf-8")
|
137
|
+
return [buffer, 200]
|
138
|
+
}
|
139
|
+
rescue Timeout::Error => e
|
140
|
+
['connection timed out', 408]
|
141
|
+
rescue OpenURI::HTTPError => e
|
142
|
+
['400 bad request', 400]
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
def open_dynarex(raw_s)
|
148
|
+
|
149
|
+
s, _ = RXFReader.read(raw_s)
|
150
|
+
puts 'inside open_dynarex s: ' + s.inspect if @debug
|
151
|
+
|
152
|
+
case s
|
153
|
+
when /^<?dynarex/
|
154
|
+
Dynarex.new.import s
|
155
|
+
when /^</
|
156
|
+
Dynarex.new s
|
157
|
+
else
|
158
|
+
Dynarex.new.import raw_doc(s)
|
123
159
|
end
|
160
|
+
|
124
161
|
end
|
125
162
|
|
126
|
-
# checks for any updates and
|
127
|
-
#
|
163
|
+
# checks for any updates and save the
|
164
|
+
# latest RSS file to the cache if there are updates
|
128
165
|
#
|
129
166
|
def updates?(feed)
|
130
167
|
|
131
168
|
if @debug then
|
132
|
-
puts 'inside updates?'
|
169
|
+
puts 'inside updates?'
|
133
170
|
puts 'feed: ' + feed.inspect
|
134
171
|
end
|
135
|
-
|
172
|
+
|
136
173
|
# fetch the feeds from the web
|
137
|
-
|
174
|
+
begin
|
175
|
+
buffer, code = fetch(feed.url)
|
176
|
+
rescue
|
177
|
+
puts 'RSScache::updates?: fetch() warning for feed ' + feed.url \
|
178
|
+
+ ' ' + ($!).inspect
|
179
|
+
return
|
180
|
+
end
|
138
181
|
|
139
182
|
if code == 200 then
|
140
|
-
|
183
|
+
begin
|
184
|
+
rss = SimpleRSS.parse(buffer)
|
185
|
+
rescue
|
186
|
+
puts 'RSScache::updates?: err: 100 SimpleRSS warning for feed ' \
|
187
|
+
+ feed.url + ' ' + ($!).inspect
|
188
|
+
return
|
189
|
+
end
|
141
190
|
else
|
142
191
|
@err_report << [feed.url, code]
|
143
192
|
return false
|
144
193
|
end
|
145
194
|
|
146
195
|
if feed.filename.empty? then
|
147
|
-
|
196
|
+
|
148
197
|
filename = feed.url[6..-1].gsub(/\W+/,'').\
|
149
198
|
reverse.slice(0,40).reverse.downcase + '.xml'
|
150
199
|
feed.filename = filename
|
151
200
|
|
152
201
|
end
|
153
|
-
|
154
|
-
rssfile = File.join(@feedsfilepath, feed.filename)
|
155
202
|
|
156
|
-
|
203
|
+
rssfile = File.join(@cache_filepath, feed.filename)
|
204
|
+
|
205
|
+
if FileX.exists? rssfile then
|
157
206
|
|
158
|
-
|
207
|
+
begin
|
208
|
+
rss_cache = SimpleRSS.parse FileX.read(rssfile)
|
209
|
+
rescue
|
210
|
+
puts 'RSScache::updates?: err: 200 SimpleRSS warning for feed ' \
|
211
|
+
+ feed.url + ' ' + ($!).inspect
|
212
|
+
FileX.rm rssfile
|
213
|
+
return false
|
214
|
+
end
|
159
215
|
new_rss_items = rss.items - rss_cache.items
|
160
|
-
(
|
161
|
-
|
216
|
+
(FileX.write rssfile, rss.source; return true) if new_rss_items.any?
|
217
|
+
|
162
218
|
else
|
163
219
|
|
164
|
-
|
220
|
+
FileX.write rssfile, rss.source
|
165
221
|
feed.title = rss.title if feed.title.empty?
|
166
222
|
|
167
223
|
return true
|
168
|
-
|
224
|
+
|
169
225
|
end
|
170
|
-
|
226
|
+
|
171
227
|
return false
|
172
228
|
end
|
173
|
-
|
174
|
-
private
|
175
|
-
|
176
|
-
def fetch(url, timeout: 2)
|
177
229
|
|
178
|
-
begin
|
179
|
-
Timeout::timeout(timeout){
|
180
230
|
|
181
|
-
buffer = open(url).read
|
182
|
-
return [buffer, 200]
|
183
|
-
}
|
184
|
-
rescue Timeout::Error => e
|
185
|
-
['connection timed out', 408]
|
186
|
-
rescue OpenURI::HTTPError => e
|
187
|
-
['400 bad request', 400]
|
188
|
-
end
|
189
|
-
|
190
|
-
end
|
191
|
-
|
192
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.0
|
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
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDl/WSn
|
17
|
+
rif0WGHmqi3lDo4hCKqsnTvQJFFBoYyGPd8nQPrXd1D6+o0B8qbihDaayk0itqVF
|
18
|
+
MAZpErc/X7G49/DsFHsCIggXezeu52Pjwos99kGla6qJoPUwP9uC4SMbUXrbfDOD
|
19
|
+
ONtkhEscM1vjZWfQketPUXxEpoQjQAgvEWP6JJ1wHIKf8zuxGgnOqXeyeMmI92sm
|
20
|
+
8zOo/Tph2scpEePy8LMxj1t7WY2IKnHAjVI2bwv0t4iqzoBTGArsoKFa9CJvlEPn
|
21
|
+
KC+XCfbOyPHDYZ9rMp1VjuzE73FNvLaZyemytRITy/xZcnCRJuQJ1M5lmG1k7VGo
|
22
|
+
h12tG5hepRnU+y5eYbc7locMlm+BA0zJO6h76O16ssTXdPGmWIx0bqvH+tnE3Y1p
|
23
|
+
ge/EpMmSPaY4DwpCrUOVB2lXkWEvCTxaEUfigbro+tNnGrlolMLzYunGh/rIPwf6
|
24
|
+
JlPQofTjBLEZZ4HnvsZrcpDbKg1UAJ8DRKuGMO8vW3+SIluXMoDfkDSornsCAwEA
|
25
|
+
AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUMZkI563V
|
26
|
+
qEbcdqMHGxFBtvTHazwwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
|
27
|
+
c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
|
28
|
+
BgkqhkiG9w0BAQsFAAOCAYEAGq7ekyOf3MP2SWidstI5qt1pOcyY0IsjJbU9KWiS
|
29
|
+
K9mCa3DxPks6EFHswXTEBb91S/523He3iHw3XIx0wNgDycH6/hxXoylhG37He/RG
|
30
|
+
UZVIYjs7TaVqHpslQkGcO0/tGXzQ35mooF8XiB88l08sBiEunZU3quCwG0ja6A0V
|
31
|
+
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-02-22 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.5
|
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.5
|
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
|