Add lab3 network examples
This commit is contained in:
commit
e66d4fa927
10 files changed
+333
No files matched your search
@@ -0,0 +1,42 @@
|
||||
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)
|
||||
|
||||
Reference in new issue
Block a user