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