| import os |
| import sqlite3 |
|
|
| ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) |
| DB_PATH = os.path.join(ROOT_DIR, "db.sqlite") |
|
|
|
|
| def main() -> int: |
| response = input("Are you sure? [y/N]: ").strip().lower() |
| if response not in {"y", "yes"}: |
| return 0 |
| if not os.path.exists(DB_PATH): |
| print("db.sqlite not found.") |
| return 1 |
|
|
| conn = sqlite3.connect(DB_PATH) |
| try: |
| cur = conn.cursor() |
| cur.execute( |
| "SELECT name FROM sqlite_master WHERE type='table' AND name='pixif_cache'" |
| ) |
| if cur.fetchone() is None: |
| print("pixif_cache table not found.") |
| return 1 |
|
|
| cur.execute("SELECT COUNT(*) FROM pixif_cache WHERE url IS ''") |
| to_delete = cur.fetchone()[0] |
| if to_delete: |
| cur.execute("DELETE FROM pixif_cache WHERE url IS ''") |
| conn.commit() |
| cur.execute("SELECT COUNT(*) FROM pixif_cache") |
| remaining = cur.fetchone()[0] |
| finally: |
| conn.close() |
|
|
| print(f"Removed {to_delete} rows with NULL url.") |
| print(f"Remaining rows: {remaining}") |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| raise SystemExit(main()) |
|
|