Created
November 4, 2012 19:00
-
-
Save trekdemo/4013085 to your computer and use it in GitHub Desktop.
Migrate readability json format to instapaper html format for pocket app import
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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