Skip to content

Instantly share code, notes, and snippets.

@nikokultalahti
Created August 28, 2025 16:23
Show Gist options
  • Select an option

  • Save nikokultalahti/29ac6869176491bd9b761a8a0503b9a9 to your computer and use it in GitHub Desktop.

Select an option

Save nikokultalahti/29ac6869176491bd9b761a8a0503b9a9 to your computer and use it in GitHub Desktop.
This ruby script convers a link list exported from Wallabag as json to html that can be imported into Karakeep
#!/usr/bin/env ruby
require 'json'
require 'time'
abort "Usage: ./script import-file [export-file]" if ARGV.empty?
input_file = ARGV.shift
export_filename = ARGV.shift
export_filename = 'exported_bookmarks.html' if export_filename.empty? || export_filename.nil?
loaded_file = JSON.load(File.open(input_file))
output_begin = '''<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
'''
output_end = '</DL><p>'
output = output_begin
for item in loaded_file do
article = "<DT><A HREF=\"#{item['url']}\" ADD_DATE=\"#{Time.parse(item['created_at']).to_i}\" LAST_MODIFIED=\"#{Time.parse(item['updated_at']).to_i}\" TAGS=\"#{item['tags'].join(',')}\">#{item['title']}</A>\n"
output << article
end
output << output_end
output_file = File.open(export_filename, 'w')
output_file.write(output)
output_file.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment