rsscache 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/lib/rsscache.rb +45 -45
- data.tar.gz.sig +0 -0
- metadata +35 -30
- 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: fa5b1293b303475b5b3ec84c1f5c0d0f99209a8e00ae6b03ff27d84f11ed7da9
|
4
|
+
data.tar.gz: 298d687c80dc04d790ec63076b02868e10177ac35e8aef1b7c6981905ca5d5ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bce3194dd3df0f6957769e9a4ac6df20f7420007a586a28372869096e638d2a0e1c504fa0391b89e857e470ad982d85e6a324e083f9ae2d5252077e017dd88d7
|
7
|
+
data.tar.gz: 7d38801562845a26c39085a7a1e8ea991af7ec02e0ad014d997bf7c21e39a830a14e04981a11baeb0989ae227823274b085065e43b328e53b95c826f98e68d62
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/rsscache.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
|
3
3
|
# file: rsscache.rb
|
4
4
|
|
5
5
|
require 'dynarex'
|
@@ -10,29 +10,29 @@ require 'timeout'
|
|
10
10
|
|
11
11
|
|
12
12
|
class RSScache
|
13
|
-
|
13
|
+
|
14
14
|
attr_reader :err_report, :dx
|
15
15
|
|
16
|
-
def initialize(rsslist=nil, filepath: '.', debug:
|
16
|
+
def initialize(rsslist=nil, filepath: '.', debug: false)
|
17
17
|
|
18
18
|
rsslist ||= File.join(filepath, 'rsscache.xml')
|
19
19
|
@dx = open_dynarex(rsslist)
|
20
20
|
@filepath = filepath
|
21
21
|
@cache_filepath = File.join(filepath, 'rsscache')
|
22
22
|
FileUtils.mkdir_p @cache_filepath
|
23
|
-
|
23
|
+
|
24
24
|
@err_report = []
|
25
25
|
@debug = debug
|
26
26
|
|
27
27
|
end
|
28
|
-
|
29
|
-
# Import a list of URLs into the Dynarex document.
|
28
|
+
|
29
|
+
# Import a list of URLs into the Dynarex document.
|
30
30
|
# URLs which already exist are ignored.
|
31
31
|
#
|
32
32
|
def import(raw_s)
|
33
|
-
|
33
|
+
|
34
34
|
s, _ = RXFHelper.read(raw_s)
|
35
|
-
|
35
|
+
|
36
36
|
s.strip.lines.each do |raw_url|
|
37
37
|
|
38
38
|
url = raw_url.chomp
|
@@ -45,24 +45,24 @@ class RSScache
|
|
45
45
|
puts 'new URL found' if @debug
|
46
46
|
@dx.create url: url
|
47
47
|
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
51
|
save()
|
52
52
|
end
|
53
53
|
|
54
54
|
# refresh each RSS feed
|
55
55
|
#
|
56
56
|
def refresh
|
57
|
-
|
57
|
+
|
58
58
|
@err_report = []
|
59
59
|
|
60
60
|
puts '@dx.to_xml' + @dx.to_xml(pretty: true) if @debug
|
61
|
-
|
61
|
+
|
62
62
|
@dx.all.each do |feed|
|
63
|
-
|
63
|
+
|
64
64
|
puts 'feed:' + feed.inspect if @debug
|
65
|
-
|
65
|
+
|
66
66
|
if feed.next_refresh.empty? or \
|
67
67
|
Time.now >= Time.parse(feed.next_refresh) then
|
68
68
|
|
@@ -70,7 +70,7 @@ class RSScache
|
|
70
70
|
|
71
71
|
feed.refresh_rate = if feed.refresh_rate.empty? then
|
72
72
|
|
73
|
-
10
|
73
|
+
10
|
74
74
|
|
75
75
|
else
|
76
76
|
|
@@ -91,7 +91,7 @@ class RSScache
|
|
91
91
|
|
92
92
|
end
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
puts '@dx: ' + @dx.to_xml(pretty: true) if @debug
|
96
96
|
save()
|
97
97
|
|
@@ -106,14 +106,14 @@ class RSScache
|
|
106
106
|
|
107
107
|
end
|
108
108
|
|
109
|
-
|
109
|
+
|
110
110
|
private
|
111
|
-
|
111
|
+
|
112
112
|
def raw_doc(s)
|
113
|
-
|
114
|
-
heading = '<?dynarex schema="rsscache[title]/feed(uid, title, ' +
|
113
|
+
|
114
|
+
heading = '<?dynarex schema="rsscache[title]/feed(uid, title, ' +
|
115
115
|
'url, refresh_rate, next_refresh, filename)"?>'
|
116
|
-
|
116
|
+
|
117
117
|
raw_dx=<<EOF
|
118
118
|
#{heading}
|
119
119
|
title: RSS Feeds to be cached
|
@@ -122,32 +122,32 @@ title: RSS Feeds to be cached
|
|
122
122
|
|
123
123
|
#{s.strip.lines.map {|x| 'url: ' + x }.join }
|
124
124
|
EOF
|
125
|
-
|
125
|
+
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
def fetch(url, timeout: 2)
|
129
129
|
|
130
130
|
puts 'inside fetch: url: ' + url.inspect if @debug
|
131
|
-
|
131
|
+
|
132
132
|
begin
|
133
133
|
Timeout::timeout(timeout){
|
134
134
|
|
135
|
-
buffer = open(url).read.force_encoding("utf-8")
|
135
|
+
buffer = URI.open(url).read.force_encoding("utf-8")
|
136
136
|
return [buffer, 200]
|
137
137
|
}
|
138
138
|
rescue Timeout::Error => e
|
139
139
|
['connection timed out', 408]
|
140
140
|
rescue OpenURI::HTTPError => e
|
141
141
|
['400 bad request', 400]
|
142
|
-
end
|
143
|
-
|
142
|
+
end
|
143
|
+
|
144
144
|
end
|
145
|
-
|
145
|
+
|
146
146
|
def open_dynarex(raw_s)
|
147
147
|
|
148
148
|
s, _ = RXFHelper.read(raw_s)
|
149
149
|
puts 'inside open_dynarex s: ' + s.inspect if @debug
|
150
|
-
|
150
|
+
|
151
151
|
case s
|
152
152
|
when /^<?dynarex/
|
153
153
|
Dynarex.new.import s
|
@@ -156,19 +156,19 @@ EOF
|
|
156
156
|
else
|
157
157
|
Dynarex.new.import raw_doc(s)
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
end
|
161
161
|
|
162
|
-
# checks for any updates and save the
|
162
|
+
# checks for any updates and save the
|
163
163
|
# latest RSS file to the cache if there are updates
|
164
|
-
#
|
164
|
+
#
|
165
165
|
def updates?(feed)
|
166
166
|
|
167
167
|
if @debug then
|
168
|
-
puts 'inside updates?'
|
168
|
+
puts 'inside updates?'
|
169
169
|
puts 'feed: ' + feed.inspect
|
170
170
|
end
|
171
|
-
|
171
|
+
|
172
172
|
# fetch the feeds from the web
|
173
173
|
begin
|
174
174
|
buffer, code = fetch(feed.url)
|
@@ -192,13 +192,13 @@ EOF
|
|
192
192
|
end
|
193
193
|
|
194
194
|
if feed.filename.empty? then
|
195
|
-
|
195
|
+
|
196
196
|
filename = feed.url[6..-1].gsub(/\W+/,'').\
|
197
197
|
reverse.slice(0,40).reverse.downcase + '.xml'
|
198
198
|
feed.filename = filename
|
199
199
|
|
200
200
|
end
|
201
|
-
|
201
|
+
|
202
202
|
rssfile = File.join(@cache_filepath, feed.filename)
|
203
203
|
|
204
204
|
if File.exists? rssfile then
|
@@ -207,24 +207,24 @@ EOF
|
|
207
207
|
rss_cache = SimpleRSS.parse File.read(rssfile)
|
208
208
|
rescue
|
209
209
|
puts 'RSScache::updates?: err: 200 SimpleRSS warning for feed ' \
|
210
|
-
+ feed.url + ' ' + ($!).inspect
|
210
|
+
+ feed.url + ' ' + ($!).inspect
|
211
211
|
FileUtils.rm rssfile
|
212
|
-
return false
|
212
|
+
return false
|
213
213
|
end
|
214
214
|
new_rss_items = rss.items - rss_cache.items
|
215
215
|
(File.write rssfile, rss.source; return true) if new_rss_items.any?
|
216
|
-
|
216
|
+
|
217
217
|
else
|
218
218
|
|
219
219
|
File.write rssfile, rss.source
|
220
220
|
feed.title = rss.title if feed.title.empty?
|
221
221
|
|
222
222
|
return true
|
223
|
-
|
223
|
+
|
224
224
|
end
|
225
|
-
|
225
|
+
|
226
226
|
return false
|
227
|
-
end
|
228
|
-
|
229
|
-
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
230
|
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.2.
|
4
|
+
version: 0.2.3
|
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+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hPkbgeiC
|
36
|
+
4DQl3q4AK/bNTpTtJNtNQxts
|
32
37
|
-----END CERTIFICATE-----
|
33
|
-
date:
|
38
|
+
date: 2021-11-18 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.8'
|
42
47
|
- - ">="
|
43
48
|
- !ruby/object:Gem::Version
|
44
|
-
version: 1.
|
49
|
+
version: 1.8.27
|
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.8'
|
52
57
|
- - ">="
|
53
58
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
59
|
+
version: 1.8.27
|
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: []
|
@@ -99,9 +104,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
104
|
version: '0'
|
100
105
|
requirements: []
|
101
106
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.7.10
|
103
108
|
signing_key:
|
104
109
|
specification_version: 4
|
105
|
-
summary: This gem helps reduce
|
110
|
+
summary: This gem helps reduce unnecessary requests to webservers by caching RSS feeds
|
106
111
|
where the RSS feeds are updated infrequently
|
107
112
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|