Skip to content

Instantly share code, notes, and snippets.

@slackorama
Created November 26, 2014 22:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save slackorama/5f906ec18b2d37ebb682 to your computer and use it in GitHub Desktop.
Export Chrome search engines to use in firefox.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Grab the search engines from Chrome and try to put them into a format that
Firefox can import so you have the same keywords to use there.
Only works on Linux right now. And with the Default profile. So yeah...
"""
import sqlite3
import os
# change this for your OS
DB_PATH = os.path.expanduser("~/.config/google-chrome/Default/Web Data")
def main():
s = sqlite3.connect(database=DB_PATH)
keywords = s.execute('select keyword, short_name, url, date_created from \
keywords where url not like "%gooogle:baseURL%"')
output = open('search_engines.html', 'w')
output.write("""<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<DL><p>
<DT>
<DT><H3>Search engines from Chrome</H3>
<DD>Search engines imported from chrome.
<DL><p>""")
for row in keywords:
url = row[2].replace('{searchTerms}', '%s')
TMPL = """<DT><A HREF="{url}" ADD_DATE="{created}"
LAST_MODIFIED="{created}" \
SHORTCUTURL="{keyword}">{short_name}</A>\n"""
output.write(TMPL.format(url=url, created=row[3],
keyword=row[0], short_name=row[1]))
output.write("</DL>")
output.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment