Skip to content

Instantly share code, notes, and snippets.

@gjedeer
Created June 8, 2015 21:14
Show Gist options
  • Select an option

  • Save gjedeer/e35dcf7f9bcca32e0d38 to your computer and use it in GitHub Desktop.

Select an option

Save gjedeer/e35dcf7f9bcca32e0d38 to your computer and use it in GitHub Desktop.
Opera's speeddial.ini to bookmark.html converter. Bookmark.html can be imported to Chromium, Firefox and other browsers.
#!/usr/bin/python
"""
Opera's speeddial.ini to bookmark.html converter
Bookmark.html can be imported to Chromium, Firefox and other browsers
"""
import cgi
import codecs
import re
import sys
title_re = re.compile(r'Title=?(.*)$')
url_re = re.compile('Url=(.*)$')
file_name = sys.argv[1]
f = codecs.open(file_name, "r", "utf8")
M_TITLE = 1
M_URL = 2
mode = M_TITLE
urls = []
for line in f:
if mode == M_TITLE:
m = title_re.match(line)
if m:
mode = M_URL
title = m.group(1).strip()
elif mode == M_URL:
m = url_re.match(line)
if m:
mode = M_TITLE
url = m.group(1).strip()
urls.append((title, url))
f.close()
fout = codecs.open("bookmarks.html", "w", "utf8")
fout.write("""<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!--This is an automatically generated file.
It will be read and overwritten.
Do Not Edit! -->
<Title>Bookmarks</Title>
<H1>Bookmarks</H1>
<DL>
""")
for title,url in urls:
fout.write('<DT><A HREF="%s" ADD_DATE="2015-01-01">%s</A></DT>\n' % (
cgi.escape(title, quote=True),
cgi.escape(url)))
fout.write("</DL>")
fout.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment