feat: complete all practice modules (Git basics, Jupyter analysis, Networking, Spectral Clustering)

This commit is contained in:
Artem
2026-05-27 21:43:59 +03:00
parent 08ac5885fa
commit afcdfb38cf
10 changed files with 1106 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
import requests
GITEA_URL = "https://git.vyatsu.ru" # Замените на ваш URL
TOKEN = "8432147d962ba64d7d7fcff7389b1d36a63508d0" # Сгенерировать в Settings -> Applications
HEADERS = {"Authorization": f"token {TOKEN}", "Accept": "application/json"}
# 1. Информация о пользователе
me = requests.get(f"{GITEA_URL}/api/v1/user", headers=HEADERS)
print(f"👤 User: {me.json()['login']}")
# 2. Создание Issue
payload = {
"title": "Тестовый Issue из практики",
"body": "Создано автоматически через API Python."
}
repo = "stud182941/main" # Замените на owner/repo
res = requests.post(f"{GITEA_URL}/api/v1/repos/{repo}/issues", json=payload, headers=HEADERS)
print(f"✅ Issue создан: {res.json().get('html_url', res.text)}")
+21
View File
@@ -0,0 +1,21 @@
import socket
HOST, PORT = "vyatsu.ru", 80
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(10)
s.connect((HOST, PORT))
# Формируем сырой HTTP-запрос
request = "GET / HTTP/1.1\r\nHost: vyatsu.ru\r\nConnection: close\r\n\r\n"
s.sendall(request.encode('utf-8'))
response = b""
while True:
chunk = s.recv(4096)
if not chunk:
break
response += chunk
print("📡 Сырой ответ сервера (первые 800 символов):")
print(response.decode('utf-8', errors='ignore')[:800])
+21
View File
@@ -0,0 +1,21 @@
import socket
HOST, PORT = '192.168.1.12', 65432
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client:
client.connect((HOST, PORT))
print("🔗 Подключено к TCP-серверу.")
messages = ["Привет, TCP!", "Как дела?", "exit"]
for msg in messages:
print(f"📤 Отправляю: {msg}")
client.sendall(msg.encode('utf-8'))
if msg.lower() == 'exit':
print("👋 Отправлена команда выхода.")
break
response = client.recv(1024)
print(f"📥 Ответ сервера: {response.decode('utf-8').strip()}")
print("✅ TCP клиент завершил работу.")
+31
View File
@@ -0,0 +1,31 @@
import socket
HOST, PORT = '0.0.0.0', 65432
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server:
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind((HOST, PORT))
server.listen(1)
print(f"🟢 TCP сервер запущен на {HOST}:{PORT}")
conn, addr = server.accept()
with conn:
print(f"🔗 Подключён клиент: {addr}")
while True:
data = conn.recv(1024)
if not data: # Клиент закрыл соединение
print("🔌 Клиент разорвал соединение.")
break
msg = data.decode('utf-8').strip()
print(f"📥 Получено: {msg}")
if msg.lower() == 'exit':
print("👋 Получена команда exit. Завершаю работу сервера.")
break
# Преобразуем в верхний регистр и отправляем обратно
response = f"SERVER: {msg.upper()}\n"
conn.sendall(response.encode('utf-8'))
print("✅ TCP сервер остановлен.")
+17
View File
@@ -0,0 +1,17 @@
import socket
HOST, PORT = '127.0.0.1', 10001
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as client:
messages = ["Привет UDP!", "Тест пакета", "exit"]
for msg in messages:
print(f"📤 Отправляю UDP: {msg}")
client.sendto(msg.encode(), (HOST, PORT))
if msg.lower() == 'exit':
break
data, _ = client.recvfrom(1024)
print(f"📥 Ответ: {data.decode().strip()}")
print("✅ UDP клиент завершил работу.")
+20
View File
@@ -0,0 +1,20 @@
import socket
HOST, PORT = '127.0.0.1', 10001
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as server:
server.bind((HOST, PORT))
print(f"🟢 UDP сервер запущен на {HOST}:{PORT}")
while True:
data, addr = server.recvfrom(1024)
msg = data.decode('utf-8').strip()
print(f"📥 От {addr}: {msg}")
if msg.lower() == 'exit':
print("👋 Получен exit. Завершаю UDP-сервер.")
break
server.sendto(f"UDP-SERVER: {msg.upper()}".encode(), addr)
print("✅ UDP сервер остановлен.")