mymedia 0.1.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.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/mymedia.rb +265 -0
  4. data.tar.gz.sig +0 -0
  5. metadata +167 -0
  6. metadata.gz.sig +1 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e8deccd266d93ef836bfb6b5297a3746014cb0aa
4
+ data.tar.gz: 686ae87c9392d2632a6c0098e3f67602d3da6ede
5
+ SHA512:
6
+ metadata.gz: 20fbf7265cac44738168fd8e59b3317c9a9dd269b336fc5f0badbdd3a18570fe03438dcf223a82659c448283d542d7fc7bfabde750f683928b496b32d2b0283f
7
+ data.tar.gz: 4fc623c55c4f6134f73363870147a279d216131823a81346480cf14e19a07d8dfd436c70cf7e286fcb7bbe8ca0a72ada4342bdb8abd6c08f4011882fdcd08992
checksums.yaml.gz.sig ADDED
Binary file
data/lib/mymedia.rb ADDED
@@ -0,0 +1,265 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: mymedia.rb
4
+
5
+ require 'time'
6
+ require 'fileutils'
7
+ require 'logger'
8
+ require 'dynarex'
9
+ require 'sps-pub'
10
+ require 'dir-to-xml'
11
+ require 'dataisland'
12
+ require 'increment'
13
+
14
+
15
+ module MyMedia
16
+
17
+ class Publisher
18
+
19
+ def publish_dynarex(dynarex_filepath='', \
20
+ record={title: '',url: '', raw_url: ''}, options={})
21
+
22
+ opt = {id: nil, rss: false}.merge(options)
23
+
24
+ dynarex = if File.exists? dynarex_filepath then
25
+ Dynarex.new(dynarex_filepath)
26
+ else
27
+ Dynarex.new(@schema)
28
+ end
29
+
30
+ dynarex.create record, opt[:id]
31
+ dynarex.save dynarex_filepath
32
+ publish_html(dynarex_filepath)
33
+
34
+
35
+ if opt[:rss] == true then
36
+
37
+ dynarex.xslt_schema = dynarex.summary[:xslt_schema]
38
+ rss_filepath = dynarex_filepath.sub(/\.xml$/,'_rss.xml')
39
+ File.open(rss_filepath, 'w'){|f| f.write dynarex.to_rss }
40
+ end
41
+
42
+ end
43
+
44
+ def publish_html(filepath)
45
+
46
+ path2 = File.dirname(filepath)
47
+
48
+ dataisland = DataIsland.new(path2 + '/index-template.html')
49
+ File.open(path2 + '/index.html','w'){|f| f.write dataisland.html_doc.xml pretty: true}
50
+ end
51
+
52
+ end
53
+
54
+ class Base < Publisher
55
+
56
+ attr_reader :to_s
57
+
58
+ def initialize(media_type: 'blog', public_type: 'blog', ext: 'txt', config: nil)
59
+
60
+ super()
61
+ @schema = 'posts/post(title, url, raw_url)'
62
+ @logger = Logger.new('/tmp/mymedia.log','daily')
63
+
64
+ @home = config[:home]
65
+ @website = config[:website]
66
+ @dynamic_website = config[:dynamic_website]
67
+ @www = config[:www]
68
+ @domain = @website[/[^\.]+\.[^\.]+$/]
69
+
70
+ @sps = config[:sps]
71
+
72
+ @media_type = media_type
73
+ @public_type = public_type ||= @media_type
74
+
75
+ @xslt_schema = 'channel[title:title,description:desc]/' + \
76
+ 'item(title:title,link:url)'
77
+ @ext = ext
78
+ @rss = false
79
+ Dir.chdir @home
80
+ end
81
+
82
+ def add_feed_item(raw_msg, record, options={})
83
+
84
+ dynarex_filepath = File.join([@home, @public_type, 'dynarex.xml'])
85
+ id = Increment.update(File.join([@home, @public_type, 'counter.txt']))
86
+ static_url = @static_baseurl + id
87
+ record[:uri] = static_url
88
+
89
+ publish_dynarex(dynarex_filepath, record, {id: id}.merge(options))
90
+ publish_timeline(raw_msg, static_url)
91
+ publish_html(@home + '/index.html')
92
+ end
93
+
94
+ def auto_copy_publish(raw_msg='')
95
+
96
+ filename = DirToXML.new(@media_src).select_by_ext(@ext)\
97
+ .sort_by(:last_modified).last[:name]
98
+ copy_publish( filename ,raw_msg)
99
+ end
100
+
101
+ def copy_publish(filename, raw_msg='')
102
+ file_publish(File.join(@media_src,filename), raw_msg)
103
+ end
104
+
105
+
106
+ private
107
+
108
+ def file_publish(src_path, raw_msg='')
109
+
110
+ raise @logger.debug("source file not found") unless File.exists? src_path
111
+ ext = File.extname(src_path)
112
+ @target_ext ||= ext
113
+
114
+ public_path = "%s/%s/%shrs%s" % [@public_type, \
115
+ Time.now.strftime('%Y/%b/%d').downcase, Time.now.strftime('%H%M'),
116
+ @target_ext]
117
+ public_path2 = "%s/%s/%shrs%s%s" % [@public_type, \
118
+ Time.now.strftime('%Y/%b/%d').downcase, Time.now.strftime('%H%M'),
119
+ Time.now.strftime('%S%2N'), @target_ext]
120
+
121
+ raw_destination = "%s/%s/%s" % [@home, 'r', public_path]
122
+
123
+ if File.exists? raw_destination then
124
+ raw_destination = "%s/%s/%s" % [@home, 'r', public_path2]
125
+ public_path = public_path2
126
+ end
127
+
128
+ destination = "%s/%s" % [@home, public_path]
129
+ FileUtils.mkdir_p File.dirname(raw_destination)
130
+ FileUtils.mkdir_p File.dirname(destination)
131
+
132
+ raw_msg = raw_msg.join if raw_msg.is_a? Array
133
+
134
+ raw_msg = src_path[/([^\/]+)\.\w+$/,1] + ' ' + raw_msg if raw_msg
135
+
136
+
137
+ if block_given? then
138
+ raw_msg, target_url = yield(destination, raw_destination)
139
+ static_url = target_url
140
+ else
141
+ FileUtils.cp src_path, destination
142
+ FileUtils.cp src_path, raw_destination
143
+ end
144
+
145
+
146
+ raw_msg = raw_msg.join if raw_msg.is_a? Array
147
+
148
+ static_filename = if raw_msg.length > 0 then
149
+ normalize(raw_msg) + File.extname(destination)
150
+ else
151
+ File.basename(src_path)
152
+ end
153
+
154
+ static_path = "%s/%s/%s" % [@public_type, \
155
+ Time.now.strftime('%Y/%b/%d').downcase, static_filename]
156
+
157
+ raw_static_destination = "%s/%s/%s" % [@home, 'r',static_path]
158
+
159
+ static_destination = "%s/%s" % [@home, static_path]
160
+ FileUtils.cp destination, static_destination
161
+ FileUtils.cp raw_destination, raw_static_destination
162
+
163
+ target_url ||= "%s/%s" % [@website, public_path]
164
+ static_url ||= "%s/%s" % [@website, static_path]
165
+
166
+ if raw_msg.length > 0 then
167
+ msg = "%s %s" % [target_url, raw_msg ]
168
+ else
169
+ msg = "the %s %s %s" % [notice, @public_type.sub(/s$/,''), target_url]
170
+ end
171
+
172
+ sps_message = [@sps[:default_subscriber] + ': publish', @public_type,
173
+ target_url, static_url, "'" + raw_msg + "'"]
174
+
175
+ topic, msg = sps_message.join(' ').split(/:\s*/,2)
176
+ send_message(topic: topic, msg: msg)
177
+
178
+ static_url
179
+
180
+ end
181
+
182
+ def normalize(s)
183
+ r = s.downcase.gsub(/\s#\w+/,'').strip.gsub(/\W/,'-').gsub(/-{2,}/,'-').gsub(/^-|-$/,'')
184
+ return s.scan(/#(\w+)/)[0..1].join('_').downcase if r.empty?
185
+ return r
186
+ end
187
+
188
+ def notice()
189
+
190
+ case
191
+ when Time.now.hour < 10
192
+ "morning"
193
+ when Time.now.hour < 12
194
+ "late morning"
195
+ when Time.now.hour >= 12 && Time.now.hour <= 13
196
+ "lunch time"
197
+ when Time.now.hour > 13 && Time.now.hour < 16
198
+ "afternoon"
199
+ when Time.now.hour < 18
200
+ "late afternoon"
201
+ when Time.now.hour >= 18
202
+ "evening"
203
+ end
204
+ end
205
+
206
+ def send_message(topic: @sps[:default_subscriber], msg: msg)
207
+
208
+ fqm = "%s: %s" % [topic, msg]
209
+ SPSPub.notice fqm, address: @sps[:address]
210
+ end
211
+
212
+ end
213
+
214
+ class Frontpage < Publisher
215
+
216
+ def initialize(conf: nil, public_type: '', rss: nil)
217
+
218
+ @home = conf[:home]
219
+ @public_type = public_type
220
+ @rss = rss
221
+
222
+ @logger = Logger.new('/tmp/mymedia.log','daily')
223
+ end
224
+
225
+ def publish_frontpage(s='index.html')
226
+ publish_html(@home + '/' + s)
227
+ 'frontpage published'
228
+ end
229
+
230
+
231
+ def publish_to_lists(record={}, public_type=nil)
232
+
233
+ @public_type = public_type if public_type
234
+
235
+ raw_msg, static_url, target_url = \
236
+ record[:title], record[:url], record[:static_url]
237
+ dynarex_filepath = "%s/%s/dynarex.xml" % [@home, @public_type]
238
+ raw_dynarex_filepath = "%s/r/%s/dynarex.xml" % [@home, @public_type]
239
+
240
+ publish_dynarex(dynarex_filepath, record, {rss: @rss || false})
241
+ publish_dynarex(raw_dynarex_filepath, record, {rss: @rss || false})
242
+ publish_timeline(raw_msg, static_url, target_url)
243
+
244
+ end
245
+
246
+
247
+ def publish_timeline(raw_msg, static_url, target_url='')
248
+
249
+ timeline_filepath = "%s/timeline/dynarex.xml" % @home
250
+ record = Dynarex.new(@home + '/dynarex.xml').find_by_title(@public_type)
251
+ thumbnail, subject_url = record.thumbnail, record.url
252
+
253
+ content = {
254
+ title: raw_msg,
255
+ url: static_url,
256
+ thumbnail: thumbnail,
257
+ subject_url: subject_url,
258
+ raw_url: target_url
259
+ }
260
+
261
+ publish_dynarex(timeline_filepath, content, rss: true)
262
+
263
+ end
264
+ end
265
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mymedia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
+ YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
+ 8ixkARkWAmV1MB4XDTE0MTAxMTA2MjU1MloXDTE1MTAxMTA2MjU1MlowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
+ ggEBAKKAkTSe5/95+/xlS5ClnMGILqiJBa8mcl9ZfH028fD6jh80dbbFcmOeukF5
19
+ rB2ZwPPCYBj+tZgrimRdzIJCXiAH0vF+uf/bA3nkSpVkcKF3ff2VaftsqGedyO/2
20
+ C3WYi/3YK1p/6vRR5aNoiCqbeIEwup683NOCAXoJ3YpAapZSBKRR050b3Bl90/fU
21
+ G3MPLi6wV9sJdzZRFytfNM/4StojqfDVHYkCytvsaKf7uNqfOBZx9EGW5mBHDUmq
22
+ jGGC6ZWfxrNsyprxelUvlb0LoxLKHByuUmcjDJGwKi0pBfIIBBYB3cEdLqNktZRm
23
+ 2iHlQ3Qc7JMiwbNvxmQSWRnl4g8CAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
+ DwQEAwIEsDAdBgNVHQ4EFgQUekt+5D5jnAxrvLBhLY6+3akzaCowJgYDVR0RBB8w
25
+ HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEALupwVNJM
27
+ erjU8TDycd/HnEaCREYkuTJTcwnyuX/slWA61sSlHpU+wbp8InU12AhqJJw6adr8
28
+ RdENSTGpV74qzOEYJiINEzkBLqlT4W3gZzw1DNc4ntUrVh4AXITrKZFXT2Ike2jy
29
+ 5Swrv93vgfpENg6oe+w/9cx6QYlKFcCGjl68h4IOl9SkPQKtXxtML6GleT1Tgl6l
30
+ evTjxChamJXYGQl8jNbytJ9NKiPOyJDDwoOrIw9bnnV435BELJqUVwlcvlE+00mp
31
+ AuNecS7mQYhxSVKaAH8VGzIiea4rbybYlYRsOllgAkcmCFTQW39mbtmMPtDedk1N
32
+ ZQNJr93cq0mf/Q==
33
+ -----END CERTIFICATE-----
34
+ date: 2014-10-11 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: dynarex
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.2'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.92
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.2'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 1.2.92
56
+ - !ruby/object:Gem::Dependency
57
+ name: sps-pub
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.4'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 0.4.0
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '0.4'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.4.0
76
+ - !ruby/object:Gem::Dependency
77
+ name: dir-to-xml
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.3'
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 0.3.3
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: '0.3'
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 0.3.3
96
+ - !ruby/object:Gem::Dependency
97
+ name: dataisland
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.1'
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: 0.1.14
106
+ type: :runtime
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: '0.1'
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: 0.1.14
116
+ - !ruby/object:Gem::Dependency
117
+ name: increment
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '0.1'
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: 0.1.4
126
+ type: :runtime
127
+ prerelease: false
128
+ version_requirements: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '0.1'
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: 0.1.4
136
+ description:
137
+ email: james@r0bertson.co.uk
138
+ executables: []
139
+ extensions: []
140
+ extra_rdoc_files: []
141
+ files:
142
+ - lib/mymedia.rb
143
+ homepage: https://github.com/jrobertson/mymedia
144
+ licenses:
145
+ - MIT
146
+ metadata: {}
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.2.2
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: Makes publishing to the web easier
167
+ test_files: []
metadata.gz.sig ADDED
@@ -0,0 +1 @@
1
+ P]�NBk��O#���B���,S��Fj%=�$��;�����=�`F[�U�+�_0��j�)���^U�5�h��X�mA@����W�F%���hlm�p�k��!�Z�eW�Tw�R��W��'娹�̚�����? `�v�{K�qk~�FB����|�H�Dk��r������+Q� �,$2a2x1S��G