-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_999_averagepoints_to_zero.py
More file actions
executable file
·73 lines (57 loc) · 2.34 KB
/
set_999_averagepoints_to_zero.py
File metadata and controls
executable file
·73 lines (57 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python3
# This will Set average points 999 back to zero. Used for team points...
# Must provide database, Which will be combined database
import sqlite3
import os
import argparse
def update_999_to_zero(db_path):
# Check if the database exists
if not os.path.exists(db_path):
print(f"Error: Database '{db_path}' does not exist.")
return
# Connect to the SQLite database
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# List of all round points columns
round_columns = [f"r{round_num}_points" for round_num in range(1, 13)]
try:
# Check and update points for each round column (r1_points to r12_points)
for round_column in round_columns:
# Fetch riders with 999 in the current round
cursor.execute(f"""
SELECT race_number, firstname, surname, {round_column}
FROM riders
WHERE {round_column} = 999
""")
riders = cursor.fetchall()
if riders:
for rider in riders:
race_number, firstname, surname, points = rider
print(f"Found 999 points for {firstname} {surname} (Race number: {race_number}) in {round_column}")
# Update the 999 points to 0
cursor.execute(f"""
UPDATE riders
SET {round_column} = 0
WHERE race_number = ?
""", (race_number,))
# Commit the changes for each column
conn.commit()
print(f"Updated {len(riders)} riders' {round_column} points from 999 to 0.")
else:
print(f"No riders found with 999 points in {round_column}")
except sqlite3.Error as e:
print(f"An error occurred: {e}")
finally:
# Close the connection
conn.close()
# Main function to parse command-line arguments
def main():
# Set up argument parser
parser = argparse.ArgumentParser(description="Update 999 points to 0 in an SQLite database.")
parser.add_argument("db_path", type=str, help="Path to the SQLite database file.")
# Parse the arguments
args = parser.parse_args()
# Call the function to update 999 points to 0
update_999_to_zero(args.db_path)
if __name__ == "__main__":
main()