Created
June 6, 2026 23:27
-
-
Save dcsportsfan23/3c54d920659c2091e7e68cba2d5b39ef to your computer and use it in GitHub Desktop.
bet-bot one-shot cleanup: clear bogus corrected=Y on pending rows
This file contains hidden or 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
| """ | |
| Bet bot one-shot cleanup: clear bogus corrected='Y' on rows still result='pending'. | |
| Background: auto_resolve_pending_bets() skips rows with corrected='Y'. | |
| On 5/11 the recovery scripts set corrected='Y' on rows that were still pending, | |
| which permanently blocks them from auto-resolving. | |
| This script: | |
| 1. Shows the affected rows BEFORE the change | |
| 2. Clears corrected from 'Y' to '' on rows where result='pending' | |
| 3. Shows the affected rows AFTER the change | |
| 4. Reports how many rows were updated | |
| Read-only on everything except the 3 (likely) stuck rows. | |
| """ | |
| import sqlite3, os, sys | |
| DB = '/data/bets.sqlite3' | |
| if not os.path.exists(DB): | |
| print(f"FATAL: {DB} does not exist") | |
| sys.exit(1) | |
| con = sqlite3.connect(DB) | |
| con.row_factory = sqlite3.Row | |
| c = con.cursor() | |
| print("=" * 60) | |
| print("STEP 1: Rows to be fixed (corrected='Y' AND result='pending')") | |
| print("=" * 60) | |
| before = list(c.execute(""" | |
| SELECT id, bet_date, author_name, channel_name, sport, | |
| substr(selection,1,60) sel, result, corrected, result_source | |
| FROM bets | |
| WHERE corrected='Y' AND (result='pending' OR result IS NULL OR result='') | |
| ORDER BY bet_date | |
| """)) | |
| if not before: | |
| print(" (no rows match — nothing to fix)") | |
| sys.exit(0) | |
| for r in before: | |
| print(f" id={r['id']:<5} {r['bet_date']} {r['author_name']:<15} {r['channel_name']:<12} {r['sport']:<15} {r['sel'][:50]:<50} result={r['result']!r} corrected={r['corrected']!r}") | |
| print(f"\nRows to update: {len(before)}") | |
| print("\n" + "=" * 60) | |
| print("STEP 2: Applying UPDATE (clearing corrected → '')") | |
| print("=" * 60) | |
| cur = c.execute(""" | |
| UPDATE bets | |
| SET corrected = '' | |
| WHERE corrected='Y' AND (result='pending' OR result IS NULL OR result='') | |
| """) | |
| con.commit() | |
| print(f"Updated {cur.rowcount} rows") | |
| print("\n" + "=" * 60) | |
| print("STEP 3: Verify (same query, should show corrected='')") | |
| print("=" * 60) | |
| ids = [str(r['id']) for r in before] | |
| placeholders = ','.join(['?'] * len(ids)) | |
| after = list(c.execute(f""" | |
| SELECT id, bet_date, author_name, sport, substr(selection,1,60) sel, | |
| result, corrected | |
| FROM bets WHERE id IN ({placeholders}) | |
| ORDER BY bet_date | |
| """, ids)) | |
| for r in after: | |
| print(f" id={r['id']:<5} {r['bet_date']} {r['author_name']:<15} {r['sport']:<15} {r['sel'][:50]:<50} result={r['result']!r} corrected={r['corrected']!r}") | |
| print("\n" + "=" * 60) | |
| print("CLEANUP COMPLETE") | |
| print("=" * 60) | |
| print("Next nightly auto-resolve job (runs after midnight UTC) will flip these to 'loss'.") | |
| print("Or run `python bot.py --resettle` to apply immediately.") | |
| con.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment