Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Alexandro1112/a6c7fa4fde950f51f356db6a3780937c to your computer and use it in GitHub Desktop.
Save Alexandro1112/a6c7fa4fde950f51f356db6a3780937c to your computer and use it in GitHub Desktop.
import os
import sqlite3
from Foundation import NSDate
def get_safari_history():
history_db_path = os.path.expanduser('~/Library/Safari/History.db')
conn = sqlite3.connect(history_db_path)
cursor = conn.cursor()
query = '''
SELECT
url,
visit_time,
title
FROM
history_visits
JOIN
history_items ON history_visits.history_item = history_items.id
'''
cursor.execute(query)
for row in cursor.fetchall():
url, date, title = (_rows for _rows in row)
yield {
'url': url,
'date': NSDate.dateWithTimeIntervalSinceReferenceDate_(date),
'title': title
}
cursor.close()
conn.close()
if __name__ == '__main__':
for i in get_safari_history():
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment