Skip to content

Instantly share code, notes, and snippets.

@jayvdb
Forked from edsu/wikihist.py
Created August 7, 2014 10:17
Show Gist options
  • Save jayvdb/a4b678767633f3df85a3 to your computer and use it in GitHub Desktop.
Save jayvdb/a4b678767633f3df85a3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
Print out a report of Wikipedia articles you've visited using your Google Chrome history database.
The output is in Markdown, and you'll need to shutdown Chrome before you run this or else the
database will be locked.
"""
import os
import re
import sqlite3
home = os.path.expanduser("~")
dbfile = home + "/Library/Application Support/Google/Chrome/Default/History"
db = sqlite3.connect(dbfile)
q = """
SELECT url, title, visit_count, datetime(last_visit_time/1000000-11644473600,'unixepoch','localtime')
FROM urls
ORDER BY visit_count DESC
"""
for url, title, visit_count, last_visit in db.execute(q):
if re.match('http://(.+)\.wikipedia\.org/wiki', url):
print ("* [%s](%s) - %s - %s" % (title, url, last_visit, visit_count)).encode('utf-8')
db.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment