mns_subscriber 0.4.9 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: '0889ecb9db1e5bcf41e3a7ab47ce04d252dc05e4'
4
- data.tar.gz: afc998311ab905e361e4cb7b09a75515fa5e7de5
2
+ SHA256:
3
+ metadata.gz: 2099c1bf98a5fa9859568e0ce7e71f1c0fa1eb695254241d2b47d99aac67472e
4
+ data.tar.gz: de2866f869b308ea2b5b18e982480a3a29ebf839f67a196c1c74517f1b79c2f8
5
5
  SHA512:
6
- metadata.gz: 9c2f8a3e55c0be33a4a984c6d9af46fa554dbf7b21fc02e12558e50bd1cbf5f53ceea4117996607c82b22249c4dadbdcd8699da77b751c72fb7139db7bae8bba
7
- data.tar.gz: c5e5d5ed646a59c369f7967c16781a3c2354a45ffe2b2d1685c09b0ea7123f62de2a8b78d1f369c3d11008366246cce3ecff32d6b871749d4ee08851aefcf9ad
6
+ metadata.gz: 3c9b72b377b23bb5070991510caab1ec8d5a208b848bd2065388459fd5e731ea9b325edd751f68853ecf8c6c4bd82ebe9df2a9171667728d5f1b9371dbc614ee
7
+ data.tar.gz: 31468678c034180943413d76f0c728e5848aafb9253d06ecf9255d647f8e56afe041ecfffbf24917571210dd57d6f11f23943323b1d71b317d32387d503cea7f
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -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=Time.now)
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
- notices = DailyNotices.new topic_dir, @options.merge(identifier: topic,
77
- title: topic.capitalize + ' daily notices')
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
- id = (raw_id || Time.now).to_i
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
- rxnotices.create id: id.to_s, message: msg
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.9
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
- MIIDljCCAn6gAwIBAgIBATANBgkqhkiG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gNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU0a7RWUQ4
26
+ bjy71dOj2inlBZ1u+NIwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
27
+ c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEANZXVYK9Ut5FWc27EOT5ajSB/DVW6GXUMWGXNVLll
29
+ x6o5OX9r4xHlINGsTEI4q01kCBQsJCjQKNFOrUss+TsEFgXremusnniPwypvoCZh
30
+ JAmmUktsIKuKmgkJ6h1hhuJf6g90++v4iVvBHt53nhN8NaGYe4Oc2OwXTfxHam0X
31
+ JfCSR+Aw2QfaQvZKi8inGHgLmM61ABpIGTZ8lwzR6fizANDF6EQ7vNixJMSZExzP
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: 2017-07-04 00:00:00.000000000 Z
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.3.4
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.3.4
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.5
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.5
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.6.2
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.6.2
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.2'
106
+ version: '0.3'
103
107
  - - ">="
104
108
  - !ruby/object:Gem::Version
105
- version: 0.2.6
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.2'
116
+ version: '0.3'
113
117
  - - ">="
114
118
  - !ruby/object:Gem::Version
115
- version: 0.2.6
119
+ version: 0.3.1
116
120
  description:
117
- email: james@jamesrobertson.eu
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.6.8
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