Проект выполнен
This commit is contained in:
parent
d337737117
commit
dac98e6b66
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1 @@
|
|||||||
.venv/
|
.env
|
||||||
|
22
gitea_api.py
Normal file
22
gitea_api.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import requests
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
TOKEN = os.getenv("GITEA_TOKEN")
|
||||||
|
|
||||||
|
|
||||||
|
headers = {"Authorization": f"token {TOKEN}"}
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"name": "3lab_testrepo",
|
||||||
|
"description": "Репозиторий созданный через API",
|
||||||
|
"private": False,
|
||||||
|
"auto_init": True
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.post("https://git.vyatsu.ru/api/v1/user/repos", json=data, headers=headers)
|
||||||
|
|
||||||
|
print("Status code:", response.status_code)
|
||||||
|
print("Text:", response.text)
|
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()
|
22
tcp_server.py
Normal file
22
tcp_server.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import socket
|
||||||
|
|
||||||
|
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
|
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
|
13
token_requiest.py
Normal file
13
token_requiest.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
import requests
|
||||||
|
|
||||||
|
load_dotenv() # Загружаем переменные из .env
|
||||||
|
|
||||||
|
token = os.getenv("GITEA_TOKEN")
|
||||||
|
if not token:
|
||||||
|
raise EnvironmentError("GITEA_TOKEN не установлен!")
|
||||||
|
|
||||||
|
headers = {"Authorization": f"token {token}"}
|
||||||
|
response = requests.get("https://git.vyatsu.ru/api/v1/user", headers=headers)
|
||||||
|
print(response.json())
|
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)
|
4
vyatsu_requiest_http.py
Normal file
4
vyatsu_requiest_http.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
response = requests.get("http://vyatsu.ru")
|
||||||
|
print(response.text[:500])
|
9
vyatsu_socket_http.py
Normal file
9
vyatsu_socket_http.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user