granicus_migrate 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +52 -0
- data/bin/granicus_migrate +11 -0
- data/granicus_migrate.gemspec +28 -0
- data/lib/granicus_migrate_helper.rb +145 -0
- metadata +119 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
granicus_migrate (0.0.1)
|
5
|
+
faraday_middleware (~> 0.7.0)
|
6
|
+
granicus-platform-api (>= 0.9.1)
|
7
|
+
nokogiri (>= 1.5.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.2.6)
|
13
|
+
akami (1.0.0)
|
14
|
+
gyoku (>= 0.4.0)
|
15
|
+
builder (3.0.0)
|
16
|
+
faraday (0.7.5)
|
17
|
+
addressable (~> 2.2.6)
|
18
|
+
multipart-post (~> 1.1.3)
|
19
|
+
rack (< 2, >= 1.1.0)
|
20
|
+
faraday_middleware (0.7.0)
|
21
|
+
faraday (~> 0.7.3)
|
22
|
+
granicus-platform-api (0.9.1)
|
23
|
+
hashie (~> 1.0.0)
|
24
|
+
savon (~> 0.9.2)
|
25
|
+
gyoku (0.4.4)
|
26
|
+
builder (>= 2.1.2)
|
27
|
+
hashie (1.0.0)
|
28
|
+
httpi (0.9.5)
|
29
|
+
rack
|
30
|
+
multipart-post (1.1.3)
|
31
|
+
nokogiri (1.5.0)
|
32
|
+
nori (1.0.2)
|
33
|
+
rack (1.3.5)
|
34
|
+
savon (0.9.7)
|
35
|
+
akami (~> 1.0)
|
36
|
+
builder (>= 2.1.2)
|
37
|
+
gyoku (>= 0.4.0)
|
38
|
+
httpi (~> 0.9)
|
39
|
+
nokogiri (>= 1.4.0)
|
40
|
+
nori (~> 1.0)
|
41
|
+
wasabi (~> 2.0)
|
42
|
+
wasabi (2.0.0)
|
43
|
+
nokogiri (>= 1.4.0)
|
44
|
+
|
45
|
+
PLATFORMS
|
46
|
+
ruby
|
47
|
+
|
48
|
+
DEPENDENCIES
|
49
|
+
faraday_middleware (~> 0.7.0)
|
50
|
+
granicus-platform-api (>= 0.9.1)
|
51
|
+
granicus_migrate!
|
52
|
+
nokogiri (>= 1.5.0)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "granicus_migrate"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Javier Muniz"]
|
9
|
+
s.email = "javier@granicus.com"
|
10
|
+
s.summary = "Tool to mass-import files from old Webcasting.com customers to the Granicus Platform"
|
11
|
+
s.homepage = "http://github.com/granicus/granicus_migrate"
|
12
|
+
s.description = "Tool to mass-import files from old Webcasting.com customers to the Granicus Platform"
|
13
|
+
|
14
|
+
s.rubyforge_project = "granicus_migrate"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency('faraday_middleware', '~> 0.7.0')
|
22
|
+
s.add_development_dependency('granicus-platform-api','>= 0.9.1')
|
23
|
+
s.add_development_dependency('nokogiri','>= 1.5.0')
|
24
|
+
|
25
|
+
s.add_dependency('faraday_middleware', '~> 0.7.0')
|
26
|
+
s.add_dependency('granicus-platform-api','>= 0.9.1')
|
27
|
+
s.add_dependency('nokogiri','>= 1.5.0')
|
28
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'granicus-platform-api'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'optparse'
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
class GranicusMigrateHelper
|
7
|
+
attr_accessor :host, :username, :password, :directory
|
8
|
+
|
9
|
+
def initialize(args)
|
10
|
+
# Handle options
|
11
|
+
options = {}
|
12
|
+
@option_parser = OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: granicus_migrate [options]"
|
14
|
+
opts.separator ""
|
15
|
+
opts.separator "Specific options:"
|
16
|
+
|
17
|
+
# host
|
18
|
+
opts.on("-h","--host HOST","The Granicus platform host to load files into.") do |host|
|
19
|
+
@host = host
|
20
|
+
end
|
21
|
+
|
22
|
+
# username
|
23
|
+
opts.on("-u","--username USERNAME","The username to use to communicate with the Granicus host.") do |user|
|
24
|
+
@username = user
|
25
|
+
end
|
26
|
+
|
27
|
+
# password
|
28
|
+
opts.on("-p","--password PASSWORD","The password to use to communicate with the Granicus host.") do |pass|
|
29
|
+
@password = pass
|
30
|
+
end
|
31
|
+
|
32
|
+
# directory
|
33
|
+
opts.on("-d","--directory DIRECTORY", "The directory containing the HTML files to migrate.") do |dir|
|
34
|
+
@directory = dir
|
35
|
+
end
|
36
|
+
|
37
|
+
# No argument, shows at tail. This will print an options summary.
|
38
|
+
opts.on_tail("-?", "--help", "Show this message") do
|
39
|
+
puts opts
|
40
|
+
exit
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# parse options
|
45
|
+
@option_parser.parse!(ARGV)
|
46
|
+
end
|
47
|
+
|
48
|
+
def extract_text(tag)
|
49
|
+
if tag.class == Nokogiri::XML::Text
|
50
|
+
tag.text.gsub(' ',' ')
|
51
|
+
else
|
52
|
+
text = ''
|
53
|
+
tag.children.each {|child| text += extract_text child }
|
54
|
+
text
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def show_help
|
59
|
+
puts @option_parser
|
60
|
+
end
|
61
|
+
|
62
|
+
def missing_arguments?
|
63
|
+
return (@host.nil? or @username.nil? or @password.nil? or @directory.nil?)
|
64
|
+
end
|
65
|
+
|
66
|
+
def process_files
|
67
|
+
granicus = GranicusPlatformAPI::Client.new @host,@username,@password
|
68
|
+
clips = granicus.get_clips 1
|
69
|
+
clips.each do |clip|
|
70
|
+
# skip the file if we don't have a matching html document
|
71
|
+
fname = @directory + clip.Name + '.html'
|
72
|
+
unless File.exists? fname
|
73
|
+
puts "Couldn't find file: #{fname} (skipping)"
|
74
|
+
next
|
75
|
+
end
|
76
|
+
|
77
|
+
f = File.open fname
|
78
|
+
sushi = Nokogiri::HTML f
|
79
|
+
f.close
|
80
|
+
puts "Processing #{clip.Name}..."
|
81
|
+
paragraphs = sushi.xpath('//p')
|
82
|
+
meta_array = []
|
83
|
+
paragraphs.count.times do |index|
|
84
|
+
tag = paragraphs[index]
|
85
|
+
# process all of the text and see if we have an item
|
86
|
+
text = extract_text tag
|
87
|
+
text.gsub!(/\u00a0/,' ')
|
88
|
+
next if not text =~ /\w\w/
|
89
|
+
|
90
|
+
meta = GranicusPlatformAPI::MetaDataData.new
|
91
|
+
meta.Payload = GranicusPlatformAPI::AgendaItem.new
|
92
|
+
meta.Name = text
|
93
|
+
|
94
|
+
# grab any links in the tag
|
95
|
+
link_tag = tag.xpath('.//a')[0]
|
96
|
+
unless link_tag.nil?
|
97
|
+
unless link_tag['href'].nil?
|
98
|
+
meta.TimeStamp = link_tag['href'].gsub(/.*?(\d+\.\d\d\d).*/,'\\1').to_i
|
99
|
+
link_tag['href'] = 'javascript:void(0);'
|
100
|
+
link_tag['onclick'] = "top.SetPlayerPosition('0:#{meta.TimeStamp}',null);"
|
101
|
+
link_tag.remove_attribute 'target'
|
102
|
+
else
|
103
|
+
puts 'Unabled to find href in link: ' + link_tag.to_s
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
meta_array << meta
|
108
|
+
end
|
109
|
+
|
110
|
+
# write the html file and upload it to the platform
|
111
|
+
File.open('agenda_temp.html', 'w') {|f| f.write(sushi.to_html) }
|
112
|
+
|
113
|
+
options = {
|
114
|
+
:headers => {
|
115
|
+
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
116
|
+
'Host' => @host,
|
117
|
+
'Cookie' => "SESS1=#{granicus.impersonation_token}"},
|
118
|
+
|
119
|
+
:ssl => {:verify => false}
|
120
|
+
}
|
121
|
+
|
122
|
+
connection = Faraday::Connection.new(options) do |builder|
|
123
|
+
builder.use Faraday::Request::Multipart
|
124
|
+
builder.adapter(Faraday.default_adapter)
|
125
|
+
end
|
126
|
+
|
127
|
+
payload = {
|
128
|
+
:form_panel_agendaPublishing => 'uploaded',
|
129
|
+
:form_submit => 'Save Settings',
|
130
|
+
:form_panel_agendaFile => Faraday::UploadIO.new('agenda_temp.html', 'text/html')
|
131
|
+
}
|
132
|
+
response = connection.post "http://#{@host}/panes/EditFileAgenda.php?clip_id=#{clip.ID}", payload
|
133
|
+
|
134
|
+
File.delete('agenda_temp.html')
|
135
|
+
|
136
|
+
# upload all of the metadata
|
137
|
+
puts "Writing #{meta_array.count} items to Granicus Clip ID #{clip.ID}"
|
138
|
+
keymap = granicus.import_clip_meta_data clip.ID, meta_array
|
139
|
+
|
140
|
+
# make the clip public
|
141
|
+
clip.Status = "Public"
|
142
|
+
granicus.update_clip clip
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: granicus_migrate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Javier Muniz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-08 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday_middleware
|
16
|
+
requirement: &2153146660 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.7.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2153146660
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: granicus-platform-api
|
27
|
+
requirement: &2153146140 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.9.1
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2153146140
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: nokogiri
|
38
|
+
requirement: &2153145640 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.5.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2153145640
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: faraday_middleware
|
49
|
+
requirement: &2153145080 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.7.0
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2153145080
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: granicus-platform-api
|
60
|
+
requirement: &2153144540 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 0.9.1
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2153144540
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: nokogiri
|
71
|
+
requirement: &2153144060 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.5.0
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2153144060
|
80
|
+
description: Tool to mass-import files from old Webcasting.com customers to the Granicus
|
81
|
+
Platform
|
82
|
+
email: javier@granicus.com
|
83
|
+
executables:
|
84
|
+
- granicus_migrate
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files: []
|
87
|
+
files:
|
88
|
+
- .gitignore
|
89
|
+
- Gemfile
|
90
|
+
- Gemfile.lock
|
91
|
+
- bin/granicus_migrate
|
92
|
+
- granicus_migrate.gemspec
|
93
|
+
- lib/granicus_migrate_helper.rb
|
94
|
+
homepage: http://github.com/granicus/granicus_migrate
|
95
|
+
licenses: []
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project: granicus_migrate
|
114
|
+
rubygems_version: 1.8.5
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Tool to mass-import files from old Webcasting.com customers to the Granicus
|
118
|
+
Platform
|
119
|
+
test_files: []
|