Compare commits

...

3 Commits

13 changed files with 153 additions and 0 deletions

2
.gitignore vendored
View File

@ -159,4 +159,6 @@ cython_debug/
# 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.
#.idea/
.venv
.env

5
practic03/.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
practic03/.idea/misc.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.12 (practic03)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (practic03)" project-jdk-type="Python SDK" />
</project>

8
practic03/.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/practic03.iml" filepath="$PROJECT_DIR$/.idea/practic03.iml" />
</modules>
</component>
</project>

10
practic03/.idea/practic03.iml generated Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.12 (practic03)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

55
practic03/gitea_api.py Normal file
View 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("NIMER3")

View File

@ -0,0 +1,5 @@
import requests
response = requests.get("http://vyatsu.ru")
print(response.status_code)
print(response.text[:500])

9
practic03/http_socket.py Normal file
View 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
practic03/tcp_client.py Normal file
View 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 server11')
data = client.recv(1024)
print(f"Ответ от сервера: {data.decode()}")
client.close()

21
practic03/tcp_server.py Normal file
View 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

10
practic03/udp_cerver.py Normal file
View 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)

7
practic03/udp_client.py Normal file
View File

@ -0,0 +1,7 @@
import socket
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
client.sendto(b'hello server', ('127.0.0.1', 10001))
data, _ = client.recvfrom(1024)
print(f"Ответ от сервера: {data.decode()}")
client.close()