Skip to content

Instantly share code, notes, and snippets.

@admariner
Forked from n8henrie/chrome_se_export.py
Created September 8, 2023 00:11
Show Gist options
  • Save admariner/d86c189aa70dcbe2f14039bfa7f6d824 to your computer and use it in GitHub Desktop.
Save admariner/d86c189aa70dcbe2f14039bfa7f6d824 to your computer and use it in GitHub Desktop.
Export your Chrome search engines to JSON.
"""chrome_se_export.py
Export your Chrome search engines to JSON.
"""
import os.path
import sqlite3
import re
import json
import click
@click.command()
@click.option(
'--path',
default='~/Library/Application Support/Google/Chrome/Default/Web Data',
help="Path to Chrome's 'Web Data' Folder")
@click.option(
'--outfile',
default='se_from_chrome.json',
help="Output file")
def export(path, outfile):
path = os.path.expanduser(path)
conn = sqlite3.connect(path)
with conn:
try:
keywords = conn.execute('''select * from keywords''')
except sqlite3.OperationalError:
print("Is Chrome running? Must be closed to work.\n")
raise
search_engines = [{'name': kw[1], 'keyword': kw[2], 'url': kw[4]}
for kw in keywords if re.search(r'{searchTerms}', kw[4])]
output = json.dumps(search_engines, sort_keys=True, indent=4,
separators=(',', ': '))
with open(outfile, 'w') as w:
w.write(output)
if __name__ == "__main__":
export()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment