Skip to content

Instantly share code, notes, and snippets.

@cekage
Created March 2, 2019 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cekage/89452fad325df7a9967188ec4dd969e3 to your computer and use it in GitHub Desktop.
Save cekage/89452fad325df7a9967188ec4dd969e3 to your computer and use it in GitHub Desktop.
Remove empty lines in Content field of document.
#!/usr/bin/env python3
import sqlite3
import re
conn = sqlite3.connect('/opt/paperless/data/db.sqlite3')
c = conn.cursor()
d = conn.cursor()
for row in c.execute('''Select id,content from documents_document order by id asc'''):
purgedContent = re.sub('(\r|\n)+','\n', row[1])
if (purgedContent != row[1]):
d.execute("update documents_document set content=:content where id=:id",
{'content':purgedContent, 'id': row[0]}
)
conn.commit()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment