Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple script to clean (remove) all thumbnails for sites placed at "Most visited" section of Google Chrome or Chromium new page.
#!/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('~/.config/google-chrome/Default/Top Sites')
CHROMIUM_FILE = CHROME_FILE.replace('google-chrome', 'chromium')
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) and not os.path.isfile(CHROMIUM_FILE):
print('Looks like you have not Google Chrome or Chromium installed ' \
'on your machine.')
sys.exit(1)
clean_thumbnails(CHROME_FILE)
clean_thumbnails(CHROMIUM_FILE)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment