Skip to content

Instantly share code, notes, and snippets.

@amontalenti
Created April 21, 2013 18:19
Show Gist options
  • Save amontalenti/5430505 to your computer and use it in GitHub Desktop.
Save amontalenti/5430505 to your computer and use it in GitHub Desktop.
Synchronize my PDF store of ebooks with my Papers2 SQLite3 database on my Mac. Replaces the title of each book with the filename on-disk, since I have my own naming convention that works much more nicely.
import sqlite3
import sys
conn = sqlite3.Connection("Database.papersdb")
query = "SELECT pub.ROWID, pdf.path, pub.title FROM Publication pub, PDF pdf WHERE pdf.object_id=pub.ROWID"
for row in conn.execute(query):
rowid, path, title = row
newtitle = path.replace("Files/", "").replace(".pdf", "")
sql = ('UPDATE Publication SET title=? WHERE ROWID=?', (newtitle, rowid))
print sql
conn.execute(*sql)
conn.commit()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment