import requests import re import json def create_gitea_repository(): session = requests.Session() # Login first login_url = "https://git.mtrcompute.com/user/login" response = session.get(login_url) # Extract CSRF token csrf_token = None match = re.search(r'csrfToken:\s*\'([^\']+)\'', response.text) if match: csrf_token = match.group(1) if not csrf_token: print("Could not find CSRF token") return False # Login data = { 'user_name': 'jleu3482', 'password': 'jleu1212', 'csrf_token': csrf_token } headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Referer': login_url } response = session.post(login_url, data=data, headers=headers, allow_redirects=False) if response.status_code not in [302, 303]: print(f"Login failed. Status: {response.status_code}") return False print("Login successful!") # Now create repository via API api_url = "https://git.mtrcompute.com/api/v1/user/repos" repo_data = { 'name': 'railseek6', 'description': 'LightRAG project with document download and auto-commit functionality', 'private': False, 'auto_init': False, 'gitignores': '', 'license': '', 'readme': '', 'default_branch': 'master' } # Get CSRF token for API (might need to be in headers) response = session.get("https://git.mtrcompute.com/api/v1/user") print(f"User API status: {response.status_code}") # Try to create repo headers = { 'Content-Type': 'application/json', 'X-Csrf-Token': csrf_token } response = session.post(api_url, json=repo_data, headers=headers) print(f"Create repo status: {response.status_code}") print(f"Create repo response: {response.text}") if response.status_code == 201: print("Repository created successfully!") return True elif response.status_code == 409: print("Repository already exists") return True else: print("Failed to create repository") return False if __name__ == "__main__": create_gitea_repository()