all code
This commit is contained in:
parent
596fa11cad
commit
2fb1064c9e
10
gitea_api_read.py
Normal file
10
gitea_api_read.py
Normal file
@ -0,0 +1,10 @@
|
||||
import requests
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
TOKEN = os.getenv("GITEA_READ_TOKEN")
|
||||
headers = {"Authorization": f"token {TOKEN}"}
|
||||
|
||||
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
|
||||
print(response.json())
|
||||
24
gitea_api_write.py
Normal file
24
gitea_api_write.py
Normal file
@ -0,0 +1,24 @@
|
||||
import requests
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
TOKEN = os.getenv("GITEA_WRITE_TOKEN")
|
||||
headers = {
|
||||
"Authorization": f"token {TOKEN}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
repo_data = {
|
||||
"name": "my-test-repo",
|
||||
"description": "Создан через API",
|
||||
"private": False
|
||||
}
|
||||
|
||||
response = requests.post("https://git.vyatsu.ru/api/v1/user/repos",
|
||||
json=repo_data,
|
||||
headers=headers)
|
||||
|
||||
print(f"Статус: {response.status_code}")
|
||||
print(response.json())
|
||||
4
request_client.py
Normal file
4
request_client.py
Normal file
@ -0,0 +1,4 @@
|
||||
import requests
|
||||
|
||||
response = requests.get("http://vyatsu.ru")
|
||||
print(response.text[:500])
|
||||
27
socket_client.py
Normal file
27
socket_client.py
Normal file
@ -0,0 +1,27 @@
|
||||
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"
|
||||
"User-Agent: python-requests/2.33.1\r\n"
|
||||
"Accept-Encoding: gzip, deflate, zstd\r\n"
|
||||
"Accept: */*\r\n"
|
||||
"Connection: keep-alive\r\n"
|
||||
"\r\n")
|
||||
|
||||
client.sendall(request.encode())
|
||||
|
||||
full_response = b""
|
||||
while True:
|
||||
try:
|
||||
chunk = client.recv(4096)
|
||||
if not chunk:
|
||||
break
|
||||
full_response += chunk
|
||||
except socket.timeout:
|
||||
break
|
||||
|
||||
print(full_response.decode('utf-8', errors='replace'))
|
||||
client.close()
|
||||
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', 10000))
|
||||
|
||||
message = input("Введите сообщение для сервера (или 'EXIT' для остановки сервера): ")
|
||||
client.sendall(message.encode())
|
||||
|
||||
data = client.recv(1024)
|
||||
print(f"Ответ от сервера: {data.decode()}")
|
||||
|
||||
client.close()
|
||||
25
tcp_server.py
Normal file
25
tcp_server.py
Normal file
@ -0,0 +1,25 @@
|
||||
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
|
||||
|
||||
modified_data = data.upper()
|
||||
conn.sendall(modified_data)
|
||||
|
||||
conn.close()
|
||||
|
||||
if data.upper() == b'EXIT':
|
||||
print("Получена команда EXIT, сервер завершает работу")
|
||||
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 = input("Введите сообщение для UDP сервера: ")
|
||||
client.sendto(message.encode(), ('127.0.0.1', 10001))
|
||||
|
||||
data, _ = client.recvfrom(1024)
|
||||
print(f"Ответ от UDP сервера: {data.decode()}")
|
||||
|
||||
client.close()
|
||||
12
udp_server.py
Normal file
12
udp_server.py
Normal file
@ -0,0 +1,12 @@
|
||||
import socket
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
server.bind(('0.0.0.0', 10001))
|
||||
print("UDP сервер запущен на порту 10001")
|
||||
|
||||
while True:
|
||||
data, addr = server.recvfrom(1024)
|
||||
print(f"Сообщение от {addr}: {data.decode()}")
|
||||
|
||||
modified_data = data.lower()
|
||||
server.sendto(modified_data, addr)
|
||||
Loading…
Reference in New Issue
Block a user