все сделал
This commit is contained in:
parent
f92d2cd4ef
commit
2d382052fd
4
.gitignore
vendored
4
.gitignore
vendored
@ -1 +1,3 @@
|
||||
.venv/
|
||||
.venv/
|
||||
.env
|
||||
__pycache__/
|
||||
|
||||
33
create_issue.py
Normal file
33
create_issue.py
Normal file
@ -0,0 +1,33 @@
|
||||
import os
|
||||
import requests
|
||||
|
||||
|
||||
TOKEN = os.getenv("GITEA_WRITE_TOKEN")
|
||||
if not TOKEN:
|
||||
raise Exception("Переменная окружения GITEA_WRITE_TOKEN не задана")
|
||||
|
||||
headers = {
|
||||
"Authorization": f"token {TOKEN}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
|
||||
owner = "stud203834"
|
||||
repo = "2zadanie"
|
||||
|
||||
url = f"https://git.vyatsu.ru/api/v1/repos/{owner}/{repo}/issues"
|
||||
|
||||
data = {
|
||||
"title": "Тестовый issue от студента",
|
||||
"body": "Создано через API Gitea с токеном на запись.",
|
||||
"labels": []
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=data)
|
||||
|
||||
if response.status_code == 201:
|
||||
print("✅ Issue создан:")
|
||||
print(response.json()["html_url"])
|
||||
else:
|
||||
print("❌ Ошибка:", response.status_code)
|
||||
print(response.text)
|
||||
9
http_requests.py
Normal file
9
http_requests.py
Normal file
@ -0,0 +1,9 @@
|
||||
import requests
|
||||
|
||||
|
||||
response = requests.get("http://vyatsu.ru")
|
||||
|
||||
print("--- Ответ через библиотеку requests ---")
|
||||
|
||||
print(f"Статус-код: {response.status_code}")
|
||||
print(response.text[:500])
|
||||
19
http_socket.py
Normal file
19
http_socket.py
Normal file
@ -0,0 +1,19 @@
|
||||
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\nConnection: close\r\n\r\n"
|
||||
|
||||
client.sendall(request.encode())
|
||||
|
||||
|
||||
response = client.recv(4096)
|
||||
print("--- Ответ через сокет ---")
|
||||
print(response.decode())
|
||||
|
||||
client.close()
|
||||
20
tcp_client.py
Normal file
20
tcp_client.py
Normal file
@ -0,0 +1,20 @@
|
||||
import socket
|
||||
|
||||
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
|
||||
client.connect(("127.0.0.1", 10000))
|
||||
|
||||
|
||||
message = b'hello server'
|
||||
client.sendall(message)
|
||||
|
||||
|
||||
data = client.recv(1024)
|
||||
|
||||
|
||||
print(f"Ответ от сервера: {data.decode()}")
|
||||
|
||||
|
||||
client.close()
|
||||
35
tcp_server.py
Normal file
35
tcp_server.py
Normal file
@ -0,0 +1,35 @@
|
||||
import socket
|
||||
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
|
||||
server.bind(("0.0.0.0", 10000))
|
||||
|
||||
|
||||
server.listen(1)
|
||||
print("TCP сервер запущен и ожидает подключения на порту 10000...")
|
||||
|
||||
while True:
|
||||
|
||||
conn, addr = server.accept()
|
||||
print(f"Подключение от клиента: {addr}")
|
||||
|
||||
|
||||
data = conn.recv(1024)
|
||||
if not data:
|
||||
break
|
||||
|
||||
|
||||
print(f"Получено сообщение: {data.decode()}")
|
||||
conn.sendall(data.upper())
|
||||
|
||||
|
||||
conn.close()
|
||||
|
||||
|
||||
if data.upper() == b'EXIT':
|
||||
print("Сервер завершает работу...")
|
||||
break
|
||||
|
||||
server.close()
|
||||
24
token_read.py
Normal file
24
token_read.py
Normal file
@ -0,0 +1,24 @@
|
||||
import os
|
||||
import requests
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Загружаем переменные из .env файла
|
||||
load_dotenv()
|
||||
|
||||
# Берем токен из переменной окружения
|
||||
TOKEN = os.getenv("GITEA_TOKEN")
|
||||
|
||||
# Проверка: если токен не найден, выведем предупреждение
|
||||
if not TOKEN:
|
||||
print("Ошибка: Токен не найден в файле .env!")
|
||||
else:
|
||||
headers = {"Authorization": f"token {TOKEN}"}
|
||||
|
||||
# Отправляем запрос на ПРАВИЛЬНУЮ ссылку (из твоего задания)
|
||||
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("Успешное подключение! Данные профиля:")
|
||||
print(response.json())
|
||||
else:
|
||||
print(f"Сервер вернул ошибку {response.status_code}: {response.text}")
|
||||
14
udp_client.py
Normal file
14
udp_client.py
Normal file
@ -0,0 +1,14 @@
|
||||
import socket
|
||||
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
message = b'hello server'
|
||||
server_address = ('127.0.0.1', 10001)
|
||||
|
||||
|
||||
client.sendto(message, server_address)
|
||||
|
||||
|
||||
data, _ = client.recvfrom(1024)
|
||||
print(f"Ответ от сервера: {data.decode()}")
|
||||
|
||||
client.close()
|
||||
18
udp_client_mod.py
Normal file
18
udp_client_mod.py
Normal file
@ -0,0 +1,18 @@
|
||||
import socket
|
||||
|
||||
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
|
||||
server_address = ('127.0.0.1', 12000)
|
||||
|
||||
message = "hello from egora"
|
||||
print(f"Отправка сообщения: {message}")
|
||||
|
||||
|
||||
client.sendto(message.encode(), server_address)
|
||||
|
||||
|
||||
data, _ = client.recvfrom(1024)
|
||||
print(f"Ответ от сервера: {data.decode()}")
|
||||
|
||||
client.close()
|
||||
17
udp_server.py
Normal file
17
udp_server.py
Normal file
@ -0,0 +1,17 @@
|
||||
import socket
|
||||
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
server.bind(('0.0.0.0', 10001))
|
||||
|
||||
print("UDP сервер запущен...")
|
||||
|
||||
while True:
|
||||
|
||||
data, addr = server.recvfrom(1024)
|
||||
print(f"Сообщение от {addr}: {data.decode()}")
|
||||
|
||||
|
||||
modified_data = data.upper() + b" [UDP]"
|
||||
server.sendto(modified_data, addr)
|
||||
23
udp_server_mod.py
Normal file
23
udp_server_mod.py
Normal file
@ -0,0 +1,23 @@
|
||||
import socket
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
|
||||
server.bind(('0.0.0.0', 12000))
|
||||
|
||||
print("Модифицированный UDP сервер запущен на порту 12000...")
|
||||
|
||||
while True:
|
||||
|
||||
data, addr = server.recvfrom(1024)
|
||||
message = data.decode()
|
||||
print(f"Получено от {addr}: {message}")
|
||||
|
||||
|
||||
current_time = datetime.now().strftime("%H:%M:%S")
|
||||
response_text = f"[{current_time}] Server received: {message.upper()}"
|
||||
|
||||
|
||||
server.sendto(response_text.encode(), addr)
|
||||
Loading…
Reference in New Issue
Block a user