Compare commits
No commits in common. "main" and "c4617b05ae4ba8f6b712d018671b56164e71c767" have entirely different histories.
main
...
c4617b05ae
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
venv/
|
||||||
|
.env/
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
*.log
|
||||||
|
api_git_example.py
|
||||||
|
token.py
|
||||||
6
api_git_example.py
Normal file
6
api_git_example.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
TOKEN = "GIT_VYATSU_TOKEN1"
|
||||||
|
headers = {"Authorization": f"token {TOKEN}"}
|
||||||
|
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
|
||||||
|
print(response.json())
|
||||||
19
gitea_create_repo.py
Normal file
19
gitea_create_repo.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import os
|
||||||
|
import requests
|
||||||
|
|
||||||
|
TOKEN = os.getenv("GITEA_WRITE_TOKEN")
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"token {TOKEN}",
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"name": "lab3-api-repo",
|
||||||
|
"description": "Репозиторий создан через Gitea API",
|
||||||
|
"private": False,
|
||||||
|
"auto_init": True
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post("https://git.vyatsu.ru/api/v1/user/repos", json=data, headers=headers)
|
||||||
|
print(response.status_code)
|
||||||
|
print(response.json())
|
||||||
13
gitea_read_user.py
Normal file
13
gitea_read_user.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import os
|
||||||
|
import requests
|
||||||
|
|
||||||
|
TOKEN = os.getenv("GITEA_READ_TOKEN")
|
||||||
|
|
||||||
|
if not TOKEN:
|
||||||
|
raise RuntimeError("Переменная окружения GITEA_READ_TOKEN не задана")
|
||||||
|
|
||||||
|
headers = {"Authorization": f"token {TOKEN}"}
|
||||||
|
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
|
||||||
|
|
||||||
|
print(response.status_code)
|
||||||
|
print(response.text)
|
||||||
17
http_socket_client.py
Normal file
17
http_socket_client.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
client.connect(("vyatsu.ru", 80))
|
||||||
|
|
||||||
|
request = (
|
||||||
|
"GET / HTTP/1.1\r\n"
|
||||||
|
"Host: vyatsu.ru\r\n"
|
||||||
|
"Connection: close\r\n"
|
||||||
|
"\r\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
client.sendall(request.encode("utf-8"))
|
||||||
|
response = client.recv(4096)
|
||||||
|
print(response.decode(errors="ignore"))
|
||||||
|
|
||||||
|
client.close()
|
||||||
4
requests_example.py
Normal file
4
requests_example.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
response = requests.get("http://vyatsu.ru")
|
||||||
|
print(response.text[:500])
|
||||||
12
tcp_client.py
Normal file
12
tcp_client.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
client.connect(("127.0.0.1", 12000))
|
||||||
|
|
||||||
|
message = "hello server"
|
||||||
|
client.sendall(message.encode())
|
||||||
|
|
||||||
|
data = client.recv(1024)
|
||||||
|
print(f"Ответ от сервера: {data.decode()}")
|
||||||
|
|
||||||
|
client.close()
|
||||||
30
tcp_server.py
Normal file
30
tcp_server.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
server.bind(("0.0.0.0", 12000))
|
||||||
|
server.listen(1)
|
||||||
|
|
||||||
|
print("TCP сервер запущен и ожидает подключения...")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
conn, addr = server.accept()
|
||||||
|
print(f"Подключение от {addr}")
|
||||||
|
|
||||||
|
data = conn.recv(1024)
|
||||||
|
if not data:
|
||||||
|
conn.close()
|
||||||
|
continue
|
||||||
|
|
||||||
|
message = data.decode()
|
||||||
|
print(f"Получено сообщение: {message}")
|
||||||
|
|
||||||
|
response = message.upper()
|
||||||
|
conn.sendall(response.encode())
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
if response == "EXIT":
|
||||||
|
print("Сервер завершает работу")
|
||||||
|
break
|
||||||
|
|
||||||
|
server.close()
|
||||||
11
udp_client.py
Normal file
11
udp_client.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
|
||||||
|
message = "привет сервер"
|
||||||
|
client.sendto(message.encode(), ("127.0.0.1", 10001))
|
||||||
|
|
||||||
|
data, _ = client.recvfrom(1024)
|
||||||
|
print(f"Ответ от сервера: {data.decode()}")
|
||||||
|
|
||||||
|
client.close()
|
||||||
14
udp_server.py
Normal file
14
udp_server.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
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)
|
||||||
|
message = data.decode()
|
||||||
|
print(f"Сообщение от {addr}: {message}")
|
||||||
|
|
||||||
|
response = message.upper()
|
||||||
|
server.sendto(response.encode(), addr)
|
||||||
Loading…
Reference in New Issue
Block a user