liveblog 0.9.0 → 0.9.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/liveblog.rb +103 -86
- metadata +2 -2
- metadata.gz.sig +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a535773752c869700d81744cdb4d70246def089c
|
4
|
+
data.tar.gz: c6180a6a1833f4525c31b87d51d4172acd1e73c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8f8e87cf159c0227e3afeb662416807957c5d0370aff95b3c61f81b2b512b7b1fcf2f3162021f9d325d2ee48cb17c3b64f8e179b3ef5c6e47c9793d29090760
|
7
|
+
data.tar.gz: 1c0ecc6cb5648956190cb83767853cef2b4de1c3b50940422e476341969f67f3c9442b839626462197d90ee34a1ad369e6904e622034f2a92adfc54c3ae4b42a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/liveblog.rb
CHANGED
@@ -13,12 +13,11 @@ class LiveBlog
|
|
13
13
|
|
14
14
|
# the config can either be a hash, a config filepath, or nil
|
15
15
|
#
|
16
|
-
def initialize(config: nil)
|
17
|
-
|
18
|
-
|
19
|
-
config = if config then
|
16
|
+
def initialize(x=nil, config: nil)
|
17
|
+
|
18
|
+
config = if x or config then
|
20
19
|
|
21
|
-
config
|
20
|
+
x || config
|
22
21
|
else
|
23
22
|
|
24
23
|
if File.exists? 'liveblog.conf' then
|
@@ -33,10 +32,12 @@ class LiveBlog
|
|
33
32
|
h = SimpleConfig.new(config).to_h
|
34
33
|
|
35
34
|
dir, @urlbase, @edit_url, @css_url, @xsl_path, \
|
36
|
-
|
37
|
-
%i(dir urlbase edit_url css_url xsl_path xsl_url bannertext
|
38
|
-
|
35
|
+
@xsl_url, @bannertext, @title, @rss_title, @rss_lang = \
|
36
|
+
(%i(dir urlbase edit_url css_url xsl_path xsl_url bannertext)\
|
37
|
+
+ %i(title rss_title rss_lang)).map{|x| h[x]}
|
39
38
|
|
39
|
+
@title ||= 'LiveBlog'
|
40
|
+
@rss_lang ||= 'en-gb'
|
40
41
|
|
41
42
|
Dir.chdir dir
|
42
43
|
|
@@ -59,19 +60,19 @@ class LiveBlog
|
|
59
60
|
|
60
61
|
def add_entry(raw_entry)
|
61
62
|
|
62
|
-
entry, hashtag = raw_entry.split(/\s
|
63
|
+
entry, hashtag = raw_entry.split(/\s*#(?=\w+$)/)
|
63
64
|
hashtag.downcase!
|
64
65
|
|
65
66
|
success, msg = case raw_entry
|
66
67
|
|
67
68
|
when /^#\s*\w.*#\w+$/ then
|
68
69
|
|
69
|
-
add_section raw_entry
|
70
|
+
add_section raw_entry, hashtag
|
70
71
|
|
71
72
|
when /#\w+$/ then
|
72
73
|
|
73
74
|
entry.gsub!(/(?:^|\s)!t\s/, '\1' + time())
|
74
|
-
add_section_entry entry, hashtag
|
75
|
+
add_section_entry entry, hashtag
|
75
76
|
|
76
77
|
else
|
77
78
|
[false, 'no valid entry found']
|
@@ -90,6 +91,12 @@ class LiveBlog
|
|
90
91
|
[true, message]
|
91
92
|
end
|
92
93
|
|
94
|
+
# returns a RecordX object for a given hashtag
|
95
|
+
#
|
96
|
+
def find_hashtag(hashtag)
|
97
|
+
@dx.find hashtag[/\w+$/]
|
98
|
+
end
|
99
|
+
|
93
100
|
# Use with yesterday's liveblog;
|
94
101
|
#
|
95
102
|
def link_today()
|
@@ -107,10 +114,10 @@ class LiveBlog
|
|
107
114
|
end
|
108
115
|
|
109
116
|
def new_file(s=nil)
|
110
|
-
|
117
|
+
|
111
118
|
s ||= <<EOF
|
112
119
|
<?dynarex schema="sections[title]/section(x)"?>
|
113
|
-
title:
|
120
|
+
title: #{@title} #{ordinalize(@d.day) + @d.strftime(" %B %Y")}
|
114
121
|
--#
|
115
122
|
|
116
123
|
EOF
|
@@ -141,7 +148,6 @@ EOF
|
|
141
148
|
|
142
149
|
@dx = Dynarex.new
|
143
150
|
@dx.import s
|
144
|
-
@dx.default_key = 'uid'
|
145
151
|
|
146
152
|
save()
|
147
153
|
|
@@ -149,71 +155,21 @@ EOF
|
|
149
155
|
|
150
156
|
alias import new_file
|
151
157
|
|
152
|
-
def
|
153
|
-
|
154
|
-
buffer = File.read File.join(path(), 'raw_formatted.xml')
|
155
|
-
doc = Rexle.new buffer
|
156
|
-
|
157
|
-
summary = doc.root.element 'summary'
|
158
|
-
|
159
|
-
dx = Dynarex.new 'liveblog[title,desc,link, pubdate, '\
|
160
|
-
+ 'lastbuild_date, lang]/entry(title, desc, created_at, uri, guid)'
|
161
|
-
|
162
|
-
dx.title = @rss_title || 'LiveBlog'
|
163
|
-
dx.desc = 'Latest LiveBlog posts fetched from ' + @urlbase
|
164
|
-
dx.link = @urlbase
|
165
|
-
dx.order = 'descending'
|
166
|
-
dx.pubdate = rss_timestamp(summary.text('published'))
|
167
|
-
dx.lastbuild_date = Time.now.strftime("%a, %-d %b %Y %H:%M:%S %Z")
|
168
|
-
dx.lang = 'en-gb'
|
169
|
-
|
170
|
-
doc.root.xpath('records/section/section/details').each do |x|
|
171
|
-
|
172
|
-
a = x.elements.to_a
|
173
|
-
h1 = a.shift.element('h1')
|
174
|
-
hashtag = h1.text[/#\w+$/]
|
175
|
-
created_at = rss_timestamp(h1.attributes[:created])
|
176
|
-
|
177
|
-
a.each do |node|
|
178
|
-
|
179
|
-
node.attributes.delete :created
|
180
|
-
node.attributes.delete :last_modified
|
181
|
-
|
182
|
-
node.traverse do |x|
|
183
|
-
|
184
|
-
x.attributes.delete :created
|
185
|
-
x.attributes.delete :last_modified
|
186
|
-
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
uri = doc.root.element('summary/link/text()') + hashtag
|
191
|
-
|
192
|
-
record = {
|
193
|
-
title: h1.text,
|
194
|
-
desc: a.map(&:xml).join("\n"),
|
195
|
-
created_at: created_at,
|
196
|
-
uri: uri,
|
197
|
-
guid: uri
|
198
|
-
}
|
199
|
-
|
200
|
-
dx.create record
|
201
|
-
end
|
202
|
-
|
203
|
-
dx.xslt_schema = 'channel[title:title,description:desc,link:link,'\
|
204
|
-
+ 'pubDate:pubdate,lastBuildDate:lastbuild_date,language:lang]/'\
|
205
|
-
+ 'item(title:title,link:uri,description:desc,pubDate:created_at,'\
|
206
|
-
+ 'guid:guid)'
|
207
|
-
File.write 'rss.xml', dx.to_rss
|
158
|
+
def save()
|
208
159
|
|
209
|
-
|
160
|
+
@dx.save File.join(path(), 'index.xml')
|
161
|
+
File.write File.join(path(), 'index.txt'), @dx.to_s
|
162
|
+
save_html()
|
163
|
+
save_rss()
|
164
|
+
end
|
165
|
+
|
210
166
|
|
211
167
|
private
|
212
168
|
|
213
169
|
|
214
170
|
def add_section_entry(raw_entry, hashtag)
|
215
171
|
|
216
|
-
rec = @dx.
|
172
|
+
rec = @dx.find hashtag
|
217
173
|
|
218
174
|
return [false, 'rec not found'] unless rec
|
219
175
|
|
@@ -221,9 +177,9 @@ EOF
|
|
221
177
|
[true, 'entry added to section ' + hashtag]
|
222
178
|
end
|
223
179
|
|
224
|
-
def add_section(raw_entry)
|
180
|
+
def add_section(raw_entry, hashtag)
|
225
181
|
|
226
|
-
@dx.create({x: raw_entry.sub(/(#\w+)$/){|x| x.downcase}})
|
182
|
+
@dx.create({x: raw_entry.sub(/(#\w+)$/){|x| x.downcase}}, hashtag.downcase)
|
227
183
|
[true, 'section added']
|
228
184
|
end
|
229
185
|
|
@@ -239,14 +195,22 @@ EOF
|
|
239
195
|
xsl_path: File.join(dir, 'liveblog.xsl'),
|
240
196
|
xsl_url: '/liveblog/liveblog.xsl',
|
241
197
|
bannertext: '',
|
242
|
-
|
198
|
+
title: "John Smith's LiveBlog",
|
199
|
+
rss_title: "John Smith's LiveBlog",
|
200
|
+
rss_lang: 'en_gb'
|
243
201
|
}
|
244
202
|
end
|
245
203
|
|
204
|
+
# returns an array with a fractured date in the format [YYYY,mmm,dd]
|
205
|
+
# e.g. #=> ['2015','apr','11']
|
206
|
+
#
|
246
207
|
def path(d=@d)
|
247
208
|
[d.year.to_s, Date::MONTHNAMES[d.month].downcase[0..2], d.day.to_s]
|
248
209
|
end
|
249
|
-
|
210
|
+
|
211
|
+
# returns a string representing a date within a directory path
|
212
|
+
# e.g. #=> 2015/apr/11/
|
213
|
+
#
|
250
214
|
def urlpath(d=@d)
|
251
215
|
path(d).join('/') + '/'
|
252
216
|
end
|
@@ -254,16 +218,7 @@ EOF
|
|
254
218
|
def static_urlpath(d=@d)
|
255
219
|
@urlbase.sub(/[^\/]$/,'\0/') + urlpath(d)
|
256
220
|
end
|
257
|
-
|
258
|
-
|
259
|
-
def save()
|
260
|
-
|
261
|
-
@dx.save File.join(path(), 'index.xml')
|
262
|
-
File.write File.join(path(), 'index.txt'), @dx.to_s
|
263
|
-
save_html()
|
264
|
-
save_rss()
|
265
|
-
end
|
266
|
-
|
221
|
+
|
267
222
|
def save_html()
|
268
223
|
|
269
224
|
formatted2_filepath = File.join(path(), 'formatted2.xml')
|
@@ -278,6 +233,7 @@ EOF
|
|
278
233
|
add summary, 'edit_url', "%s/%s" % [@edit_url, urlpath()]
|
279
234
|
add summary, 'date', @d.strftime("%d-%b-%Y").upcase
|
280
235
|
add summary, 'day', @d.strftime("%A")
|
236
|
+
add summary, 'date_uri', urlpath()
|
281
237
|
add summary, 'css_url', @css_url
|
282
238
|
add summary, 'published', Time.now.strftime("%d-%m-%Y %H:%M")
|
283
239
|
add summary, 'prev_day', static_urlpath(@d-1)
|
@@ -410,4 +366,65 @@ EOF
|
|
410
366
|
Time.parse(s).strftime("%a, %-d %b %Y %H:%M:%S %Z")
|
411
367
|
end
|
412
368
|
|
369
|
+
def save_rss()
|
370
|
+
|
371
|
+
buffer = File.read File.join(path(), 'raw_formatted.xml')
|
372
|
+
doc = Rexle.new buffer
|
373
|
+
|
374
|
+
summary = doc.root.element 'summary'
|
375
|
+
|
376
|
+
dx = Dynarex.new 'liveblog[title,desc,link, pubdate, '\
|
377
|
+
+ 'lastbuild_date, lang]/entry(title, desc, created_at, uri, guid)'
|
378
|
+
|
379
|
+
dx.title = @rss_title || 'LiveBlog'
|
380
|
+
dx.desc = 'Latest LiveBlog posts fetched from ' + @urlbase
|
381
|
+
dx.link = @urlbase
|
382
|
+
dx.order = 'descending'
|
383
|
+
dx.pubdate = rss_timestamp(summary.text('published'))
|
384
|
+
dx.lastbuild_date = Time.now.strftime("%a, %-d %b %Y %H:%M:%S %Z")
|
385
|
+
dx.lang = @rss_lang
|
386
|
+
|
387
|
+
doc.root.xpath('records/section/section/details').each do |x|
|
388
|
+
|
389
|
+
next if x.elements.empty?
|
390
|
+
a = x.elements.to_a
|
391
|
+
h1 = a.shift.element('h1')
|
392
|
+
hashtag = h1.text[/#\w+$/]
|
393
|
+
created_at = rss_timestamp(h1.attributes[:created])
|
394
|
+
|
395
|
+
a.each do |node|
|
396
|
+
|
397
|
+
node.attributes.delete :created
|
398
|
+
node.attributes.delete :last_modified
|
399
|
+
|
400
|
+
node.traverse do |x|
|
401
|
+
|
402
|
+
x.attributes.delete :created
|
403
|
+
x.attributes.delete :last_modified
|
404
|
+
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
uri = doc.root.element('summary/link/text()') + hashtag
|
409
|
+
|
410
|
+
record = {
|
411
|
+
title: h1.text,
|
412
|
+
desc: a.map(&:xml).join("\n"),
|
413
|
+
created_at: created_at,
|
414
|
+
uri: uri,
|
415
|
+
guid: uri
|
416
|
+
}
|
417
|
+
|
418
|
+
dx.create record
|
419
|
+
end
|
420
|
+
|
421
|
+
dx.xslt_schema = 'channel[title:title,description:desc,link:link,'\
|
422
|
+
+ 'pubDate:pubdate,lastBuildDate:lastbuild_date,language:lang]/'\
|
423
|
+
+ 'item(title:title,link:uri,description:desc,pubDate:created_at,'\
|
424
|
+
+ 'guid:guid)'
|
425
|
+
File.write 'rss.xml', dx.to_rss
|
426
|
+
|
427
|
+
end
|
428
|
+
|
429
|
+
|
413
430
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liveblog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
WoOSxvsTN7qoA8F0W4mkDpf+HhHxBOLTPykcHMIlx2gILLnNraaZ1rJlZAqWABGj
|
32
32
|
v8lGgeeqqjd5QA==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2015-
|
34
|
+
date: 2015-04-11 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: dynarex
|
metadata.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
�mY�o��+'qd8��a�{�?�_n��������\��\��!�m?�݊��$��:����oV�!�Ƙ��]���;���E��O7\�_� E��A�����'�×������C�ݖ!0[@ s.�!e
|