Repo_lab3_make_with_api/token_write.py

42 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import requests
import os
import sys
sys.path.append(r"C:\Users\Максим\Desktop\доки по вузу\2_курс\практика_2\2 задание\venv\Lib\site-packages")
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('writetok')
if not TOKEN:
print("Токен не найден!")
exit(1)
headers = {
"Authorization": f"token {TOKEN}",
"Content-Type": "application/json"
}
repo_data = {
"name": "Repo_lab3_make_with_api",
"description": "Репозиторий создан через API Gitea",
"private": False,
"auto_init": True
}
print("Создание репозитория...")
response = requests.post(
"https://git.vyatsu.ru/api/v1/user/repos",
headers=headers,
json=repo_data
)
if response.status_code == 201:
repo = response.json()
print(f"Репозиторий создан!")
print(f"Название: {repo['full_name']}")
print(f"URL: {repo['html_url']}")
else:
print(f"Ошибка: {response.status_code}")
print(response.text)