all Laba2
This commit is contained in:
parent
c6feb29706
commit
2b295dfb39
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
.venv/
|
.venv/
|
||||||
|
.env
|
||||||
15
gitea_read.py
Normal file
15
gitea_read.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import os
|
||||||
|
import requests
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
TOKEN = os.getenv("GITEA_TOKEN_READ")
|
||||||
|
headers = {"Authorization": f"token {TOKEN}"}
|
||||||
|
|
||||||
|
owner = "stud203988"
|
||||||
|
repo = "Laba2"
|
||||||
|
|
||||||
|
response = requests.get(f"https://git.vyatsu.ru/api/v1/repos/{owner}/{repo}", headers=headers)
|
||||||
|
print("Информация о репозитории:")
|
||||||
|
print(response.json())
|
||||||
22
gitea_write.py
Normal file
22
gitea_write.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import os
|
||||||
|
import requests
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
TOKEN = os.getenv("GITEA_TOKEN_WRITE")
|
||||||
|
headers = {
|
||||||
|
"Authorization": f"token {TOKEN}",
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
|
||||||
|
owner = "stud203988"
|
||||||
|
repo = "Laba2"
|
||||||
|
data = {
|
||||||
|
"description": "Обновлённое описание репозитория через API",
|
||||||
|
"private": False
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.patch(f"https://git.vyatsu.ru/api/v1/repos/{owner}/{repo}", headers=headers, json=data)
|
||||||
|
print(f"Статус: {response.status_code}")
|
||||||
|
print(response.json())
|
||||||
4
http_requests.py
Normal file
4
http_requests.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
response = requests.get("http://vyatsu.ru")
|
||||||
|
print(response.text[:500])
|
||||||
17
http_socket.py
Normal file
17
http_socket.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\nHost: vyatsu.ru\r\nUser-agent: python-requests/2.33.1\r\nAccept-Encoding: gzip, deflate, zstd\r\nAccept: */*\r\nConnection: keep-alive\r\n"
|
||||||
|
client.sendall(request.encode())
|
||||||
|
chunks = []
|
||||||
|
while True:
|
||||||
|
chunk = client.recv(4096)
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
chunks.append(chunk)
|
||||||
|
|
||||||
|
response = b"".join(chunks)
|
||||||
|
|
||||||
|
print(response.decode())
|
||||||
|
client.close()
|
||||||
10
tcp_client.py
Normal file
10
tcp_client.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
client.connect(('127.0.0.1', 10000))
|
||||||
|
|
||||||
|
message = input("Введите сообщение: ")
|
||||||
|
client.sendall(message.encode())
|
||||||
|
data = client.recv(1024)
|
||||||
|
print("Ответ от сервера:", data.decode())
|
||||||
|
client.close()
|
||||||
17
tcp_server.py
Normal file
17
tcp_server.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
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
udp_client.py
Normal file
7
udp_client.py
Normal 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()
|
||||||
10
udp_server.py
Normal file
10
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', 10001))
|
||||||
|
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