Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 82 lines (76 sloc) 1.735 kb
#!/usr/bin/env ruby
require "rubygems"
require "pathname"
require "hpricot"
class GooglePlusDocument
def initialize(path)
@path = path
end
def doc
@doc ||= Hpricot(File.open(@path, 'rb', &:read))
end
def published
@published ||= doc.at(".published")["title"]
end
def published_pretty
@published_pretty ||= doc.at(".published").inner_text
end
def content
@original_content ||= doc.at(".entry-content").to_s
end
def permalink
@permalink ||= doc.at(".permalink a")["href"]
end
def style
doc.at("style").to_s
end
def remove_doc!
# Free memory
@doc = nil
end
def attachments
@attachments ||= (doc/".attachment").to_a.map(&:to_s)
end
def parse!
permalink
content
attachments
published
published_pretty
end
end
def process_gplus_takeout!(stream_dir, output_html)
docs = []
style = nil
Pathname(stream_dir).children.each do |file|
puts file
doc = GooglePlusDocument.new(file)
doc.parse!
style ||= doc.style
doc.remove_doc!
docs << doc
end
File.open(output_html, 'wb') do |fh|
fh.puts "<html>"
fh.puts "<head>"
fh.puts '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'
fh.puts style
fh.puts "</head>"
fh.puts "<body>"
docs.sort_by(&:published).reverse.each do |doc|
fh.puts "<h3><a href='#{doc.permalink}'>#{doc.published_pretty}</a></h3>"
fh.puts doc.content
doc.attachments.each{|at|
fh.puts at
end
end
fh.puts "</body>"
fh.puts "</html>"
}
end
unless ARGV.size == 2
STDERR.puts "Usage: #{$0} Stream/ output.html"
exit
end
stream_dir, output_html = *ARGV
process_gplus_takeout!(stream_dir, output_html)
Jump to Line
Something went wrong with that request. Please try again.