noticesys 0.3.0 → 0.4.0
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/noticesys.rb +266 -6
- metadata +4 -4
- 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: dc57ed6739da60187b8cc0ef1e4da8a1cc80ac45c7d61457d06dfdd1d41b1879
|
4
|
+
data.tar.gz: c6766e6a31a2cef0597d16ff710ef60ab4f85a0e3b93a6bdba43f245d5272e93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9f242c894cb5cfd50618f8035cfe71404584d846f99b0bcc43d3ee32428d895c669ea2d6f5a64b2afc3771719a1d1519747b3b0e1a25ddcdbf4070a5a6f3e40
|
7
|
+
data.tar.gz: 95b74880b300da703559a865c3ae1c916d6123f5437af2ad0cdeed65696602454ab3a901cb2a59a52bcd61ca0af35e9fe6c3577afb3e88fd48fd53d806f2da0a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/noticesys.rb
CHANGED
@@ -7,8 +7,18 @@ require 'weblet' # HTML retrieval
|
|
7
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
|
+
require 'recordx_sqlite'
|
10
11
|
|
11
12
|
|
13
|
+
# classes:
|
14
|
+
#
|
15
|
+
# Client - sends the msg to the messaging broker
|
16
|
+
# StatusView - renders the HTML for a user status
|
17
|
+
# StatusListView - renders the HTML for a user timeline
|
18
|
+
# CardView - renders the HTML for a card; used within a status
|
19
|
+
# HashtagQueryView - renders the HTML for the results for a hashtag search
|
20
|
+
# SearchQueryView - renders the HTML for the results for a keyword search
|
21
|
+
|
12
22
|
module NoticeSys
|
13
23
|
|
14
24
|
class Client
|
@@ -190,10 +200,10 @@ module NoticeSys
|
|
190
200
|
|
191
201
|
class StatusView
|
192
202
|
|
193
|
-
def initialize(basepath, xslfile, css_url,
|
203
|
+
def initialize(basepath, xslfile, css_url, weblet)
|
194
204
|
|
195
205
|
@basepath, @xslfile, @css_url = basepath, xslfile, css_url
|
196
|
-
@w =
|
206
|
+
@w = weblet
|
197
207
|
@card = CardView.new(@w)
|
198
208
|
|
199
209
|
end
|
@@ -202,7 +212,7 @@ module NoticeSys
|
|
202
212
|
|
203
213
|
id = rawid[0..9].to_i
|
204
214
|
|
205
|
-
filepath = File.join(@basepath, topic)
|
215
|
+
filepath = File.join(@basepath, 'u', topic)
|
206
216
|
a = [Time.at(id).strftime("%Y/%b/%-d").downcase, rawid]
|
207
217
|
xmlfile = File.join(filepath, "%s/%s/index.xml" % a)
|
208
218
|
xslfile = File.join(@basepath, "/xsl/notices/#{topic}.xsl")
|
@@ -277,12 +287,20 @@ module NoticeSys
|
|
277
287
|
|
278
288
|
end
|
279
289
|
|
290
|
+
class NoticeView
|
291
|
+
|
292
|
+
def render()
|
293
|
+
end
|
294
|
+
|
295
|
+
end
|
296
|
+
|
297
|
+
|
280
298
|
class StatusListView
|
281
299
|
|
282
|
-
def initialize(basepath, css_url,
|
300
|
+
def initialize(basepath, css_url, static_urlbase, weblet)
|
283
301
|
|
284
302
|
@basepath, @css_url, @static_urlbase = basepath, css_url, static_urlbase
|
285
|
-
@w =
|
303
|
+
@w = weblet
|
286
304
|
@card = CardView.new(@w)
|
287
305
|
|
288
306
|
end
|
@@ -291,7 +309,7 @@ module NoticeSys
|
|
291
309
|
|
292
310
|
s = ''
|
293
311
|
|
294
|
-
dx = Dynarex.new(File.join(@basepath, username, 'feed.xml'))
|
312
|
+
dx = Dynarex.new(File.join(@basepath, 'u', username, 'feed.xml'))
|
295
313
|
|
296
314
|
s += @w.render 'user/ptop', binding
|
297
315
|
|
@@ -325,6 +343,7 @@ module NoticeSys
|
|
325
343
|
''
|
326
344
|
end
|
327
345
|
|
346
|
+
utitle, uimage, ubio = dx.title, dx.image, dx.bio
|
328
347
|
@w.render :notice, binding
|
329
348
|
|
330
349
|
end
|
@@ -334,6 +353,247 @@ module NoticeSys
|
|
334
353
|
@w.render :user, binding
|
335
354
|
|
336
355
|
end
|
356
|
+
end
|
357
|
+
|
358
|
+
class HashtagQueryView
|
359
|
+
|
360
|
+
def initialize(basepath, css_url, weblet, static_urlbase, urlbase)
|
361
|
+
|
362
|
+
@basepath, @css_url, @static_urlbase = basepath, css_url, static_urlbase
|
363
|
+
@w, @urlbase = weblet, urlbase
|
364
|
+
@card = CardView.new(@w)
|
365
|
+
|
366
|
+
end
|
367
|
+
|
368
|
+
def render(q, referer)
|
369
|
+
#q = args.first
|
370
|
+
dbpath = File.join(@basepath, '/hashtag/index.db')
|
371
|
+
db = RecordxSqlite.new(dbpath, table: 'hashtags')
|
372
|
+
|
373
|
+
|
374
|
+
a = db.find_all_by_tag q
|
375
|
+
|
376
|
+
topics = a.map(&:topic).uniq.map do |topic|
|
377
|
+
|
378
|
+
topicpath = File.join(@basepath, 'u', topic)
|
379
|
+
filepath = File.join(topicpath, "notices.db")
|
380
|
+
db = RecordxSqlite.new(filepath, table: 'notices')
|
381
|
+
|
382
|
+
dx = Dynarex.new(File.join(topicpath, 'feed.xml'))
|
383
|
+
[topic, OpenStruct.new(title: dx.title, image: dx.image, db: db)]
|
384
|
+
|
385
|
+
end.to_h
|
386
|
+
|
387
|
+
|
388
|
+
rows = a.map do |x|
|
389
|
+
|
390
|
+
r = topics[x.topic]
|
391
|
+
rx = r.db.find x.noticeid
|
392
|
+
link = "%s/%s/status/%s" % [@urlbase, x.topic, x.noticeid]
|
393
|
+
OpenStruct.new(rx.to_h.merge({topic: x.topic, title: r.title,
|
394
|
+
image: r.image, bio: r.bio, link: link}))
|
395
|
+
|
396
|
+
end
|
397
|
+
|
398
|
+
|
399
|
+
s = ''
|
400
|
+
|
401
|
+
notices = rows.sort_by {|x| -(x.id.to_i)}.take(20).map do |rx|
|
402
|
+
|
403
|
+
next unless rx.description
|
404
|
+
|
405
|
+
card2 = ''
|
406
|
+
rawcard = rx.to_h[:card]
|
407
|
+
|
408
|
+
card2 = if rawcard and rawcard.length > 10 then
|
409
|
+
|
410
|
+
card = JSON.parse(rawcard, symbolize_names: true)
|
411
|
+
|
412
|
+
if card.is_a? Hash then
|
413
|
+
@card.render(dx, rx, card)
|
414
|
+
end
|
415
|
+
|
416
|
+
else
|
417
|
+
''
|
418
|
+
end
|
419
|
+
|
420
|
+
t2 = Time.at rx.id.to_s[0..9].to_i
|
421
|
+
relative_time = Unichron.new(t2).elapsed
|
422
|
+
|
423
|
+
d = t2.strftime("%I:%M%p %b %d %Y")
|
424
|
+
|
425
|
+
description = if rx.description.length > 1 then
|
426
|
+
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
427
|
+
doc.root.xpath('img|div').each(&:delete)
|
428
|
+
"<p>%s</p>" % doc.root.xml
|
429
|
+
else
|
430
|
+
''
|
431
|
+
end
|
432
|
+
|
433
|
+
utitle, uimage, ubio = rx.title, rx.image, rx.bio
|
434
|
+
@w.render :notice, binding
|
435
|
+
|
436
|
+
end
|
437
|
+
|
438
|
+
s += if notices.any? then
|
439
|
+
notices.compact.join
|
440
|
+
else
|
441
|
+
"<p>No results for #{q}</p>"
|
442
|
+
end
|
443
|
+
|
444
|
+
ref = referer
|
445
|
+
ref = '../' if ref =~ /(?:status|hashtag)\/\d+/
|
446
|
+
|
447
|
+
svg = @w.render 'svg/backarrow', binding
|
448
|
+
back = ref ? "<a href='#{ref}'>#{svg}</a>" : ''
|
449
|
+
|
450
|
+
@w.render :search_pg, binding
|
451
|
+
|
452
|
+
end
|
453
|
+
|
454
|
+
|
455
|
+
end
|
456
|
+
|
457
|
+
class SearchQueryView
|
458
|
+
|
459
|
+
def initialize(basepath, css_url, weblet, static_urlbase, urlbase)
|
460
|
+
|
461
|
+
@basepath, @css_url, @static_urlbase = basepath, css_url, static_urlbase
|
462
|
+
@w, @urlbase = weblet, urlbase
|
463
|
+
@card = CardView.new(@w)
|
464
|
+
|
465
|
+
end
|
466
|
+
|
467
|
+
def render(q, referer)
|
468
|
+
|
469
|
+
|
470
|
+
users = Dir.glob(File.join(@basepath, 'u', '*')).map do |x|
|
471
|
+
File.basename(x)
|
472
|
+
end
|
473
|
+
|
474
|
+
topics = users.map do |topic|
|
475
|
+
|
476
|
+
topicpath = File.join(@basepath, 'u', topic)
|
477
|
+
filepath = File.join(topicpath, "notices.db")
|
478
|
+
db = RecordxSqlite.new(filepath, table: 'notices')
|
479
|
+
|
480
|
+
dx = Dynarex.new(File.join(topicpath, 'feed.xml'))
|
481
|
+
[topic, OpenStruct.new(title: dx.title, image: dx.image, bio: dx.bio, db: db)]
|
482
|
+
|
483
|
+
end.to_h
|
484
|
+
|
485
|
+
#return topics.inspect
|
486
|
+
rows = topics.flat_map do |topic, r|
|
487
|
+
|
488
|
+
a = r.db.all.select {|x| x.description =~ /#{q}/i}
|
489
|
+
a.map do |rx|
|
490
|
+
link = "%s/%s/status/%s" % [@urlbase, topic, rx.noticeid]
|
491
|
+
OpenStruct.new(rx.to_h.merge({topic: topic, title: r.title, image: r.image, link: link}))
|
492
|
+
end
|
493
|
+
|
494
|
+
end
|
495
|
+
|
496
|
+
|
497
|
+
#return rows.inspect
|
498
|
+
s = ''
|
499
|
+
|
500
|
+
notices = rows.sort_by {|x| -(x.id.to_i)}.take(20).map do |rx|
|
501
|
+
|
502
|
+
|
503
|
+
card2 = ''
|
504
|
+
rawcard = rx.to_h[:card]
|
505
|
+
|
506
|
+
card2 = if rawcard and rawcard.length > 10 then
|
507
|
+
|
508
|
+
card = JSON.parse(rawcard, symbolize_names: true)
|
509
|
+
|
510
|
+
if card.is_a? Hash then
|
511
|
+
@card.render(dx, rx, card)
|
512
|
+
end
|
513
|
+
|
514
|
+
else
|
515
|
+
''
|
516
|
+
end
|
517
|
+
|
518
|
+
#rx.description
|
519
|
+
t2 = Time.at rx.id.to_s[0..9].to_i
|
520
|
+
relative_time = Unichron.new(t2).elapsed
|
521
|
+
|
522
|
+
d = t2.strftime("%I:%M%p %b %d %Y")
|
523
|
+
|
524
|
+
#desc = rx.description.gsub(/<\/?p>/,'').gsub('<','<').gsub('>','>')
|
525
|
+
|
526
|
+
topic = rx.topic
|
527
|
+
title, image, bio = %i(title image bio).map do |x|
|
528
|
+
topics[topic].method(x).call
|
529
|
+
end
|
530
|
+
|
531
|
+
description = if rx.description.length > 1 then
|
532
|
+
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
533
|
+
doc.root.xpath('img|div').each(&:delete)
|
534
|
+
"<p>%s</p>" % doc.root.xml
|
535
|
+
else
|
536
|
+
''
|
537
|
+
end
|
538
|
+
|
539
|
+
utitle, uimage, ubio = title, image, bio
|
540
|
+
@w.render :notice, binding
|
541
|
+
|
542
|
+
|
543
|
+
end
|
544
|
+
#return notices.inspect
|
545
|
+
|
546
|
+
s += if notices.any? then
|
547
|
+
notices.join
|
548
|
+
else
|
549
|
+
"<p>No results for #{q}</p>"
|
550
|
+
end
|
551
|
+
|
552
|
+
#ref = @env["HTTP_REFERER"]
|
553
|
+
ref = referer
|
554
|
+
ref = '../' if ref =~ /(?:status\/\d+|search)/
|
555
|
+
svg = @w.render 'svg/backarrow', binding
|
556
|
+
back = ref ? "<a href='#{ref}'>#{svg}</a>" : ''
|
557
|
+
|
558
|
+
@w.render :search_pg, binding
|
559
|
+
|
560
|
+
|
561
|
+
end
|
562
|
+
|
563
|
+
|
564
|
+
end
|
565
|
+
|
566
|
+
class Main
|
567
|
+
|
568
|
+
def initialize(basepath, xslfile, statuscss_url, statuslistcss_url,
|
569
|
+
weblet_file, static_urlbase, urlbase)
|
570
|
+
|
571
|
+
weblet = Weblet.new(weblet_file)
|
572
|
+
@status = StatusView.new(basepath, xslfile, statuscss_url, weblet)
|
573
|
+
@statuslist = StatusListView.new(basepath, statuslistcss_url,
|
574
|
+
static_urlbase, weblet)
|
575
|
+
@hashtag = HashtagQueryView.new(basepath, statuslistcss_url, weblet,
|
576
|
+
static_urlbase, urlbase)
|
577
|
+
@search = SearchQueryView.new(basepath, statuslistcss_url, weblet,
|
578
|
+
static_urlbase, urlbase)
|
579
|
+
|
580
|
+
end
|
581
|
+
|
582
|
+
def status(topic, rawid, referer)
|
583
|
+
@status.render topic, rawid, referer
|
584
|
+
end
|
585
|
+
|
586
|
+
def status_list(username)
|
587
|
+
@statuslist.render username
|
588
|
+
end
|
589
|
+
|
590
|
+
def hashtag_query(s, referer)
|
591
|
+
@hashtag.render s, referer
|
592
|
+
end
|
593
|
+
|
594
|
+
def search_query(s, referer)
|
595
|
+
@search.render s, referer
|
596
|
+
end
|
337
597
|
|
338
598
|
end
|
339
599
|
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
iGAgDWBQqM/kdjDslqjBGtyWyFyuYHzXMU1gO/P0aE3rh1enqahZ8BqY+gxXLGrR
|
36
36
|
sU+WFV9qPqoqNOG0tOknOZXN
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2021-04-
|
38
|
+
date: 2021-04-05 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: down
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
version: '0.3'
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.3.
|
69
|
+
version: 0.3.3
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0.3'
|
77
77
|
- - ">="
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: 0.3.
|
79
|
+
version: 0.3.3
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: dynarex
|
82
82
|
requirement: !ruby/object:Gem::Requirement
|
metadata.gz.sig
CHANGED
Binary file
|