def view_forum(forum_name):
    global forum_details
    forum_details['action'] = "view_forum"
    forum_details['forum_name'] = forum_name

    forum_json = JSON_Socket.json()
    json_object = forum_json.deserializer(forum_details)

    return json_object,forum_name
Esempio n. 2
0
def main():
    global dict_user

    client = mySocket()
    host = socket.gethostname()
    port = 8999
    client.connect((host, port))
    while True:
        print "Welcome To TEAM 13 Forum :P"
        print "\t 1. Sign in"
        print "\t 2. Sign Up for Free"
        print "\t 3. View Forums"
        print "\t 4. Exit"

        choice = raw_input("Please Select an Option : ")

        if choice == '1':
            input = signin()
            client_json = JSON_Socket.json()
            client_json.deserializer(input)
            client.send(client_json.representation())
            received = client.receive()
            print received

        elif choice == '2':
            input = signup()
            client_json = JSON_Socket.json()
            client_json.deserializer(input)
            client.send(client_json.representation())
            received = client.receive()
            print received

        elif choice == '3':
            display()


        elif choice == '4':
            client.close()

        else:
            print "\nPlease Select a Valid Option"

    pass
def main():
    global dict_user
    global uname

    client = mySocket()
    host = socket.gethostname()
    port = 8999
    client.connect((host, port))
    while True:
        print "Welcome To TEAM 13 Forum :P"
        print "\t 1. Sign in"
        print "\t 2. Sign Up for Free"
        print "\t 3. View Forums"
        print "\t 4. Exit"

        choice = raw_input("Please Select an Option : ")

        if choice == '1':
            input = signin()
            uname = input['username']
            client_json = JSON_Socket.json()
            json_object = client_json.deserializer(input)
            client.send(json_object)
            received = client.receive()
            serialized = serialize_auth(received)
            if serialized == "True":
                print "Welcome, " + uname
                while True:
                    forum_name = display_user(uname)
                    client.send(forum_name)
                    display_forums_from_server = client.receive()
                    subforums_Json = JSON_Socket.json()
                    output = subforums_Json.serializer(display_forums_from_server)
                    output += output.split()
                    while True:
                        client.send(display_user_selected_forum(output,uname))
                        questions = client.receive()
                        questions_Json = JSON_Socket.json()
                        questions = questions_Json.serializer(questions)
                        result = display_questions(questions)
                        if result == "break":
                            break
                        elif result == "exit":
                            exit(0)
                        client.send(result)
                        about_question = client.receive()
                        pass

                pass
            else:
                print "Invalid Login Credentials"

        elif choice == '2':
            input = signup()
            client_json = JSON_Socket.json()
            client_json.deserializer(input)
            client.send(client_json.representation())
            received = client.receive()
            print received

        elif choice == '3':
            display()


        elif choice == '4':
            client.close()

        else:
            print "\nPlease Select a Valid Option"

    pass
def main():
    global dict_user
    global uname
    try:
        client = mySocket()
        host = socket.gethostname()
        port = 8100
        client.connect((host, port))
        while True:
            print ""
            print "Welcome To TEAM 13 Forums"
            print "\t1. Sign in"
            print "\t2. Sign Up for Free"
            print "\t3. View Forums"
            print "\t4. Exit"

            choice = raw_input("Please Select an Option : ")

            if choice == '1':
                input = signin()
                uname = input['name']
                client_json = JSON_Socket.json()
                json_object = client_json.deserializer(input)
                client.send(json_object)
                received = client.receive()
                serialized = serialize_auth(received)
                if serialized == "login successful":
                    print "\n","*********Login Successful*********"
                    print "Welcome, " + uname,"\n"
                    while True:
                        data_forum,f_name = display_user(uname)
                        if data_forum['action'] == "break":
                            break
                        while True:
                            client.send(data_forum)
                            a=client.receive()
                            a=a.split(";")
                            display_forums_from_server=a[0]
                            list_ids=a[1]
                            subforums_Json = JSON_Socket.json()
                            output = subforums_Json.serializer(display_forums_from_server)
                            list_output=convert_string_list_to_list(list_ids)
                            data_send = display_user_selected_forum(f_name,output,uname,list_output)
                            if data_send['action'] == "break":
                                break
                            elif data_send['action'] == "LogOut":
                                exit(0)
                            elif data_send['action'] == "open_sub_forum":
                                while True:
                                    sub_forum = data_send['name']
                                    client.send(str(data_send))
                                    questions = client.receive()
                                    cli_json= JSON_Socket.json()
                                    if questions == None:
                                        continue
                                    for i in range(len(questions)):
                                        if questions[i] == ";":
                                            break
                                    id_of_question = questions[(i+1):]
                                    id_of_question = convert_string_list_to_list(id_of_question)
                                    questions= cli_json.serializer(questions)
                                    question,id_q = split_client_one(questions)
                                    operation = display_questions(question,uname,f_name,sub_forum,id_of_question)
                                    if operation['action'] == 'post_question':
                                        sub_forum=operation['sub_forum']
                                        client.send(str(operation))
                                        rcvd = client.receive()
                                        questions=client_json.serializer(rcvd)
                                        if questions['message'] == "unsuccessful":
                                            continue
                                    if operation['action'] == "continue":
                                        break
                                    if operation['action'] == "view_question":
                                        while True:
                                            question_id = operation['question_id']
                                            client.send(str(operation))
                                            received = client.receive()
                                            questions_about = client_json.serializer(received)
                                            if questions_about['message']:
                                                display_reply(questions_about)
                                            result = display_replies(uname,f_name,sub_forum,question_id)
                                            if result['action'] == "break":
                                                break
                                            client.send(result)
                                            about_reply = client.receive()
                                            print_rep_info = serialize_auth(about_reply)
                                            print print_rep_info
                            elif data_send['action'] == "new_sub_forum":
                                sub_forum=data_send["name"]
                                client.send(str(data_send))
                                success = client.receive()
                                success = client_json.serializer(success)
                                for i in success.values():
                                    print i
                else:
                    print "\n$$$$$Invalid Login Credentials. Please re-check them$$$$$\n"
            elif choice == '2':
                input = signup()
                client_json = JSON_Socket.json()
                client.send(client_json.deserializer(input))
                received = client.receive()
                print received
            elif choice == '3':
                display()
            elif choice == '4':
                input=exit_connection()
                client_json = JSON_Socket.json()
                client.send(client_json.deserializer(input))
                client.close()
                break
            else:
                print "\nPlease Select a Valid Option\n"
    except Exception as e:
        print e,"\n$$$$$Error at line 279$$$$$\n"
    pass
def main():
    global dict_user
    global uname

    client = mySocket()
    host = socket.gethostname()
    port = 8999
    client.connect((host, port))
    while True:
        print "Welcome To TEAM 13 Forum :P"
        print "\t 1. Sign in"
        print "\t 2. Sign Up for Free"
        print "\t 3. View Forums"
        print "\t 4. Exit"

        choice = raw_input("Please Select an Option : ")

        if choice == '1':
            input = signin()
            uname = input['username']
            client_json = JSON_Socket.json()
            json_object = client_json.deserializer(input)
            client.send(json_object)
            received = client.receive()
            serialized = serialize_auth(received)
            if serialized == "login successful":
                print "Welcome, " + uname
                while True:
                    forum_name,f_name = display_user(uname)
                    client.send(forum_name)
                    display_forums_from_server = client.receive()
                    subforums_Json = JSON_Socket.json()
                    output = subforums_Json.serializer(display_forums_from_server)
                    #output += output.split()
                    data_send = display_user_selected_forum(f_name,output,uname)
                    sub_forum=data_send["new_forum_name"]
                    client.send(str(data_send))
                    questions = client.receive()
                    print questions
                    cli_json=JSON_Socket.json()
                    questions= cli_json.serializer(questions)
                    questions,id_q = split_client(questions)
                    while True:
                        result = display_questions(questions,uname,f_name,sub_forum,id_q)
                        if result == "break":
                            break
                        elif result == "exit":
                            exit(0)
                        client.send(result)
                        about_question = client.receive()
                        print_info = serialize_auth(about_question)
                        print_info.split()
                        while True:
                            for i in print_info:
                                print i
                            #replies_Json = JSON_Socket.json()
                            #replies = replies_Json.serializer(about_question)
                            result = display_replies(uname,f_name,sub_forum)
                            if result == "break":
                                break
                            elif result =="exit":
                                exit(0)
                            client.send(result)
                            about_reply = client.receive()
                            print_rep_info = serialize_auth(about_reply)
                            print_rep_info.split()
                            for i in print_rep_info:
                             print i
            else:
                print "Invalid Login Credentials. Please re-check them"

        elif choice == '2':
            input = signup()
            client_json = JSON_Socket.json()
            client.send(client_json.deserializer(input))
            received = client.receive()
            print received

        elif choice == '3':
            display()


        elif choice == '4':
            input=exit_connection()
            client_json = JSON_Socket.json()
            client.send(client_json.deserializer(input))
            client.close()
            break

        else:
            print "\nPlease Select a Valid Option"

    pass