Skip to content

Instantly share code, notes, and snippets.

Created February 16, 2013 22:02
  • Star 2 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
What would you like to do?
Python 3 script to manually remove some Firefox history items.
# The queries operate only if either:
# * There are more than 10 visits (for things like my mail, which only bug me
# once they are trying to clog up my new tab page)
# * They are > 10 days old (for things like searches; recent searches aren't
# a big problem; old searches are).
# This should be run only if Firefox is shut down (and I mean really; you
# don't want to corrupt your DB because it was hung!)
# Also, take care about your queries!
import datetime
import sqlite3
import time
PLACES_DB = "/EDITME/path/to/places.sqlite"
conn = sqlite3.connect(PLACES_DB)
cursor = conn.cursor()
select_statement = """select url from moz_places
where url like :query and
(last_visit_date < :ten_days_ago or
visit_count > 10)"""
delete_statement = """delete from moz_places
where url like :query and
(last_visit_date < :ten_days_ago or
visit_count > 10)"""
# The time stored in the DB is in UTC, so we need to be consistent.
old_time_dt = datetime.datetime.utcnow() - datetime.timedelta(days=10)
raw_time = time.mktime(old_time_dt.timetuple())
ten_days_ago = int(raw_time * 1000000)
queries = ["%localhost/roundcube/?%", # Round Cube
"", # Google Search
# Set to True if you want to preview what would be deleted
statement = select_statement
statement = delete_statement
for query in queries:
variable_bindings = {"query": query, "ten_days_ago": ten_days_ago}
cursor.execute(statement, variable_bindings)
for row in cursor:
if not TEST_MODE:
print("Deleted {} rows.".format(conn.total_changes))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment