Compare commits
2 Commits
4bc4739f9f
...
809d73e715
| Author | SHA1 | Date | |
|---|---|---|---|
| 809d73e715 | |||
| 6cfa9d3520 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -158,5 +158,6 @@ cython_debug/
|
|||||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
.idea
|
||||||
|
.venv
|
||||||
|
.env
|
||||||
55
3lb/gitea_api.py
Normal file
55
3lb/gitea_api.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import os
|
||||||
|
import requests
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
# 1. Загружаем токен из файла .env
|
||||||
|
load_dotenv()
|
||||||
|
TOKEN = os.getenv("GITEA_TOKEN")
|
||||||
|
|
||||||
|
if not TOKEN:
|
||||||
|
print(" Ошибка: Токен не найден! Проверь файл .env")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
# Заголовки для авторизации (стандарт Gitea)
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"token {TOKEN}",
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def check_user():
|
||||||
|
print("--- Шаг 1: Проверка профиля ---")
|
||||||
|
url = "https://git.vyatsu.ru/api/v1/user"
|
||||||
|
response = requests.get(url, headers=headers)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
data = response.json()
|
||||||
|
print(f" Успешный вход! Логин: {data.get('login')}")
|
||||||
|
else:
|
||||||
|
print(f" Ошибка авторизации: {response.status_code}")
|
||||||
|
|
||||||
|
|
||||||
|
def create_repo(repo_name):
|
||||||
|
print(f"\n--- Шаг 2: Создание репозитория '{repo_name}' ---")
|
||||||
|
url = "https://git.vyatsu.ru/api/v1/user/repos"
|
||||||
|
payload = {
|
||||||
|
"name": repo_name,
|
||||||
|
"description": "Лабораторная работа по сетям",
|
||||||
|
"private": False,
|
||||||
|
"auto_init": True # Создаст сразу README.md
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post(url, headers=headers, json=payload)
|
||||||
|
|
||||||
|
if response.status_code == 201:
|
||||||
|
print(f" Репозиторий создан: {response.json().get('html_url')}")
|
||||||
|
elif response.status_code == 422:
|
||||||
|
print(" Репозиторий с таким именем уже существует.")
|
||||||
|
else:
|
||||||
|
print(f" Что-то пошло не так: {response.text}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
check_user()
|
||||||
|
# В названии репозитория укажи что-то уникальное, чтобы не пересекаться с другими
|
||||||
|
create_repo("zadanie3")
|
||||||
5
3lb/http_requests.py
Normal file
5
3lb/http_requests.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
response = requests.get("http://vyatsu.ru")
|
||||||
|
print(response.status_code)
|
||||||
|
print(response.text[:500])
|
||||||
9
3lb/http_socket.py
Normal file
9
3lb/http_socket.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
client.connect(('vyatsu.ru', 80))
|
||||||
|
request = "GET / HTTP/1.1\r\nHost: vyatsu.ru\r\n\r\n"
|
||||||
|
client.sendall(request.encode())
|
||||||
|
response = client.recv(4096)
|
||||||
|
print(response.decode())
|
||||||
|
client.close()
|
||||||
8
3lb/tcp_client.py
Normal file
8
3lb/tcp_client.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
client.connect(('127.0.0.1', 10000))
|
||||||
|
client.sendall(b'hello server')
|
||||||
|
data = client.recv(1024)
|
||||||
|
print(f"Ответ от сервера: {data.decode()}")
|
||||||
|
client.close()
|
||||||
21
3lb/tcp_server.py
Normal file
21
3lb/tcp_server.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
server.bind(("0.0.0.0", 10000))
|
||||||
|
server.listen(1)
|
||||||
|
print("TCP сервер запущен")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
conn, addr = server.accept()
|
||||||
|
print(f"Подключение от {addr}")
|
||||||
|
|
||||||
|
data = conn.recv(1024)
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
conn.sendall(data.upper())
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
if data.upper() == b'EXIT':
|
||||||
|
break
|
||||||
7
3lb/udp_client.py
Normal file
7
3lb/udp_client.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
client.sendto(b'hello server12', ('127.0.0.1', 10001))
|
||||||
|
data, _ = client.recvfrom(1024)
|
||||||
|
print(f"Ответ от сервера: {data.decode()}")
|
||||||
|
client.close()
|
||||||
10
3lb/udp_server.py
Normal file
10
3lb/udp_server.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
server.bind(('0.0.0.0', 10000))
|
||||||
|
print("UDP сервер запущен")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
data, addr = server.recvfrom(1024)
|
||||||
|
print(f"Сообщение от {addr}: {data.decode()}")
|
||||||
|
server.sendto(data.upper(), addr)
|
||||||
Loading…
Reference in New Issue
Block a user