Python 3 script to manually remove some Firefox history items.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# 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.com/search?%", # Google Search | |
] | |
# Set to True if you want to preview what would be deleted | |
TEST_MODE = False | |
if TEST_MODE: | |
statement = select_statement | |
else: | |
statement = delete_statement | |
for query in queries: | |
variable_bindings = {"query": query, "ten_days_ago": ten_days_ago} | |
cursor.execute(statement, variable_bindings) | |
if TEST_MODE: | |
for row in cursor: | |
print(row['url']) | |
if not TEST_MODE: | |
print("Deleted {} rows.".format(conn.total_changes)) | |
conn.commit() | |
cursor.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment