Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Shareflow Export Script

View gist:434930
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
#!/usr/bin/env ruby
require "rubygems"
require "highline/import"
require "flareshow"
require "erb"
require "time"
require "open-uri"
 
class ShareflowExporter
def initialize(domain, username, password)
@domain = domain
@username = username
@password = password
@flow_template = load_template
end
def export
Flareshow::Service.configure(@domain)
Flareshow::Service.authenticate(@username, @password)
flows = Flow.find(:limit => 300)
cleanup_output_directory
flows.each {|flow| export_flow(flow)}
end
 
def export_flow(flow)
puts "*"*80
puts "exporting flow: #{flow.name}"
puts "*"*80
has_more_posts = true
offset = 0
posts = []
while(has_more_posts)
retrieved_posts = Post.find(:offset => offset, :limit => 30, :flow_id => flow.id)
has_more_posts = false if !retrieved_posts || retrieved_posts.size == 0
if retrieved_posts
posts.concat(retrieved_posts)
offset += retrieved_posts.size
end
end
File.open(output_file_for_flow(flow), "w") { |f|
f << @flow_template.result(binding)
}
end
 
def export_post(post)
puts post.content
end
def cleanup_output_directory
FileUtils.rm_rf("#{@domain}")
end
def localized_original_url_for_file(file,key)
puts "downloading #{file.original_url}?pk=#{key}"
f = open("#{file.original_url}?pk=#{key}")
path = File.join(output_path_for_files, "#{file.id[0..5]}_#{file.file_name}")
File.open(path, "w") do |ff|
ff << f.read
end
path.gsub(/#{@domain}\//,"")
rescue
puts "*"*80
puts "error downloading file #{file.name}"
puts "*"*80
end
 
def localized_thumbnail_url_for_file(file, key)
download_path = "#{file.thumbnail_url}"
if download_path.match(/\?/)
download_path += "&pk=#{key}"
else
download_path += "?pk=#{key}"
end
puts "downloading #{download_path}"
f = open("#{download_path}")
FileUtils.mkdir_p("#{output_path_for_files}/thumbs")
path = File.join(output_path_for_files, "thumbs", "#{file.id}_thumb.jpg")
File.open(path, "w") do |ff|
ff << f.read
end
path.gsub(/#{@domain}\//,"")
rescue
puts "*"*80
puts "error downloading thumbnail for #{file.name}"
puts "*"*80
end
def output_path_for_files
path = "#{@domain}/files"
FileUtils.mkdir_p(path)
path
end
def output_file_for_flow(flow)
FileUtils.mkdir_p("#{@domain}")
File.join(@domain, flow.name.gsub(/["'<>\s]/,"_") + "_#{flow.id[0..5]}.html")
end
def load_template
ERB.new(DATA.read)
end
def pretty_date(date=Time.now)
date = Time.parse(date.to_s)
date.getlocal.strftime("%b %d, %Y ~ %l:%M %p")
end
end
 
if (__FILE__ == $0)
domain = ask("Enter the domain? ")
username = ask("Enter the username? ")
password = ask("Enter the password? ")
exporter = ShareflowExporter.new(domain, username, password)
exporter.export
end
 
###############################
## BEGIN TEMPLATE FOR OUTPUT ##
###############################
__END__
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title><%= flow.name %></title>
<style type="text/css" media="screen">
* {font-family:"helvetica neue", helvetica, arial, sans-serif;}
a, a:hover, a:active, a:visited {text-decoration:none;}
body{
background:#E3F4F4;
}
.wrapper{
width:800px;
margin:auto;
}
h1 {
color:#103d4a;
}
/* ================== */
/* = Shareflow Post = */
/* ================== */
.shareflow_post{
position:relative;
margin-bottom:10px;
background:#fff;
-moz-border-radius:4px;
-webkit-border-radius:4px;
padding:5px;
-moz-box-shadow:2px 2px 6px #B3C0C3;
-webkit-box-shadow:2px 2px 6px #B3C0C3;
}
.shareflow_post .shareflow_post {
-moz-box-shadow:0px 0px 0px #B3C0C3;
-webkit-box-shadow:0px 0px 0px #B3C0C3;
margin-bottom:5px;
}
.shareflow_post *, .shareflow_post {
font-size:12px;
}
.shareflow_post .shareflow_avatar{
position:absolute;
top:5px; left:5px;
-moz-border-radius:4px;
-webkit-border-radius:4px;
height:50px;
width:50px;
}
.shareflow_post .post_body{
min-height:34px;
margin-left:60px;
}
.shareflow_post .post_title{
margin-left:60px;
font-size:12px;
font-family:"Trebuchet MS";
font-style:italic;
}
.shareflow_post .post_title a,
.older_comments_link a{
color:#ab1921; font-size:12px;
}
.older_comments_link {padding-left:5px;}
.comments {
margin-left:54px;
}
.file_thumbnail_link{border:0px solid #fff;}
.file_thumbnail{margin:10px; display:block; float:left;
-moz-box-shadow:2px 2px 6px #B3C0C3;
-webkit-box-shadow:2px 2px 6px #B3C0C3;
border:0px solid #fff;
}
.file_icon{margin:10px; display:block; float:left;
border:0px solid #fff;
}
</style>
</head>
<body>
<h1><%= flow.name %></h1>
<% posts.each do |post| %>
<div class="shareflow_post">
<div class="shareflow_avatar" style="background:url(<%= post.user.avatar_url %>)">
</div>
<div class="post_title">
<%= post.user_full_name %> &mdash; <%= pretty_date(post.created_at) %>
</div>
<div class="post_body">
<%= post.content.to_s %>
<div class="files" style="clear:both">
<% post.files.each do |f| %>
<a href="<%=localized_original_url_for_file(f, post.post_key)%>" class="file_thumbnail_link" target="_blank" title="<%=f.file_name%>">
<% if f.width && f.height %>
<img src="<%=localized_thumbnail_url_for_file(f, post.post_key)%>" class="file_thumbnail" height="80" width="80" />
<% else %>
<img src="<%=localized_thumbnail_url_for_file(f, post.post_key)%>" height="80" width="80" class="file_icon" />
<% end %>
</a>
<% end %>
<div style="clear:both"></div>
</div>
</div>
<div class="comments">
<% post.comments.each do |comment| %>
<div class="shareflow_post">
<div class="shareflow_avatar" style="background:url(<%= comment.user.avatar_url %>)">
</div>
<div class="post_title">
<%= comment.user_full_name %> &mdash; <%= pretty_date(comment.created_at) %>
</div>
<div class="post_body">
<%= comment.content.to_s %>
<div class="files" style="clear:both">
<% comment.files.each do |f| %>
<a href="<%=localized_original_url_for_file(f, post.post_key)%>" class="file_thumbnail_link" target="_blank" title="<%=f.file_name%>">
<% if f.width && f.height %>
<img src="<%=localized_thumbnail_url_for_file(f, post.post_key)%>" class="file_thumbnail" height="80" width="80" />
<% else %>
<img src="<%=localized_thumbnail_url_for_file(f, post.post_key)%>" height="80" width="80" class="file_icon" />
<% end %>
</a>
<% end %>
<div style="clear:both"></div>
</div>
</div>
</div>
<% end %>
</div>
</div>
<% end %>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.