Created
January 6, 2015 14:28
-
-
Save boris-chervenkov/84b7c3f06bb94c106ba8 to your computer and use it in GitHub Desktop.
Export Chrome/Chromium history directly from the browser's database. Based on http://stackoverflow.com/questions/2141537/convert-datetime-fields-in-chrome-history-file-sqlite-to-readable-format/3174614#3174614 , but works with more recent versions of the browser.
This file contains hidden or 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/env python | |
import os | |
import sys | |
import datetime | |
import sqlite3 | |
SQL_VISITS = 'select v.visit_time, u.url from visits v inner join urls u on (v.url = u.id) order by v.visit_time' | |
def date_from_webkit(webkit_timestamp): | |
epoch_start = datetime.datetime(1601, 1, 1) | |
delta = datetime.timedelta(microseconds=int(webkit_timestamp)) | |
return epoch_start + delta | |
def main(db_filename): | |
assert os.path.exists(db_filename) | |
c = sqlite3.connect(db_filename) | |
visits = list((date_from_webkit(row[0]), row[1]) for row in c.execute(SQL_VISITS)) | |
for v in visits: | |
print('"{}", "{}"'.format(*v)) | |
c.close() | |
return 0 | |
if __name__ == '__main__': | |
if len(sys.argv) < 2: | |
print("Usage: {} <path-to-chrome-history-file>".format(sys.argv[0])) | |
print(" for Chromium 38 on MacOS: ~/Library/Application\ Support/Chromium/Default/History ") | |
sys.exit(1) | |
else: | |
sys.exit(main(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment