Skip to content

Instantly share code, notes, and snippets.

@falconser
Forked from playpauseandstop/clean-chrome-thumbnails.py
Last active December 14, 2015 04:39
Show Gist options
  • Save falconser/5029562 to your computer and use it in GitHub Desktop.
Save falconser/5029562 to your computer and use it in GitHub Desktop.
Chrome's top site thumbnails cleaner for Mac OS.
#!/usr/bin/env python
#
# Simple script to clean (remove) all thumbnails for sites placed at "Most
# visited" section of Google Chrome or Chromium new page.
#
# Installation
# ============
#
# Store this script somewhere in your ``$PATH`` (like ``~/bin/`` or
# ``/usr/local``).
#
# Requirements
# ============
#
# * Python 2.5 or higher
#
# Usage
# =====
#
# $ clean-chrome-thumbnails.py
#
import os
import sqlite3
import sys
CHROME_FILE = os.path.expanduser('~/Library/Application Support/Google/Chrome/Default/Top Sites')
def clean_thumbnails(filename):
"""
Connect to sqlite3 database where Google Chrome or Chromium store
information about most visited sites and blanks all ``thumbnail`` fields
in ``thumbnails`` table.
"""
if not os.path.isfile(filename):
return
name = filename.split(os.path.sep)[-3].replace('-', ' ').title()
print('Clean thumbnails of Most Visited Sites for %s.') % name
conn = sqlite3.connect(filename)
sql = 'UPDATE thumbnails SET thumbnail = null;'
cursor = conn.cursor()
cursor.execute(sql)
conn.commit()
cursor.close()
print('All OK!')
def main():
"""
Run clean thumbnails function only if Google Chrome or Chromium top
sites database found at disk.
"""
if not os.path.isfile(CHROME_FILE):
print('Looks like you have not Google Chrome or Chromium installed ' \
'on your machine.')
sys.exit(1)
clean_thumbnails(CHROME_FILE)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment