43 lines
995 B
Python
43 lines
995 B
Python
import os
|
|
|
|
import requests
|
|
|
|
|
|
API_URL = "https://git.vyatsu.ru/api/v1"
|
|
|
|
|
|
def load_token() -> str:
|
|
token = os.getenv("GITEA_TOKEN")
|
|
if token:
|
|
return token
|
|
|
|
if os.path.exists(".env"):
|
|
with open(".env", "r", encoding="utf-8") as file:
|
|
for line in file:
|
|
line = line.strip()
|
|
if line.startswith("GITEA_TOKEN="):
|
|
return line.split("=", 1)[1].strip()
|
|
|
|
return ""
|
|
|
|
|
|
token = load_token()
|
|
if not token:
|
|
print("Token not found. Create .env file with GITEA_TOKEN=your_token")
|
|
raise SystemExit(1)
|
|
|
|
headers = {"Authorization": f"token {token}"}
|
|
|
|
response = requests.get(f"{API_URL}/user", headers=headers, timeout=10)
|
|
print(f"Status code: {response.status_code}")
|
|
|
|
if response.ok:
|
|
user = response.json()
|
|
print("Gitea user information:")
|
|
print(f"Login: {user.get('login')}")
|
|
print(f"Full name: {user.get('full_name')}")
|
|
print(f"Email: {user.get('email')}")
|
|
else:
|
|
print(response.text)
|
|
|