Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import json
- import pandas as pd
- def get_website(organization_name):
- data = pd.read_csv('organizations.csv')
- website = data[data['Name'] == organization_name]['Website'].values
- if len(website) > 0:
- return website[0]
- else:
- return "Organization not found"
- def get_country(organization_name):
- data = pd.read_csv('organizations.csv')
- country = data[data['Name'] == organization_name]['Country'].values
- if len(country) > 0:
- return country[0]
- else:
- return "Organization not found"
- def get_number_of_employees(organization_name):
- data = pd.read_csv('organizations.csv')
- employees = data[data['Name'] == organization_name]['Number of Employees'].values
- if len(employees) > 0:
- return str(employees[0])
- else:
- return "Organization not found"
- def start_server():
- host = "127.0.0.32"
- port = 12345
- server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- server_socket.bind((host, port))
- server_socket.listen(1)
- while True:
- client_socket, address = server_socket.accept()
- data = client_socket.recv(1024)
- if data is None:
- break
- message = data.decode()
- if message == "exit":
- break
- print(f'Строка от клиента: {message}')
- request_data = json.loads(message)
- operation = request_data.get("operation")
- name = request_data.get("name")
- if operation == "get_website":
- result = get_website(name)
- elif operation == "get_country":
- result = get_country(name)
- elif operation == "get_number_of_employees":
- result = get_number_of_employees(name)
- else:
- result = "Invalid operation"
- client_socket.send(result.encode())
- client_socket.close()
- if __name__ == "__main__":
- start_server()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement