Skip to content

Instantly share code, notes, and snippets.

Last active February 25, 2019 01:53
What would you like to do?
import sqlite3
import contextlib
import os
import sys
def clean_binja_snapshots(conn, limit = 1):
with conn as cur:
for section in [ 'snapshot', 'file_data' ]:
cur.execute(f'DELETE FROM {section} WHERE id NOT IN (SELECT id FROM {section} ORDER BY id DESC LIMIT ?)', (limit,))
with conn as cur:
if __name__ == '__main__':
if len(sys.argv) > 1:
db_file = sys.argv[1]
db_file = input('Enter *.bndn name: ')
if os.path.isfile(db_file):
with contextlib.closing(sqlite3.connect(db_file)) as conn:
clean_binja_snapshots(conn, 1)
print('%s does not exist' % db_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment