Created
February 7, 2026 05:28
-
-
Save JJTech0130/83036dd6093ae931357ff6cab6511e9a to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env python3 | |
| import csv | |
| import sys | |
| import requests | |
| from typing import Dict, Any, Optional | |
| # Configuration | |
| BASE_URL = "https://scorify.local" | |
| GRAPHQL_URL = f"{BASE_URL}/api/query" | |
| VERIFY_SSL = False | |
| USERNAME = "admin" | |
| PASSWORD = "admin" | |
| # Global session for storing cookies/auth | |
| session = requests.Session() | |
| session.headers.update({"Content-Type": "application/json"}) | |
| # Suppress InsecureRequestWarning for self-signed certs | |
| if not VERIFY_SSL: | |
| import urllib3 | |
| urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | |
| def query(gql: str, variables: Optional[Dict[str, Any]] = None) -> Dict[str, Any]: | |
| """Execute a GraphQL query/mutation""" | |
| payload = {"query": gql} | |
| if variables: | |
| payload["variables"] = variables | |
| response = session.post(GRAPHQL_URL, json=payload, verify=VERIFY_SSL) | |
| response.raise_for_status() | |
| result = response.json() | |
| if "errors" in result: | |
| raise Exception(f"GraphQL Error: {result['errors']}") | |
| return result.get("data", {}) | |
| def login(username: str, password: str) -> Dict[str, Any]: | |
| gql = """ | |
| mutation Login($username: String!, $password: String!) { | |
| login(username: $username, password: $password) { | |
| name | |
| token | |
| } | |
| } | |
| """ | |
| result = query(gql, {"username": username, "password": password}) | |
| login_info = result["login"] | |
| # Store auth cookie | |
| session.cookies.set(login_info["name"], login_info["token"]) | |
| return login_info | |
| def create_user( | |
| username: str, password: str, role: str = "user", number: Optional[int] = None | |
| ) -> Dict[str, Any]: | |
| gql = """ | |
| mutation CreateUser($username: String!, $password: String!, $role: Role!, $number: Int) { | |
| createUser(username: $username, password: $password, role: $role, number: $number) { | |
| id | |
| username | |
| number | |
| } | |
| } | |
| """ | |
| variables = {"username": username, "password": password, "role": role} | |
| if number is not None: | |
| variables["number"] = number | |
| return query(gql, variables)["createUser"] | |
| def import_teams_from_csv(csv_file: str) -> None: | |
| created = 0 | |
| failed = 0 | |
| with open(csv_file, 'r') as f: | |
| reader = csv.DictReader(f) | |
| for row in reader: | |
| username = row['username'].strip() | |
| password = row['password'].strip() | |
| number = int(row['number']) if row.get('number') else None | |
| try: | |
| user = create_user(username, password, role="user", number=number) | |
| print(f"✓ Created team: {user['username']} (#{user.get('number', 'N/A')})") | |
| created += 1 | |
| except Exception as e: | |
| print(f"✗ Failed to create {username}: {e}") | |
| failed += 1 | |
| print(f"\n{'='*50}") | |
| print(f"Summary: {created} created, {failed} failed") | |
| def main(): | |
| if len(sys.argv) < 2: | |
| print("Usage: ./scorify_batch.py <teams.csv>") | |
| print("\nCSV format:") | |
| print(" username,password,number") | |
| print(" team1,pass123,1") | |
| print(" team2,pass456,2") | |
| sys.exit(1) | |
| csv_file = sys.argv[1] | |
| # Login as admin | |
| login(USERNAME, PASSWORD) | |
| # Import teams | |
| print(f"Importing teams from {csv_file}...") | |
| print(f"{'='*50}") | |
| import_teams_from_csv(csv_file) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment