예제 #1
0
def history(user=None):
    data = list(db.Request_logs.find({'username': user}))
    if not data:
        line_break("Sorry,No history to show")
    else:
        show_history(data)
        confirm = input("Are you sure to confirm this menu? [Y/N]: ")
예제 #2
0
def insert_menu(user=None, select_menu=None):
    if not select_menu:
        line_break("Sorry, Please select food first!!")
    else:
        show_detail(select_menu)
        confirm = input("Are you sure to confirm this menu? [Y/N]: ")
        if confirm.upper() == "Y":
            db.Request_logs.insert_one({
                "create_date": datetime.now(),
                "username": user,
                "food_detail": select_menu,
                "status": 0
            })
            return True
예제 #3
0
def ask_port(special=False):
    if not special:
        return 1234

    try:
        while True:
            port = check_port(input("Enter special port: "))
            if port:
                break
            line_break("ไม่พบเลข Port ดังกล่าว")
            sleep(2)
            _ = system('cls')
            clear_output()
        return int(port['port'])
    except Exception as e:
        print("Special:", e)
예제 #4
0
def options(user=None):
    select_food = None
    while True:
        sleep(2)
        system("cls")
        print("\n   Welcome:", user)
        print(options_text, end="")
        menu_option = input("   Select option: ").upper()
        if menu_option == 'M':
            print()
            select_food = menu()

        elif menu_option == 'C':
            confirm = insert_menu(user, select_food)
            if confirm:
                select_food = None

        elif menu_option == 'H':
            history(user)

        elif menu_option == 'E':
            line_break("Exiting...")
            sleep(2)
            system("cls")
            line_break("Thank you!!")
            break

        else:
            line_break("Please, select the correct option!!")

    return "Options: " + menu_option
예제 #5
0
def workflow(s, user):
    s.send("option".encode())
    server_data = s.recv(1024)
    if hasattr(server_data, "decode"):
        try:
            tmp = loads(server_data)
            tmp("Create user complete!!")
            sleep(2)
            options(user)

        except UnpicklingError as e:
            command = server_data.decode().upper()

            if command == "EXIT":
                s.send('exit'.encode())
                return 'break'

            elif command == "OPTION":
                system("cls")
                line_break("Welcome to food delivery!!")
                options(user)

            else:
                print(server_data.decode())
예제 #6
0
def server_command(c, addr):
    print('Connection from :', addr)
    c.send(file)

    try:
        while True:
            sleep(2)
            client_data = c.recv(1024)
            if hasattr(client_data, "decode"):
                try:
                    tmp = loads(client_data)

                    if tmp["function"] == "register":
                        (user, name, password) = tmp["params"]
                        c.send(dumps(line_break))
                        register(user, name, password)

                except UnpicklingError:
                    command = client_data.decode().upper()

                    if command == 'EXIT':
                        c.send("exit".encode())
                        line_break(
                            f"Client {addr[0]}:{addr[1]} has been disconnect!!"
                        )
                        c.close()
                        break

                    elif command == 'OPTION':
                        c.send('option'.encode())

            else:
                print("Special case")

    except UnicodeDecodeError:
        print("Unit code error :")

    except ConnectionAbortedError as con:
        print(con)

    except ConnectionResetError:
        line_break(f"Client {addr[0]}:{addr[1]} has been shutdown!!")

    except EOFError:
        line_break(f"Client not sending anything!!")
예제 #7
0
from socket import socket, gethostname
from pickle import dumps, loads
from pickle import UnpicklingError
from function.connect import ask_port
from function.member import line_break

s = socket()
host = gethostname()
port = ask_port()

try:
    try:
        s.connect((host, port))
    except ConnectionRefusedError as con:
        line_break("Server was closed.")
        exit()

    server_data = s.recv(1024)
    data = loads(server_data)()
    if data['function'] == 'register':
        print("Params:", data)
        s.send(dumps({"function": 'register', "params": data['params']}))
        user = data['params'][0]
    else:
        user = data['params']
        s.send("exit".encode())

    print("Login:", user)
    while True:
        server_data = s.recv(1024)
예제 #8
0
from socket import (gethostname)
from function.connect import ask_port
import socket
import pickle
from function.member import line_break
import time, sys

host = gethostname()

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

while True:
    try:
        port = ask_port(True)
        s.connect((host, port))
    except ConnectionRefusedError:
        line_break("Server was closed.")
    else:
        break

s.send(pickle.dumps('Hello Server'))

data = s.recv(1024)
print('Received : ', pickle.loads(data))