Skip to content

Instantly share code, notes, and snippets.

@trekdemo
Created November 4, 2012 19:00
Show Gist options
  • Select an option

  • Save trekdemo/4013085 to your computer and use it in GitHub Desktop.

Select an option

Save trekdemo/4013085 to your computer and use it in GitHub Desktop.
Migrate readability json format to instapaper html format for pocket app import
require 'json'
TEMPLATE = <<-HTML
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Instapaper: Export</title>
</head>
<body>
%s
</body>
</html>
HTML
json_path = ARGV[0]
if json_path == "" || json_path.nil?
puts "You must provide the path to json"
exit 1
end
json_file = File.read json_path
json = JSON.parse json_file
tags = { :unread => [], :archived => [] }
json.each do |link|
entry = { :title => link['article__title'], :url => link['article__url'] }
if link['archive']
tags[:archived] << entry
else
tags[:unread] << entry
end
end
content = ""
tags.each_pair do |tag, entries|
content << "<h1>#{tag.to_s.capitalize}</h1>\n"
content << "<ol>\n"
entries.each do |entry|
content << "<li><a href=\"#{entry[:url]}\">#{entry[:title]}</a></li>\n"
end
content << "</ol>\n"
end
html = TEMPLATE % content
puts html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment