Добавлены TCP, UDP, HTTP, API Gitea скрипты
This commit is contained in:
parent
475de20d32
commit
9e7c3c3ca3
31
gitea_create.py
Normal file
31
gitea_create.py
Normal file
@ -0,0 +1,31 @@
|
||||
import requests
|
||||
|
||||
data = open("token.env", "r").readlines()
|
||||
for line in data:
|
||||
if "WRITE_TOKEN" in line:
|
||||
TOKEN = line.strip().split("=")[1]
|
||||
|
||||
headers = {
|
||||
"Authorization": f"token {TOKEN}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
repo_data = {
|
||||
"name": "3laba_create_by_API",
|
||||
"description": "Репозиторий создан через API",
|
||||
"private": False
|
||||
}
|
||||
|
||||
response = requests.post(
|
||||
"https://git.vyatsu.ru/api/v1/user/repos",
|
||||
headers=headers,
|
||||
json=repo_data
|
||||
)
|
||||
|
||||
if response.status_code == 201:
|
||||
print("Репозиторий создан!")
|
||||
print(response.json()["html_url"])
|
||||
else:
|
||||
print(f"Ошибка: {response.status_code}")
|
||||
print(response.text)
|
||||
|
||||
12
gitea_read.py
Normal file
12
gitea_read.py
Normal file
@ -0,0 +1,12 @@
|
||||
import requests
|
||||
|
||||
with open("token.env", "r") as f:
|
||||
for line in f:
|
||||
if line.startswith("READ_TOKEN="):
|
||||
TOKEN = line.strip().split("=")[1]
|
||||
|
||||
headers = {"Authorization": f"token {TOKEN}"}
|
||||
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
|
||||
print("Информация о пользователе:")
|
||||
print(response.json())
|
||||
|
||||
8
http_requests.py
Normal file
8
http_requests.py
Normal file
@ -0,0 +1,8 @@
|
||||
import requests
|
||||
|
||||
response = requests.get("http://vyatsu.ru")
|
||||
print("Первые 500 символов ответа:")
|
||||
print(response.text[:500])
|
||||
print("\nЗаголовки ответа:")
|
||||
print(response.headers)
|
||||
|
||||
8
tcp_client.py
Normal file
8
tcp_client.py
Normal 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 server')
|
||||
data = client.recv(1024)
|
||||
print(f"Ответ от сервера: {data.decode()}")
|
||||
client.close()
|
||||
24
tcp_server.py
Normal file
24
tcp_server.py
Normal file
@ -0,0 +1,24 @@
|
||||
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
|
||||
|
||||
print(f"Получено: {data.decode()}")
|
||||
conn.sendall(data.upper())
|
||||
print(f"Отправлено: {data.upper().decode()}")
|
||||
|
||||
conn.close()
|
||||
|
||||
if data.upper() == b'EXIT':
|
||||
print("Завершение работы сервера")
|
||||
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 сервер запущен на порту 10001")
|
||||
|
||||
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