mns_subscriber 0.4.9 → 0.6.2
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.tar.gz.sig +0 -0
- data/lib/mns_subscriber.rb +109 -11
- metadata +50 -46
- 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: 2099c1bf98a5fa9859568e0ce7e71f1c0fa1eb695254241d2b47d99aac67472e
|
4
|
+
data.tar.gz: de2866f869b308ea2b5b18e982480a3a29ebf839f67a196c1c74517f1b79c2f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c9b72b377b23bb5070991510caab1ec8d5a208b848bd2065388459fd5e731ea9b325edd751f68853ecf8c6c4bd82ebe9df2a9171667728d5f1b9371dbc614ee
|
7
|
+
data.tar.gz: 31468678c034180943413d76f0c728e5848aafb9253d06ecf9255d647f8e56afe041ecfffbf24917571210dd57d6f11f23943323b1d71b317d32387d503cea7f
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/mns_subscriber.rb
CHANGED
@@ -12,7 +12,10 @@ require 'recordx_sqlite'
|
|
12
12
|
class MNSSubscriber < SPSSub
|
13
13
|
|
14
14
|
def initialize(host: 'sps', port: 59000, dir: '.', options: {},
|
15
|
-
timeline: nil)
|
15
|
+
timeline: nil, log: nil, hashtag_url: nil)
|
16
|
+
|
17
|
+
@log = log
|
18
|
+
log.info 'mns_subscriber/initialize: active' if log
|
16
19
|
|
17
20
|
# note: a valid url_base must be provided
|
18
21
|
|
@@ -21,13 +24,30 @@ class MNSSubscriber < SPSSub
|
|
21
24
|
dx_xslt: '/xsl/dynarex.xsl',
|
22
25
|
rss_xslt: '/xsl/feed.xsl',
|
23
26
|
target_page: :page,
|
24
|
-
target_xslt: '/xsl/page.xsl'
|
27
|
+
target_xslt: '/xsl/page.xsl',
|
28
|
+
local_media_path: '/home/user/media',
|
29
|
+
url_media_path: 'http://media.yourwebsitehere.co.uk/'
|
25
30
|
}.merge(options)
|
26
31
|
|
27
|
-
super(host: host, port: port)
|
32
|
+
super(host: host, port: port, log: log)
|
28
33
|
@filepath, @timeline = dir, timeline
|
29
34
|
|
30
35
|
@index = nil
|
36
|
+
@hashtags = nil
|
37
|
+
|
38
|
+
|
39
|
+
if hashtag_url then
|
40
|
+
|
41
|
+
@hashtag_url = @options[:url_base] + hashtag_url.sub(/^\//,'')
|
42
|
+
|
43
|
+
hashtag_path = File.join(dir, 'hashtag')
|
44
|
+
tagdb = File.join(hashtag_path, 'index.db')
|
45
|
+
FileUtils.mkdir_p File.dirname(tagdb)
|
46
|
+
|
47
|
+
h = {hashtags: {id: '', tag: '', topic: '', noticeid: ''}}
|
48
|
+
@hashtags = RecordxSqlite.new(tagdb, table: h )
|
49
|
+
|
50
|
+
end
|
31
51
|
|
32
52
|
end
|
33
53
|
|
@@ -38,6 +58,8 @@ class MNSSubscriber < SPSSub
|
|
38
58
|
private
|
39
59
|
|
40
60
|
def ontopic(topic, msg)
|
61
|
+
|
62
|
+
@log.info 'mns_subscriber/ontopic: topic: ' + topic.inspect if @topic
|
41
63
|
|
42
64
|
a = topic.split('/')
|
43
65
|
puts "%s: %s %s" % [topic, Time.now.to_s, msg.inspect]
|
@@ -57,10 +79,48 @@ class MNSSubscriber < SPSSub
|
|
57
79
|
|
58
80
|
update_attributes(:title, subtopic=a[-2], title=msg)
|
59
81
|
|
82
|
+
when :image
|
83
|
+
|
84
|
+
update_attributes(:image, subtopic=a[-2], title=msg)
|
85
|
+
|
60
86
|
when :delete
|
61
87
|
|
62
88
|
delete_notice(subtopic=a[-2], msg)
|
63
89
|
|
90
|
+
when :json
|
91
|
+
|
92
|
+
# JSON contains a message and 1 or more media files
|
93
|
+
h = JSON.parse msg, symbolize_names: true
|
94
|
+
|
95
|
+
subtopic = a[-2]
|
96
|
+
|
97
|
+
t = Time.now
|
98
|
+
id = t.to_i.to_s + t.strftime("%2N")
|
99
|
+
|
100
|
+
filepath = File.join(@options[:local_media_path], 'images')
|
101
|
+
|
102
|
+
a = h[:files].map.with_index do |f,i|
|
103
|
+
|
104
|
+
file = "%s%s" % [(id.to_i + i+1).to_s(36).reverse, File.extname(f)]
|
105
|
+
dest = File.join(filepath, file)
|
106
|
+
|
107
|
+
FileUtils.cp f, dest
|
108
|
+
FileUtils.chmod 0755, dest
|
109
|
+
|
110
|
+
dir = File.extname(file) =~ /\.(?:jpg|png)/ ? 'images' : ''
|
111
|
+
url = [@options[:url_media_path], dir, file].join('/')
|
112
|
+
|
113
|
+
href = [@options[:url_base].sub(/\/$/,''), subtopic, 'status', id,
|
114
|
+
'photo', (i+1).to_s ].join('/')
|
115
|
+
"<a href='%s'><img class='img1' src='%s'/></a>" % [href, url]
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
div = a.any? ? "<div id='media'>#{a.join}</div>" : ''
|
120
|
+
|
121
|
+
add_notice(subtopic, h[:msg] + "\n" + div, id)
|
122
|
+
|
123
|
+
|
64
124
|
else
|
65
125
|
|
66
126
|
subtopic, id = a[1..-1]
|
@@ -70,13 +130,20 @@ class MNSSubscriber < SPSSub
|
|
70
130
|
|
71
131
|
end
|
72
132
|
|
73
|
-
def add_notice(topic, raw_msg, raw_id=
|
133
|
+
def add_notice(topic, raw_msg, raw_id=nil)
|
74
134
|
|
135
|
+
@log.info 'mns_subscriber/add_notice: active' if @log
|
75
136
|
topic_dir = File.join(@filepath, topic)
|
76
|
-
|
77
|
-
|
137
|
+
|
138
|
+
options = @options.clone
|
139
|
+
options.delete :local_media_path
|
140
|
+
options.delete :url_media_path
|
141
|
+
|
142
|
+
notices = DailyNotices.new topic_dir, options.merge(identifier: topic,
|
143
|
+
title: topic.capitalize + ' daily notices', log: @log)
|
78
144
|
|
79
|
-
|
145
|
+
t = Time.now
|
146
|
+
id = (raw_id || t.to_i.to_s + t.strftime("%2N")).to_i
|
80
147
|
|
81
148
|
# strip out any JSON from the end of the message
|
82
149
|
msg, raw_json = raw_msg.split(/(?=\{.*)/)
|
@@ -89,6 +156,27 @@ class MNSSubscriber < SPSSub
|
|
89
156
|
mtlite.to_s
|
90
157
|
end
|
91
158
|
|
159
|
+
if @hashtag_url then
|
160
|
+
|
161
|
+
tags = desc.scan(/(?<=#)\w+/)
|
162
|
+
|
163
|
+
desc.gsub!(/#\w+/) do |x|
|
164
|
+
"<a href='%s%s'>%s</a>" % [@hashtag_url, x[1..-1], x]
|
165
|
+
end
|
166
|
+
|
167
|
+
# add the record to the database
|
168
|
+
tags.each do |tag|
|
169
|
+
|
170
|
+
t = Time.now
|
171
|
+
id2 = (t.to_i.to_s + t.strftime("%2N")).to_i
|
172
|
+
h = {id: id2, tag: tag, topic: topic, noticeid: id}
|
173
|
+
|
174
|
+
@hashtags.create h if @hashtags
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
|
92
180
|
title = mtlite.to_s.lines.first.chomp
|
93
181
|
title = title[0..136] + ' ...' if title.length > 140
|
94
182
|
|
@@ -103,8 +191,13 @@ class MNSSubscriber < SPSSub
|
|
103
191
|
return if return_status == :duplicate
|
104
192
|
|
105
193
|
rxnotices = RecordxSqlite.new(File.join(topic_dir, 'notices.db'),
|
106
|
-
table: {notices: {id: 0, message: ''}})
|
107
|
-
|
194
|
+
table: {notices: {id: 0, description: '', message: ''}})
|
195
|
+
|
196
|
+
begin
|
197
|
+
rxnotices.create id: id.to_s, description: desc, message: msg
|
198
|
+
rescue
|
199
|
+
puts 'warning: rxnotices.create -> ' + ($!).inspect
|
200
|
+
end
|
108
201
|
|
109
202
|
if raw_json then
|
110
203
|
|
@@ -125,11 +218,16 @@ class MNSSubscriber < SPSSub
|
|
125
218
|
|
126
219
|
def delete_notice(topic, msg)
|
127
220
|
|
221
|
+
|
128
222
|
topic_dir = File.join(@filepath, topic)
|
129
223
|
|
224
|
+
id = msg.to_i
|
225
|
+
|
226
|
+
feed = DailyNotices.new topic_dir, log: @log
|
227
|
+
feed.delete id
|
228
|
+
|
130
229
|
notices = RecordxSqlite.new(File.join(topic_dir, 'notices.db'),
|
131
230
|
table: 'notices')
|
132
|
-
id = msg.to_i
|
133
231
|
notices.delete id
|
134
232
|
|
135
233
|
indexdb = File.join(topic_dir, 'index.db')
|
@@ -167,4 +265,4 @@ class MNSSubscriber < SPSSub
|
|
167
265
|
|
168
266
|
end
|
169
267
|
|
170
|
-
end
|
268
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mns_subscriber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,49 +10,53 @@ 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
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjEwMjI0MTMzNzMzWhcN
|
15
|
+
MjIwMjI0MTMzNzMzWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjw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aQvZKi8inGHgLmM61ABpIGTZ8lwzR6fizANDF6EQ7vNixJMSZExzP
|
32
|
+
s1BgeI/oTI1Y7UNeUtwWA8NkQ1bczUBH4FDUab4QRIbBYhXz+Hs8ddtugTzcmRwf
|
33
|
+
W0wI6iCh95fKaCbmSS5MY3dYMexH07A1XFGyHWOogCEWWYZ4ho+a44Fm0Uotp5ky
|
34
|
+
TjsXYJbdzlsAVQKfCSIfCi3T/k4bp/2wc342j/WYjkKLN4aZID+E9P/VX1Nc0m/s
|
35
|
+
yOAycOYzp7fxmPl3/HV5D0YOJwuy1XslA50GQJwq12A5vMyUGUCHuxH/zKZcM/zr
|
36
|
+
0QZaKiVqq5ZeGvni0eQSavhQ
|
33
37
|
-----END CERTIFICATE-----
|
34
|
-
date:
|
38
|
+
date: 2021-03-06 00:00:00.000000000 Z
|
35
39
|
dependencies:
|
36
40
|
- !ruby/object:Gem::Dependency
|
37
41
|
name: mtlite
|
38
42
|
requirement: !ruby/object:Gem::Requirement
|
39
43
|
requirements:
|
40
|
-
- - "~>"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '0.3'
|
43
44
|
- - ">="
|
44
45
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
46
|
+
version: 0.4.0
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.4'
|
46
50
|
type: :runtime
|
47
51
|
prerelease: false
|
48
52
|
version_requirements: !ruby/object:Gem::Requirement
|
49
53
|
requirements:
|
50
|
-
- - "~>"
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '0.3'
|
53
54
|
- - ">="
|
54
55
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
56
|
+
version: 0.4.0
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0.4'
|
56
60
|
- !ruby/object:Gem::Dependency
|
57
61
|
name: sps-sub
|
58
62
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,7 +66,7 @@ dependencies:
|
|
62
66
|
version: '0.3'
|
63
67
|
- - ">="
|
64
68
|
- !ruby/object:Gem::Version
|
65
|
-
version: 0.3.
|
69
|
+
version: 0.3.7
|
66
70
|
type: :runtime
|
67
71
|
prerelease: false
|
68
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -72,49 +76,49 @@ dependencies:
|
|
72
76
|
version: '0.3'
|
73
77
|
- - ">="
|
74
78
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.3.
|
79
|
+
version: 0.3.7
|
76
80
|
- !ruby/object:Gem::Dependency
|
77
81
|
name: daily_notices
|
78
82
|
requirement: !ruby/object:Gem::Requirement
|
79
83
|
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0.6'
|
83
84
|
- - ">="
|
84
85
|
- !ruby/object:Gem::Version
|
85
|
-
version: 0.
|
86
|
+
version: 0.7.0
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.7'
|
86
90
|
type: :runtime
|
87
91
|
prerelease: false
|
88
92
|
version_requirements: !ruby/object:Gem::Requirement
|
89
93
|
requirements:
|
90
|
-
- - "~>"
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: '0.6'
|
93
94
|
- - ">="
|
94
95
|
- !ruby/object:Gem::Version
|
95
|
-
version: 0.
|
96
|
+
version: 0.7.0
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0.7'
|
96
100
|
- !ruby/object:Gem::Dependency
|
97
101
|
name: recordx_sqlite
|
98
102
|
requirement: !ruby/object:Gem::Requirement
|
99
103
|
requirements:
|
100
104
|
- - "~>"
|
101
105
|
- !ruby/object:Gem::Version
|
102
|
-
version: '0.
|
106
|
+
version: '0.3'
|
103
107
|
- - ">="
|
104
108
|
- !ruby/object:Gem::Version
|
105
|
-
version: 0.
|
109
|
+
version: 0.3.1
|
106
110
|
type: :runtime
|
107
111
|
prerelease: false
|
108
112
|
version_requirements: !ruby/object:Gem::Requirement
|
109
113
|
requirements:
|
110
114
|
- - "~>"
|
111
115
|
- !ruby/object:Gem::Version
|
112
|
-
version: '0.
|
116
|
+
version: '0.3'
|
113
117
|
- - ">="
|
114
118
|
- !ruby/object:Gem::Version
|
115
|
-
version: 0.
|
119
|
+
version: 0.3.1
|
116
120
|
description:
|
117
|
-
email:
|
121
|
+
email: digital.robertson@gmail.com
|
118
122
|
executables: []
|
119
123
|
extensions: []
|
120
124
|
extra_rdoc_files: []
|
@@ -140,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
144
|
version: '0'
|
141
145
|
requirements: []
|
142
146
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.
|
147
|
+
rubygems_version: 2.7.10
|
144
148
|
signing_key:
|
145
149
|
specification_version: 4
|
146
150
|
summary: Creates microblog posts from different identities by subscribing to the SPS
|
metadata.gz.sig
CHANGED
Binary file
|