noticesys 0.5.0 → 0.6.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/noticesys.rb +264 -242
- data.tar.gz.sig +0 -0
- metadata +27 -28
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea1b9ee5b44f05c795688bff4c18dc5530e757782fb1b5a6b6a65119151b1fee
|
4
|
+
data.tar.gz: 37317ae548c6181c7dc0ec93f4c81d0d3d67ccbb2ca6f4f7b19aa72b15593b07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cab5dce7320a1174cae26d92147901072f814888b6303a543ba2e5434d134ed73c8568f3c01bbbc1841b2e1f1a3c916a86e2458173a0a09b4588a8acca897346
|
7
|
+
data.tar.gz: '095fafcf29b12628b0b8854071a63931fe282dcfc8e4b7f9cb5a7b4e1ae826d1d3383ff99c755601926717fbfe2ac482f022e12f17cee75dfd2d54ae9492fee7'
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/noticesys.rb
CHANGED
@@ -8,6 +8,7 @@ require 'dynarex' # flat file storage system
|
|
8
8
|
require 'unichron' # universal chron tool (i.e. time calculation)
|
9
9
|
require 'ogextractor' # extract metadata
|
10
10
|
require 'recordx_sqlite'
|
11
|
+
require 'rxfileio'
|
11
12
|
|
12
13
|
|
13
14
|
# classes:
|
@@ -23,6 +24,7 @@ require 'recordx_sqlite'
|
|
23
24
|
module NoticeSys
|
24
25
|
|
25
26
|
class Client
|
27
|
+
include RXFileIOModule
|
26
28
|
|
27
29
|
def initialize(user='', rmagick=nil, debug: false)
|
28
30
|
@user, @rmagick, @debug = user, rmagick, debug
|
@@ -34,29 +36,29 @@ module NoticeSys
|
|
34
36
|
|
35
37
|
# save the file attachments containing the images etc.
|
36
38
|
|
37
|
-
files = (1..3).map do |n|
|
38
|
-
|
39
|
+
files = (1..3).map do |n|
|
40
|
+
|
39
41
|
f = params['file' + n.to_s]
|
40
|
-
next unless f
|
41
|
-
|
42
|
+
next unless f
|
43
|
+
|
42
44
|
original = f[:tempfile].to_path
|
43
|
-
|
45
|
+
|
44
46
|
scale_img original
|
45
|
-
|
46
|
-
end.compact
|
47
|
-
|
47
|
+
|
48
|
+
end.compact
|
49
|
+
|
48
50
|
msg = params['msg']
|
49
51
|
|
50
52
|
urls = msg.scan(/https:\/\/[^ ]+/)
|
51
|
-
|
53
|
+
|
52
54
|
if urls.any? then
|
53
55
|
|
54
56
|
h2 = OgExtractor.new(urls.last).to_h
|
55
|
-
|
57
|
+
|
56
58
|
puts 'h2: ' + h2.inspect if @debug
|
57
|
-
|
59
|
+
|
58
60
|
if h2 then
|
59
|
-
h = {msg: msg, files: files}
|
61
|
+
h = {msg: msg, files: files}
|
60
62
|
|
61
63
|
h[:site]= h2[:url][/https?:\/\/([^\/]+)/,1].sub(/^www\./,'')
|
62
64
|
|
@@ -64,55 +66,55 @@ module NoticeSys
|
|
64
66
|
tmpfile = Down.download h2[:img]
|
65
67
|
files2 = scale_img tmpfile.to_path
|
66
68
|
end
|
67
|
-
|
69
|
+
|
68
70
|
h[:files] = files2 || []
|
69
|
-
h[:card] = {h2[:card] => { title: h2[:title], desc: h2[:desc],
|
71
|
+
h[:card] = {h2[:card] => { title: h2[:title], desc: h2[:desc],
|
70
72
|
url: h2[:url]}}
|
71
73
|
h[:msg] = msg.sub(urls.last,'')
|
72
74
|
|
73
75
|
return "notice/%s/json: %s" % [@user, h.to_json]
|
74
|
-
|
76
|
+
|
75
77
|
end
|
76
|
-
|
77
|
-
end
|
78
78
|
|
79
|
-
|
79
|
+
end
|
80
|
+
|
81
|
+
return "notice/%s: %s" % [@user, msg]
|
82
|
+
|
83
|
+
end
|
80
84
|
|
81
|
-
end
|
82
|
-
|
83
85
|
private
|
84
86
|
|
85
|
-
def scale_img(raworiginal)
|
87
|
+
def scale_img(raworiginal)
|
86
88
|
|
87
89
|
original = if raworiginal =~ /\.\w+$/ then
|
88
|
-
|
90
|
+
|
89
91
|
raworiginal
|
90
|
-
|
92
|
+
|
91
93
|
else
|
92
|
-
|
94
|
+
|
93
95
|
neworiginal = raworiginal + '.jpg'
|
94
|
-
|
96
|
+
FileX.mv raworiginal, neworiginal
|
95
97
|
neworiginal
|
96
|
-
|
98
|
+
|
97
99
|
end
|
98
|
-
|
99
|
-
res = %w(240x240 360x360 *518x389 1280x720 2048x1080)
|
100
|
+
|
101
|
+
res = %w(240x240 360x360 *518x389 1280x720 2048x1080)
|
100
102
|
a = @rmagick.resize(original, res)
|
101
103
|
a2 = (a + [nil,nil,nil]).take(res.length)
|
102
104
|
|
103
105
|
oldfile = nil
|
104
106
|
sizes = %w(240x240 360x360 small medium large)
|
105
|
-
|
107
|
+
|
106
108
|
file_sizes = a2.zip(sizes).map.with_index do |x, i|
|
107
109
|
|
108
110
|
f, label = x
|
109
111
|
|
110
|
-
if f then
|
111
|
-
|
112
|
+
if f then
|
113
|
+
|
112
114
|
f2 = f.sub(/_(n\d+x\d+)\.\w+$/) {|x| x.sub($1, label)}
|
113
115
|
|
114
|
-
|
115
|
-
oldfile = f2
|
116
|
+
FileX.mv f, f2
|
117
|
+
oldfile = f2
|
116
118
|
|
117
119
|
elsif oldfile
|
118
120
|
|
@@ -120,47 +122,47 @@ module NoticeSys
|
|
120
122
|
|
121
123
|
oldfile = original if i == a.length - 1
|
122
124
|
|
123
|
-
|
125
|
+
FileX.cp oldfile, f2
|
124
126
|
|
125
127
|
end
|
126
|
-
|
127
|
-
|
128
|
+
|
129
|
+
|
128
130
|
f2
|
129
131
|
|
130
|
-
end
|
131
|
-
|
132
|
+
end
|
133
|
+
|
132
134
|
imgfile = original.sub(/\.\w+$/,'2\0')
|
133
|
-
|
135
|
+
FileX.mv original, imgfile
|
134
136
|
|
135
137
|
file_sizes << imgfile
|
136
138
|
|
137
139
|
end
|
138
140
|
|
139
|
-
end
|
140
|
-
|
141
|
-
|
141
|
+
end
|
142
|
+
|
143
|
+
|
142
144
|
class CardView
|
143
|
-
|
145
|
+
|
144
146
|
def initialize(weblet)
|
145
|
-
|
147
|
+
|
146
148
|
@w = weblet
|
147
|
-
|
149
|
+
|
148
150
|
end
|
149
|
-
|
151
|
+
|
150
152
|
def render(dx, rx, card)
|
151
|
-
|
152
|
-
card2 = case card.keys.first
|
153
|
+
|
154
|
+
card2 = case card.keys.first
|
153
155
|
when :images
|
154
|
-
|
156
|
+
|
155
157
|
card[:images].map.with_index do |img, i|
|
156
|
-
|
157
|
-
href = [dx.link.sub(/\/$/,''), rx.topic, 'status', rx.id,
|
158
|
+
|
159
|
+
href = [dx.link.sub(/\/$/,''), rx.topic, 'status', rx.id,
|
158
160
|
'photo', (i+1).to_s ].join('/')
|
159
161
|
url, align = img[:url], img[:align]
|
160
162
|
"<a href='%s'><div class='top-crop %s'><img class='img1' src='%s'/></div></a>" % [href, align, url]
|
161
|
-
|
163
|
+
|
162
164
|
end.join
|
163
|
-
|
165
|
+
|
164
166
|
when :summary_large_image
|
165
167
|
|
166
168
|
h2 = card[:summary_large_image]
|
@@ -171,7 +173,7 @@ module NoticeSys
|
|
171
173
|
site = h2[:url][/https?:\/\/([^\/]+)/,1].sub(/^www\./,'')
|
172
174
|
title = h2[:title]
|
173
175
|
img = h2[:img]
|
174
|
-
url = h2[:url]
|
176
|
+
url = h2[:url]
|
175
177
|
|
176
178
|
@w.render('card', binding)
|
177
179
|
|
@@ -186,45 +188,48 @@ module NoticeSys
|
|
186
188
|
title = h2[:title].length > 46 ? h2[:title][0..46] + '...' : h2[:title]
|
187
189
|
img = h2[:img]
|
188
190
|
url = h2[:url]
|
189
|
-
|
190
|
-
img_element = if img then
|
191
|
+
|
192
|
+
img_element = if img then
|
191
193
|
"<img src='#{img}'>"
|
192
194
|
else
|
193
195
|
@w.render('svg/article')
|
194
196
|
end
|
195
197
|
|
196
|
-
@w.render('card2', binding)
|
197
|
-
|
198
|
+
@w.render('card2', binding)
|
199
|
+
|
198
200
|
end
|
199
|
-
end
|
201
|
+
end
|
200
202
|
end
|
201
|
-
|
203
|
+
|
202
204
|
class StatusView
|
203
|
-
|
205
|
+
include RXFReader
|
206
|
+
|
204
207
|
def initialize(basepath, xslfile, css_url, weblet)
|
205
|
-
|
208
|
+
|
206
209
|
@basepath, @xslfile, @css_url = basepath, xslfile, css_url
|
207
|
-
@w = weblet
|
210
|
+
@w = weblet
|
208
211
|
@card = CardView.new(@w)
|
209
|
-
|
212
|
+
|
210
213
|
end
|
211
|
-
|
212
|
-
def render(topic, rawid, referer)
|
214
|
+
|
215
|
+
def render(topic, rawid, referer)
|
213
216
|
|
214
217
|
id = rawid[0..9].to_i
|
215
|
-
|
218
|
+
|
216
219
|
filepath = File.join(@basepath, 'u', topic)
|
217
220
|
a = [Time.at(id).strftime("%Y/%b/%-d").downcase, rawid]
|
218
221
|
xmlfile = File.join(filepath, "%s/%s/index.xml" % a)
|
219
222
|
xslfile = File.join(@basepath, "/xsl/notices/#{topic}.xsl")
|
220
|
-
|
221
|
-
unless
|
223
|
+
|
224
|
+
unless FileX.exists? xslfile then
|
222
225
|
xslfile = @xslfile
|
223
226
|
end
|
224
227
|
|
225
228
|
dx = Dynarex.new(File.join(filepath, 'feed.xml'))
|
226
|
-
|
227
|
-
|
229
|
+
s = FileX.read(xmlfile)
|
230
|
+
|
231
|
+
doc = Rexle.new(s.force_encoding("UTF-8"))
|
232
|
+
|
228
233
|
doc.root.element('summary/title').text = dx.title
|
229
234
|
e = doc.root.element('summary/image')
|
230
235
|
|
@@ -232,72 +237,72 @@ module NoticeSys
|
|
232
237
|
e = Rexle::Element.new 'image'
|
233
238
|
doc.root.element('summary').add e
|
234
239
|
end
|
235
|
-
|
240
|
+
|
236
241
|
doc.root.element('summary/image').text = dx.image
|
237
|
-
|
242
|
+
|
238
243
|
# remove the card from the description
|
239
244
|
desc = doc.root.element('body/description')
|
240
245
|
desc.xpath('img|div').each(&:delete)
|
241
246
|
|
242
247
|
doc = Nokogiri::XML(doc.root.xml)
|
243
|
-
xslt = Nokogiri::XSLT(
|
248
|
+
xslt = Nokogiri::XSLT(FileX.read(xslfile))
|
244
249
|
|
245
250
|
s = xslt.transform(doc)
|
246
251
|
doc = Rexle.new(s.to_s)
|
247
|
-
|
248
|
-
rx = Kvx.new(xmlfile)
|
252
|
+
|
253
|
+
rx = Kvx.new(xmlfile)
|
249
254
|
|
250
255
|
rawcard = rx.card
|
251
256
|
|
252
257
|
|
253
258
|
card2, meta = if rawcard and rawcard.length > 10 then
|
254
|
-
|
259
|
+
|
255
260
|
card = JSON.parse(rawcard, symbolize_names: true)
|
256
|
-
|
257
|
-
if card.is_a? Hash then
|
258
|
-
|
261
|
+
|
262
|
+
if card.is_a? Hash then
|
263
|
+
|
259
264
|
type = card.keys.first
|
260
265
|
h = card[type]
|
261
266
|
#img = h[:img].sub(/small(?=\.\w+$)/,'large')
|
262
267
|
img = h[:img]
|
263
268
|
metadata = @w.render(:meta, binding)
|
264
269
|
[@card.render(dx, rx, card), metadata]
|
265
|
-
|
270
|
+
|
266
271
|
end
|
267
272
|
else
|
268
273
|
'<span/>'
|
269
274
|
end
|
270
|
-
|
275
|
+
|
271
276
|
|
272
277
|
e = doc.root.at_css '#notice'
|
273
278
|
desc = e.at_css '#desc'
|
274
|
-
desc.add Rexle.new(card2).root
|
279
|
+
desc.add Rexle.new(card2).root
|
275
280
|
|
276
281
|
ref = referer
|
277
282
|
svg = @w.render 'svg/backarrow', binding
|
278
|
-
|
283
|
+
|
279
284
|
back = if ref then
|
280
285
|
"<div id='back'><a href='#{ref}' title='back'>#{svg}</a></div>"
|
281
286
|
else
|
282
|
-
''
|
287
|
+
"<div id='back'><a href='/' title='back'>#{svg}</a></div>"
|
283
288
|
end
|
284
|
-
|
289
|
+
|
285
290
|
@w.render :status, binding
|
286
291
|
|
287
292
|
end
|
288
|
-
|
293
|
+
|
289
294
|
end
|
290
|
-
|
295
|
+
|
291
296
|
class CssView
|
292
|
-
|
297
|
+
|
293
298
|
def initialize(weblet_file)
|
294
|
-
|
299
|
+
|
295
300
|
@weblet_file = weblet_file
|
296
|
-
|
301
|
+
|
297
302
|
end
|
298
|
-
|
303
|
+
|
299
304
|
def noticelist_css()
|
300
|
-
|
305
|
+
|
301
306
|
w = Weblet.new(@weblet_file)
|
302
307
|
|
303
308
|
lines = []
|
@@ -308,72 +313,72 @@ module NoticeSys
|
|
308
313
|
lines << w.render('main/noticelist')
|
309
314
|
lines << w.render('main/footer')
|
310
315
|
lines.join("\n")
|
311
|
-
|
316
|
+
|
312
317
|
end
|
313
|
-
|
318
|
+
|
314
319
|
def notice_css()
|
315
|
-
|
320
|
+
|
316
321
|
w = Weblet.new(@weblet_file)
|
317
322
|
|
318
323
|
lines = []
|
319
324
|
lines << w.render(:status)
|
320
325
|
lines << w.render(:cards)
|
321
326
|
lines.join("\n")
|
322
|
-
|
323
|
-
end
|
324
|
-
|
325
|
-
end
|
326
|
-
|
327
|
+
|
328
|
+
end
|
329
|
+
|
330
|
+
end
|
331
|
+
|
327
332
|
class NoticeView
|
328
|
-
|
333
|
+
|
329
334
|
def render()
|
330
335
|
end
|
331
|
-
|
336
|
+
|
332
337
|
end
|
333
338
|
|
334
|
-
|
339
|
+
|
335
340
|
class StatusListView
|
336
|
-
|
341
|
+
|
337
342
|
def initialize(basepath, css_url, static_urlbase, weblet)
|
338
|
-
|
343
|
+
|
339
344
|
@basepath, @css_url, @static_urlbase = basepath, css_url, static_urlbase
|
340
345
|
@w = weblet
|
341
346
|
@card = CardView.new(@w)
|
342
|
-
|
347
|
+
|
343
348
|
end
|
344
|
-
|
345
|
-
def render(username)
|
349
|
+
|
350
|
+
def render(username)
|
346
351
|
|
347
352
|
s = ''
|
348
|
-
|
353
|
+
|
349
354
|
dx = Dynarex.new(File.join(@basepath, 'u', username, 'feed.xml'))
|
350
|
-
|
355
|
+
|
351
356
|
s += @w.render 'user/ptop', binding
|
352
|
-
|
357
|
+
|
353
358
|
notices = dx.all.map do |rx|
|
354
|
-
|
359
|
+
|
355
360
|
card2 = ''
|
356
|
-
rawcard = rx.to_h[:card]
|
357
|
-
|
361
|
+
rawcard = rx.to_h[:card]
|
362
|
+
|
358
363
|
card2 = if rawcard and rawcard.length > 10 then
|
359
|
-
|
360
|
-
card = JSON.parse(rawcard, symbolize_names: true)
|
361
|
-
|
362
|
-
if card.is_a? Hash then
|
364
|
+
|
365
|
+
card = JSON.parse(rawcard, symbolize_names: true)
|
366
|
+
|
367
|
+
if card.is_a? Hash then
|
363
368
|
@card.render(dx, rx, card)
|
364
369
|
end
|
365
|
-
|
370
|
+
|
366
371
|
else
|
367
372
|
''
|
368
|
-
end
|
369
|
-
|
373
|
+
end
|
374
|
+
|
370
375
|
t2 = Time.at rx.id.to_s[0..9].to_i
|
371
376
|
relative_time = Unichron.new(t2).elapsed
|
372
|
-
|
377
|
+
|
373
378
|
d = t2.strftime("%I:%M%p %b %d %Y")
|
374
|
-
|
379
|
+
|
375
380
|
description = if rx.description.length > 1 then
|
376
|
-
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
381
|
+
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
377
382
|
doc.root.xpath('img|div').each(&:delete)
|
378
383
|
"<p>%s</p>" % doc.root.xml
|
379
384
|
else
|
@@ -382,39 +387,45 @@ module NoticeSys
|
|
382
387
|
|
383
388
|
utitle, uimage, ubio = dx.title, dx.image, dx.bio
|
384
389
|
@w.render :notice, binding
|
385
|
-
|
390
|
+
|
386
391
|
end
|
387
392
|
|
388
|
-
s += notices.join
|
389
|
-
s += @w.render 'user/rsslink', binding
|
393
|
+
s += notices.join
|
394
|
+
s += @w.render 'user/rsslink', binding
|
390
395
|
@w.render :user, binding
|
391
|
-
|
396
|
+
|
392
397
|
end
|
393
398
|
end
|
394
|
-
|
399
|
+
|
395
400
|
class HashtagQueryView
|
396
|
-
|
397
|
-
def initialize(basepath, css_url, weblet, static_urlbase,
|
398
|
-
|
401
|
+
|
402
|
+
def initialize(basepath, db_basepath, css_url, weblet, static_urlbase,
|
403
|
+
urlbase, debug: false)
|
404
|
+
|
399
405
|
@basepath, @css_url, @static_urlbase = basepath, css_url, static_urlbase
|
400
|
-
@w, @urlbase = weblet, urlbase
|
406
|
+
@db_basepath, @w, @urlbase, @debug = db_basepath, weblet, urlbase, debug
|
401
407
|
@card = CardView.new(@w)
|
402
|
-
|
408
|
+
|
403
409
|
end
|
404
|
-
|
405
|
-
def render(q, referer)
|
406
|
-
#q = args.first
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
410
|
+
|
411
|
+
def render(q, referer)
|
412
|
+
#q = args.first
|
413
|
+
dbindex_path = File.join(@db_basepath, '/hashtag/index.db')
|
414
|
+
puts 'dbindex_path: ' + dbindex_path.inspect if @debug
|
415
|
+
|
416
|
+
db = RecordxSqlite.new(dbindex_path, table: 'hashtags')
|
417
|
+
|
418
|
+
|
411
419
|
a = db.find_all_by_tag q
|
412
420
|
|
413
|
-
topics = a.map(&:topic).uniq.map do |topic|
|
421
|
+
topics = a.map(&:topic).uniq.map do |topic|
|
414
422
|
|
415
423
|
topicpath = File.join(@basepath, 'u', topic)
|
416
|
-
|
417
|
-
|
424
|
+
topic_db_path = File.join(@db_basepath, 'u', topic)
|
425
|
+
|
426
|
+
db_filepath = File.join(topic_db_path, "notices.db")
|
427
|
+
puts 'db_filepath: ' + db_filepath.inspect if @debug
|
428
|
+
db = RecordxSqlite.new(db_filepath, table: 'notices')
|
418
429
|
|
419
430
|
dx = Dynarex.new(File.join(topicpath, 'feed.xml'))
|
420
431
|
[topic, OpenStruct.new(title: dx.title, image: dx.image, db: db)]
|
@@ -427,92 +438,93 @@ module NoticeSys
|
|
427
438
|
r = topics[x.topic]
|
428
439
|
rx = r.db.find x.noticeid
|
429
440
|
link = "%s/%s/status/%s" % [@urlbase, x.topic, x.noticeid]
|
430
|
-
OpenStruct.new(rx.to_h.merge({topic: x.topic, title: r.title,
|
441
|
+
OpenStruct.new(rx.to_h.merge({topic: x.topic, title: r.title,
|
431
442
|
image: r.image, bio: r.bio, link: link}))
|
432
443
|
|
433
444
|
end
|
434
|
-
|
435
|
-
|
445
|
+
|
446
|
+
|
436
447
|
s = ''
|
437
|
-
|
448
|
+
|
438
449
|
notices = rows.sort_by {|x| -(x.id.to_i)}.take(20).map do |rx|
|
439
|
-
|
450
|
+
|
440
451
|
next unless rx.description
|
441
|
-
|
452
|
+
|
442
453
|
card2 = ''
|
443
|
-
rawcard = rx.to_h[:card]
|
444
|
-
|
454
|
+
rawcard = rx.to_h[:card]
|
455
|
+
|
445
456
|
card2 = if rawcard and rawcard.length > 10 then
|
446
|
-
|
447
|
-
card = JSON.parse(rawcard, symbolize_names: true)
|
448
|
-
|
449
|
-
if card.is_a? Hash then
|
457
|
+
|
458
|
+
card = JSON.parse(rawcard, symbolize_names: true)
|
459
|
+
|
460
|
+
if card.is_a? Hash then
|
450
461
|
@card.render(dx, rx, card)
|
451
462
|
end
|
452
|
-
|
463
|
+
|
453
464
|
else
|
454
465
|
''
|
455
|
-
end
|
456
|
-
|
466
|
+
end
|
467
|
+
|
457
468
|
t2 = Time.at rx.id.to_s[0..9].to_i
|
458
469
|
relative_time = Unichron.new(t2).elapsed
|
459
|
-
|
470
|
+
|
460
471
|
d = t2.strftime("%I:%M%p %b %d %Y")
|
461
|
-
|
472
|
+
|
462
473
|
description = if rx.description.length > 1 then
|
463
|
-
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
474
|
+
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
464
475
|
doc.root.xpath('img|div').each(&:delete)
|
465
476
|
"<p>%s</p>" % doc.root.xml
|
466
477
|
else
|
467
478
|
''
|
468
|
-
end
|
479
|
+
end
|
469
480
|
|
470
481
|
utitle, uimage, ubio = rx.title, rx.image, rx.bio
|
471
482
|
@w.render :notice, binding
|
472
|
-
|
473
|
-
end
|
474
|
-
|
483
|
+
|
484
|
+
end
|
485
|
+
|
475
486
|
s += if notices.any? then
|
476
|
-
notices.compact.join
|
487
|
+
notices.compact.join
|
477
488
|
else
|
478
489
|
"<p>No results for #{q}</p>"
|
479
490
|
end
|
480
|
-
|
491
|
+
|
481
492
|
ref = referer
|
482
|
-
ref = '../' if ref =~ /(?:status|hashtag)\/\d+/
|
483
|
-
|
493
|
+
ref = '../' if ref =~ /(?:status|hashtag)\/\d+/
|
494
|
+
|
484
495
|
svg = @w.render 'svg/backarrow', binding
|
485
496
|
back = ref ? "<a href='#{ref}'>#{svg}</a>" : ''
|
486
|
-
|
497
|
+
|
487
498
|
@w.render :search_pg, binding
|
488
|
-
|
499
|
+
|
489
500
|
end
|
490
|
-
|
491
|
-
|
501
|
+
|
502
|
+
|
492
503
|
end
|
493
|
-
|
504
|
+
|
494
505
|
class SearchQueryView
|
495
|
-
|
496
|
-
def initialize(basepath, css_url, weblet, static_urlbase, urlbase)
|
497
|
-
|
506
|
+
|
507
|
+
def initialize(basepath, db_basepath, css_url, weblet, static_urlbase, urlbase)
|
508
|
+
|
498
509
|
@basepath, @css_url, @static_urlbase = basepath, css_url, static_urlbase
|
499
|
-
@w, @urlbase = weblet, urlbase
|
510
|
+
@db_basepath, @w, @urlbase = db_basepath, weblet, urlbase
|
500
511
|
@card = CardView.new(@w)
|
501
|
-
|
512
|
+
|
502
513
|
end
|
503
|
-
|
504
|
-
def render(q, referer)
|
505
|
-
|
514
|
+
|
515
|
+
def render(q, referer)
|
516
|
+
|
506
517
|
|
507
518
|
users = Dir.glob(File.join(@basepath, 'u', '*')).map do |x|
|
508
519
|
File.basename(x)
|
509
520
|
end
|
510
521
|
|
511
|
-
topics = users.map do |topic|
|
522
|
+
topics = users.map do |topic|
|
512
523
|
|
513
524
|
topicpath = File.join(@basepath, 'u', topic)
|
514
|
-
|
515
|
-
|
525
|
+
topic_db_path = File.join(@db_basepath, 'u', topic)
|
526
|
+
db_filepath = File.join(topic_db_path, "notices.db")
|
527
|
+
db = RecordxSqlite.new(db_filepath, table: 'notices')
|
516
528
|
|
517
529
|
dx = Dynarex.new(File.join(topicpath, 'feed.xml'))
|
518
530
|
[topic, OpenStruct.new(title: dx.title, image: dx.image, bio: dx.bio, db: db)]
|
@@ -522,114 +534,125 @@ module NoticeSys
|
|
522
534
|
#return topics.inspect
|
523
535
|
rows = topics.flat_map do |topic, r|
|
524
536
|
|
525
|
-
a = r.db.all.select {|x| x.description =~ /#{q}/i}
|
537
|
+
a = r.db.all.select {|x| x.description =~ /#{q.gsub('$',"\\$")}/i}
|
526
538
|
a.map do |rx|
|
527
539
|
link = "%s/%s/status/%s" % [@urlbase, topic, rx.noticeid]
|
528
540
|
OpenStruct.new(rx.to_h.merge({topic: topic, title: r.title, image: r.image, link: link}))
|
529
541
|
end
|
530
542
|
|
531
543
|
end
|
532
|
-
|
533
|
-
|
534
|
-
#return rows.inspect
|
544
|
+
|
545
|
+
|
546
|
+
#return rows.inspect
|
535
547
|
s = ''
|
536
|
-
|
548
|
+
|
537
549
|
notices = rows.sort_by {|x| -(x.id.to_i)}.take(20).map do |rx|
|
538
|
-
|
539
|
-
|
550
|
+
|
551
|
+
|
540
552
|
card2 = ''
|
541
|
-
rawcard = rx.to_h[:card]
|
542
|
-
|
553
|
+
rawcard = rx.to_h[:card]
|
554
|
+
|
543
555
|
card2 = if rawcard and rawcard.length > 10 then
|
544
|
-
|
545
|
-
card = JSON.parse(rawcard, symbolize_names: true)
|
546
|
-
|
547
|
-
if card.is_a? Hash then
|
556
|
+
|
557
|
+
card = JSON.parse(rawcard, symbolize_names: true)
|
558
|
+
|
559
|
+
if card.is_a? Hash then
|
548
560
|
@card.render(dx, rx, card)
|
549
561
|
end
|
550
|
-
|
562
|
+
|
551
563
|
else
|
552
564
|
''
|
553
|
-
end
|
554
|
-
|
565
|
+
end
|
566
|
+
|
555
567
|
#rx.description
|
556
568
|
t2 = Time.at rx.id.to_s[0..9].to_i
|
557
569
|
relative_time = Unichron.new(t2).elapsed
|
558
|
-
|
570
|
+
|
559
571
|
d = t2.strftime("%I:%M%p %b %d %Y")
|
560
|
-
|
572
|
+
|
561
573
|
#desc = rx.description.gsub(/<\/?p>/,'').gsub('<','<').gsub('>','>')
|
562
|
-
|
574
|
+
|
563
575
|
topic = rx.topic
|
564
576
|
title, image, bio = %i(title image bio).map do |x|
|
565
577
|
topics[topic].method(x).call
|
566
578
|
end
|
567
|
-
|
579
|
+
|
568
580
|
description = if rx.description.length > 1 then
|
569
|
-
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
581
|
+
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
570
582
|
doc.root.xpath('img|div').each(&:delete)
|
571
583
|
"<p>%s</p>" % doc.root.xml
|
572
584
|
else
|
573
585
|
''
|
574
|
-
end
|
575
|
-
|
586
|
+
end
|
587
|
+
|
576
588
|
utitle, uimage, ubio = title, image, bio
|
577
589
|
@w.render :notice, binding
|
578
590
|
|
579
591
|
|
580
592
|
end
|
581
593
|
#return notices.inspect
|
582
|
-
|
594
|
+
|
583
595
|
s += if notices.any? then
|
584
|
-
notices.join
|
596
|
+
notices.join
|
585
597
|
else
|
586
598
|
"<p>No results for #{q}</p>"
|
587
599
|
end
|
588
|
-
|
600
|
+
|
589
601
|
#ref = @env["HTTP_REFERER"]
|
590
602
|
ref = referer
|
591
603
|
ref = '../' if ref =~ /(?:status\/\d+|search)/
|
592
604
|
svg = @w.render 'svg/backarrow', binding
|
593
|
-
back = ref ? "<a href='#{ref}'>#{svg}</a>" : ''
|
594
|
-
|
605
|
+
back = ref ? "<a href='#{ref}'>#{svg}</a>" : "<a href='/'>#{svg}</a>"
|
606
|
+
|
595
607
|
@w.render :search_pg, binding
|
596
|
-
|
597
|
-
|
608
|
+
|
609
|
+
|
598
610
|
end
|
599
|
-
|
600
|
-
|
601
|
-
end
|
602
|
-
|
611
|
+
|
612
|
+
|
613
|
+
end
|
614
|
+
|
603
615
|
class Main
|
604
|
-
|
605
|
-
def initialize(basepath, xslfile, statuscss_url,
|
606
|
-
weblet_file, static_urlbase,
|
607
|
-
|
608
|
-
|
616
|
+
|
617
|
+
def initialize(basepath, db_basepath, xslfile, statuscss_url,
|
618
|
+
statuslistcss_url, weblet_file, static_urlbase,
|
619
|
+
urlbase, weblet_cssfile, debug: false)
|
620
|
+
|
621
|
+
weblet_file ||= File.join(File.dirname(__FILE__), '..',
|
622
|
+
'data', 'microblog.txt')
|
623
|
+
|
624
|
+
weblet = Weblet.new(weblet_file)
|
625
|
+
|
609
626
|
@status = StatusView.new(basepath, xslfile, statuscss_url, weblet)
|
610
|
-
|
627
|
+
|
628
|
+
@statuslist = StatusListView.new(basepath, statuslistcss_url,
|
611
629
|
static_urlbase, weblet)
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
static_urlbase, urlbase)
|
616
|
-
|
630
|
+
|
631
|
+
@hashtag = HashtagQueryView.new(basepath, db_basepath,
|
632
|
+
statuslistcss_url, weblet,
|
633
|
+
static_urlbase, urlbase, debug: debug)
|
634
|
+
|
635
|
+
@search = SearchQueryView.new(basepath, db_basepath, statuslistcss_url,
|
636
|
+
weblet, static_urlbase, urlbase)
|
637
|
+
|
638
|
+
weblet_cssfile ||= File.join(File.dirname(__FILE__), '..',
|
639
|
+
'data', 'css.txt')
|
617
640
|
@css = CssView.new(weblet_cssfile)
|
618
|
-
|
641
|
+
|
619
642
|
end
|
620
|
-
|
643
|
+
|
621
644
|
def notice_css()
|
622
645
|
@css.notice_css()
|
623
646
|
end
|
624
|
-
|
647
|
+
|
625
648
|
def noticelist_css()
|
626
649
|
@css.noticelist_css()
|
627
650
|
end
|
628
|
-
|
651
|
+
|
629
652
|
def status(topic, rawid, referer)
|
630
653
|
@status.render topic, rawid, referer
|
631
654
|
end
|
632
|
-
|
655
|
+
|
633
656
|
def status_list(username)
|
634
657
|
@statuslist.render username
|
635
658
|
end
|
@@ -637,13 +660,12 @@ module NoticeSys
|
|
637
660
|
def hashtag_query(s, referer)
|
638
661
|
@hashtag.render s, referer
|
639
662
|
end
|
640
|
-
|
663
|
+
|
641
664
|
def search_query(s, referer)
|
642
665
|
@search.render s, referer
|
643
666
|
end
|
644
667
|
|
645
|
-
|
646
|
-
|
668
|
+
|
647
669
|
end
|
648
|
-
|
649
|
-
end
|
670
|
+
|
671
|
+
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noticesys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,88 +35,88 @@ cert_chain:
|
|
35
35
|
iGAgDWBQqM/kdjDslqjBGtyWyFyuYHzXMU1gO/P0aE3rh1enqahZ8BqY+gxXLGrR
|
36
36
|
sU+WFV9qPqoqNOG0tOknOZXN
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2022-02-23 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: down
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 5.2.0
|
47
44
|
- - "~>"
|
48
45
|
- !ruby/object:Gem::Version
|
49
|
-
version: '5.
|
46
|
+
version: '5.3'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 5.3.0
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 5.2.0
|
57
54
|
- - "~>"
|
58
55
|
- !ruby/object:Gem::Version
|
59
|
-
version: '5.
|
56
|
+
version: '5.3'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 5.3.0
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: weblet
|
62
62
|
requirement: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
64
|
- - "~>"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: '0.
|
66
|
+
version: '0.4'
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.
|
69
|
+
version: 0.4.0
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '0.
|
76
|
+
version: '0.4'
|
77
77
|
- - ">="
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: 0.
|
79
|
+
version: 0.4.0
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: dynarex
|
82
82
|
requirement: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
84
|
- - "~>"
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version: '1.
|
86
|
+
version: '1.9'
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 1.
|
89
|
+
version: 1.9.5
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '1.
|
96
|
+
version: '1.9'
|
97
97
|
- - ">="
|
98
98
|
- !ruby/object:Gem::Version
|
99
|
-
version: 1.
|
99
|
+
version: 1.9.5
|
100
100
|
- !ruby/object:Gem::Dependency
|
101
101
|
name: unichron
|
102
102
|
requirement: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
104
|
- - "~>"
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
version: '0.
|
106
|
+
version: '0.4'
|
107
107
|
- - ">="
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.
|
109
|
+
version: 0.4.0
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: '0.
|
116
|
+
version: '0.4'
|
117
117
|
- - ">="
|
118
118
|
- !ruby/object:Gem::Version
|
119
|
-
version: 0.
|
119
|
+
version: 0.4.0
|
120
120
|
- !ruby/object:Gem::Dependency
|
121
121
|
name: ogextractor
|
122
122
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,7 +126,7 @@ dependencies:
|
|
126
126
|
version: '0.1'
|
127
127
|
- - ">="
|
128
128
|
- !ruby/object:Gem::Version
|
129
|
-
version: 0.1.
|
129
|
+
version: 0.1.4
|
130
130
|
type: :runtime
|
131
131
|
prerelease: false
|
132
132
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -136,7 +136,7 @@ dependencies:
|
|
136
136
|
version: '0.1'
|
137
137
|
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: 0.1.
|
139
|
+
version: 0.1.4
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
141
|
name: recordx_sqlite
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,7 +146,7 @@ dependencies:
|
|
146
146
|
version: '0.3'
|
147
147
|
- - ">="
|
148
148
|
- !ruby/object:Gem::Version
|
149
|
-
version: 0.3.
|
149
|
+
version: 0.3.3
|
150
150
|
type: :runtime
|
151
151
|
prerelease: false
|
152
152
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -156,7 +156,7 @@ dependencies:
|
|
156
156
|
version: '0.3'
|
157
157
|
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 0.3.
|
159
|
+
version: 0.3.3
|
160
160
|
description:
|
161
161
|
email: digital.robertson@gmail.com
|
162
162
|
executables: []
|
@@ -185,8 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
- !ruby/object:Gem::Version
|
186
186
|
version: '0'
|
187
187
|
requirements: []
|
188
|
-
|
189
|
-
rubygems_version: 2.7.10
|
188
|
+
rubygems_version: 3.2.22
|
190
189
|
signing_key:
|
191
190
|
specification_version: 4
|
192
191
|
summary: A small part of an experimental microblogging system.
|
metadata.gz.sig
CHANGED
Binary file
|