Created
March 30, 2025 20:03
-
-
Save Alexandro1112/a6c7fa4fde950f51f356db6a3780937c to your computer and use it in GitHub Desktop.
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
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