rsscache 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/rsscache.rb +85 -47
- metadata +1 -1
- metadata.gz.sig +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13d621b5f6fada69a9b0d44f228f5a109114ae5b
|
4
|
+
data.tar.gz: 2f3b4b9553374db248914d72b8f6e2e612559c9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a38232230077fb48b0eb518883f90e23d48410e0603c4af46db6401558f73c9093239100525f3812733f1cdd19fcba1be9a3892fbf25b48fe92f90c79ee381f9
|
7
|
+
data.tar.gz: 54febc9ada04ee92d908fb02110187b8bd70053b4aa0a7e96e8b190d54a0c487d7a8934fe5ad28fe83721eb63e8a5f64bd832773ea9be22fef5e15b384783322
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/rsscache.rb
CHANGED
@@ -11,13 +11,15 @@ require 'timeout'
|
|
11
11
|
|
12
12
|
class RSScache
|
13
13
|
|
14
|
-
attr_reader :err_report
|
14
|
+
attr_reader :err_report, :dx
|
15
15
|
|
16
|
-
def initialize(rsslist,
|
16
|
+
def initialize(rsslist=nil, filepath: '.', debug: true)
|
17
17
|
|
18
|
+
rsslist ||= File.join(filepath, 'rsscache.xml')
|
18
19
|
@dx = open_dynarex(rsslist)
|
19
|
-
@
|
20
|
-
|
20
|
+
@filepath = filepath
|
21
|
+
@cache_filepath = File.join(filepath, 'rsscache')
|
22
|
+
FileUtils.mkdir_p @cache_filepath
|
21
23
|
|
22
24
|
@err_report = []
|
23
25
|
@debug = debug
|
@@ -46,7 +48,7 @@ class RSScache
|
|
46
48
|
|
47
49
|
end
|
48
50
|
|
49
|
-
|
51
|
+
save()
|
50
52
|
end
|
51
53
|
|
52
54
|
# refresh each RSS feed
|
@@ -89,43 +91,77 @@ class RSScache
|
|
89
91
|
|
90
92
|
end
|
91
93
|
end
|
94
|
+
|
92
95
|
puts '@dx: ' + @dx.to_xml(pretty: true) if @debug
|
93
|
-
|
96
|
+
save()
|
94
97
|
|
95
98
|
end
|
96
99
|
|
97
100
|
alias update refresh
|
98
101
|
|
99
|
-
def
|
102
|
+
def save()
|
100
103
|
|
101
|
-
|
102
|
-
|
103
|
-
Dynarex.new.import x
|
104
|
-
else
|
105
|
-
Dynarex.new x
|
106
|
-
end
|
107
|
-
end
|
104
|
+
@dx.save File.join(@filepath, 'rsscache.xml')
|
105
|
+
File.write File.join(@filepath, 'rsscache.txt'), @dx.to_s
|
108
106
|
|
109
|
-
|
110
|
-
|
111
|
-
if @rsslist.lines.length == 1 and File.exists?(@rsslist)
|
107
|
+
end
|
112
108
|
|
113
|
-
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def raw_doc(s)
|
113
|
+
|
114
|
+
heading = '<?dynarex schema="rsscache[title]/feed(uid, title, ' +
|
115
|
+
'url, refresh_rate, next_refresh, filename)"?>'
|
116
|
+
|
117
|
+
raw_dx=<<EOF
|
118
|
+
#{heading}
|
119
|
+
title: RSS Feeds to be cached
|
114
120
|
|
115
|
-
|
121
|
+
--+
|
116
122
|
|
117
|
-
|
123
|
+
#{s.strip.lines.map {|x| 'url: ' + x }.join }
|
124
|
+
EOF
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
def fetch(url, timeout: 2)
|
118
129
|
|
119
|
-
|
130
|
+
puts 'inside fetch: url: ' + url.inspect if @debug
|
131
|
+
|
132
|
+
begin
|
133
|
+
Timeout::timeout(timeout){
|
120
134
|
|
121
|
-
|
135
|
+
buffer = 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]
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
def open_dynarex(raw_s)
|
122
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)
|
123
158
|
end
|
159
|
+
|
124
160
|
end
|
125
161
|
|
126
|
-
# checks for any updates and
|
127
|
-
#
|
128
|
-
#
|
162
|
+
# checks for any updates and save the
|
163
|
+
# latest RSS file to the cache if there are updates
|
164
|
+
#
|
129
165
|
def updates?(feed)
|
130
166
|
|
131
167
|
if @debug then
|
@@ -134,10 +170,22 @@ class RSScache
|
|
134
170
|
end
|
135
171
|
|
136
172
|
# fetch the feeds from the web
|
137
|
-
|
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
|
138
180
|
|
139
181
|
if code == 200 then
|
140
|
-
|
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
|
141
189
|
else
|
142
190
|
@err_report << [feed.url, code]
|
143
191
|
return false
|
@@ -151,11 +199,18 @@ class RSScache
|
|
151
199
|
|
152
200
|
end
|
153
201
|
|
154
|
-
rssfile = File.join(@
|
202
|
+
rssfile = File.join(@cache_filepath, feed.filename)
|
155
203
|
|
156
204
|
if File.exists? rssfile then
|
157
205
|
|
158
|
-
|
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
|
159
214
|
new_rss_items = rss.items - rss_cache.items
|
160
215
|
(File.write rssfile, rss.source; return true) if new_rss_items.any?
|
161
216
|
|
@@ -169,24 +224,7 @@ class RSScache
|
|
169
224
|
end
|
170
225
|
|
171
226
|
return false
|
172
|
-
end
|
173
|
-
|
174
|
-
private
|
227
|
+
end
|
175
228
|
|
176
|
-
def fetch(url, timeout: 2)
|
177
|
-
|
178
|
-
begin
|
179
|
-
Timeout::timeout(timeout){
|
180
|
-
|
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
229
|
|
192
230
|
end
|
metadata
CHANGED
metadata.gz.sig
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
�XTa��
|
2
|
+
Bϴڨ�r�Sջ�B�jM�+Z<SezH0*%cb���n�����_�Y�2�K�M�֭�����*��
|
3
|
+
�'���������f,���w��7�W!��}�d�8]�g�q����(Ñ�iۗM��tm�=�"e�Sh�č��s�|�
|