Created
April 21, 2013 18:19
-
-
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.
This file contains 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 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