Add hashbang, script description, and useful error message to convert_db script

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2023-07-25 16:10:09 -07:00
parent 532393c2c7
commit e51dd85d54

8
convert_db.py Normal file → Executable file
View File

@@ -1,3 +1,7 @@
#!/usr/bin/env python3
# Convert between the old database format and the new one.
# You probably won't need to run this script.
import json import json
import sqlite3 import sqlite3
@@ -52,6 +56,10 @@ bans = old_db.execute("SELECT * FROM BANS").fetchall()
print("Converting", len(bans), "rows") print("Converting", len(bans), "rows")
for ban in bans: for ban in bans:
if 'post' not in ban:
print("ERROR: The database either does not exist, or already exists in the new format. Exiting")
raise SystemExit(1)
post = json.loads(ban["post"]) post = json.loads(ban["post"])
post["action"] = ban["action"] post["action"] = ban["action"]
# post['board'] = ban['board'] # post['board'] = ban['board']