Exemple #1
0
    def recommendations(self):
        # origin = "Main Library, University of New South Wales, Sydney, Australia"
        curr_user = current_user.get_cu()
        if curr_user is None:
            print ("Something is wrong. Someone must be logged in, please login first")
            return
        current_user_id = curr_user.id
        user = User_Profile.query.filter_by(id=current_user_id).first()
        origin = input("Your current locaton please: ")


        recs_sys = Recommendation_System()
        # current_user_id = current_user.id
        # current_user_id = current_user.id
        curr_user = current_user.get_cu()
        if curr_user is None:
            print ("Something is wrong. Someone must be logged in, please login first")
            return
        current_user_id = curr_user.id
        user = User_Profile.query.filter_by(id=current_user_id).first()
        user.location = origin
        db.session.commit()
        recommendations = recs_sys.getRecommendations(origin, current_user_id)
        print(len(recommendations))
        # To print during pytest, uncomment False Assertion
        for recommendation in recommendations:
            # event.user_id = owner.id
            print("########################")
            print("Username: "******"Name: ", recommendation['match_name'])
            # print("Age: ", recommendation['match_age'])
            # print("Bio: ", recommendation['bio'])
            print("Distance: ", recommendation['distance'])
Exemple #2
0
    def get_businesses(self):

        curr_user = current_user.get_cu()
        if curr_user is None:
            print("Something is wrong. Someone must be logged in, please login first")
            return
        current_user_id = curr_user.id

        while True:
            command = input(
                "commands: businesses list, search business, search category, all deals, business deals, exit: ")
            if command == "exit":
                break

            if command == "businesses list":
                self.view_businesses()

            if command == "search business":
                self.serch_businesses()

            if command == "search category":
                self.serch_category()

            if command == "all deals":
                self.view_deals()

            if command == "business deals":
                self.deals_for_business()
Exemple #3
0
    def get_conversation_messages(self):
        curr_user = current_user.get_cu()
        if curr_user is None:
            print("Something is wrong. Someone must be logged in, please login first")
            return
        current_user_id = curr_user.id
        target_username = input("Which conversation would you like to view: ")
        target_user = User_Profile.query.filter_by(username=target_username).first()
        if target_user is None:
            print ("We couldn't find a user with that username, please check the username and try again")
            return
        username_one = User_Profile.query.filter_by(id=current_user_id).first().id
        username_two = target_user.id
        if (Conversation.query.filter_by(username_one=username_one).filter_by(username_two=username_two).first()) is not None:
            room_id=Conversation.query.filter_by(username_one=username_one).filter_by(username_two=username_two).first().room
        elif (Conversation.query.filter_by(username_two=username_one).filter_by(username_one=username_two).first()) is not None:
            room_id=Conversation.query.filter_by(username_two=username_one).filter_by(username_one=username_two).first().room
        else:
            print("Conversation with " + target_username + " does not exist in our system. Are you sure, its the right username?")
            return


        message_sys = Message_System()
        conversation, messages = message_sys.getMessages(room_id, current_user_id)
        print("########################")
        print("Username: "******"***********************")
        for message in messages:
            print("Message Sender: ", message['message_username'])
            print("Message: ", message['message'])
            print("Time: ", message['time_sent'])
Exemple #4
0
    def make_reservation(self):
        print("Reservation System")
        print("########################")
        curr_user = current_user.get_cu()
        if curr_user is None:
            print("Something is wrong. Someone must be logged in, please login first")
            return
        current_user_id = curr_user.id

        reserv_sys = Reservation_system()

        matches = reserv_sys.get_matched_users(current_user_id)

        if not matches:
            print("Sorry you dont have any matches to make reservations with")
            return
        print("Your current matches include: ")
        print("########################")

        x = 1
        for record in matches:
            print(record)
            x = x + 1
        print("########################")
        match_id = input("Please add the user id of the match you want to book for: ")
        deals_sys = Deals_system()

        print("Current deals available include: ")
        print("########################")
        deals_sys = Deals_system()
        deals = deals_sys.all_deals_list()
        if not deals:
            print("Sorry no deals available at this time!")
            return

        x = 1;

        for record in deals:
            print("Deal ", x)
            print(record)
            x = x + 1

        print("########################")
        deal_id = input("Please add the deal id of the deal you want to book for: ")
        print("########################")
        start_time = input("Please specify reservation start time in format HH:MM: ")
        end_time = input("Please specify reservation end time: in format HH:MM: ")
        date_of_meeting = input("Please specify reservation date in format YYYY-MM-DD: ")
        print("########################")
        date_time_obj = datetime.strptime(date_of_meeting, '%Y-%m-%d')
        check = reserv_sys.check_date(deal_id, date_time_obj.date())

        if not check:
            message = "You either tried to book for an expired deal or booked a date before today, please go back an try again. "
            return message
        result = reserv_sys.add_meeting(deal_id, match_id, date_time_obj.date(), start_time, end_time)
        print("Meeting booked with the following information:")
        print(result)
Exemple #5
0
    def get_conversations(self):
        curr_user = current_user.get_cu()
        if curr_user is None:
            print("Something is wrong. Someone must be logged in, please login first")
            return
        current_user_id = curr_user.id

        message_sys = Message_System()
        conversations = message_sys.getConversations(current_user_id)
        for conversation in conversations:
            print("########################")
            # print("First Name: ", recommendation.f_name)
            # print ("Last Name: ", recommendation.l_name)
            # print("addr: ", event.addr)
            # print("start: ", event.start_time)
            # print("end: ", event.end_time)
            print("Username: "******"Last_Message: ", conversation['last_message'])
            print("Time: ", conversation['time'])
Exemple #6
0
    def command_centre(self):
        with app.app_context():
            print("Testing authentication:")
            command = ""
            while True:
                command = input(

                    "commands: signup, signup dummy, login, logout, view blocked, block, profile, recommendations,"
                    "swipe_right, my_conversations, view conversation, send_message, business, reservation,exit: ")

                if command == "exit":
                    break

                if command == "get user":
                    print(current_user.get_cu())
                    continue

                if command == "signup":
                    request = {'email': input("enter email: "), 'username': input("enter username: "******"enter first name: "), 'l_name': input("enter last name: "),
                               'password': input("enter password: "******"confirm password: "******"enter DOB (YYYY-MM-DD): "),
                               'min_target': input("enter min matching age: "),
                               'max_target': input("enter max matching age: "),
                               'gender': input("enter gender (male, female, other): "),
                               'gender_preference': input("enter gender preference (male, female, everyone): "),
                               'bio': input("enter bio: "), 'location': input("enter matching location: "),
                               'max_match_distance': input("enter max match distance: ")}

                    signup(request)
                    continue

                if command == "signup dummy":
                    request = {'email': '*****@*****.**', 'username': '******', 'f_name': 'sascha',
                               'l_name': 'graham', 'password': '******', 'password_repeat': 'awd', 'dob': '1999-11-02',
                               'min_target': '16', 'max_target': '22', 'gender': 'male',
                               'gender_preference': 'everyone',
                               'bio': 'awd', 'location': '23 Cameron Ave Artarmon', 'max_match_distance': '200'}

                    signup(request)
                    continue

                if command == "login":
                    request = {'username': input("enter username: "******"enter password: "******"logout":
                    logout()
                    continue

                if command == "view blocked":
                    print("blocked users: ")
                    print(view_blocked())
                    continue

                if command == "block":
                    print("blockable users: ")
                    print(view_blockable())
                    target_user = input("select user, \\n to abort: ")
                    if target_user == "":
                        continue
                    block(target_user)

                if command == "profile":
                    print("profile:\n\n")
                    print(view_profile())
                    profile_command = input("commands: edit match preferences (1), edit bio(2), exit profile (3): ")
                    if profile_command == "1":
                        edit = input(
                            "gender preference (1), min match age (2), max match age (3), max match distance (4): ")
                        if edit == "1":
                            pref = input("new gender preference (male, female, everyone): ")
                            update_gender_preference(pref)
                        if edit == "2":
                            age = input("new min match age: ")
                            update_min_match_age(age)
                        if edit == "3":
                            age = input("new max match age: ")
                            update_max_match_age(age)
                        if edit == "4":
                            dist = input("new max match distance: ")
                            update_max_match_distance(dist)
                    if profile_command == "2":
                        bio = input("new bio (150 chars): ")
                        update_bio(bio)
                    if profile_command == "3":
                        pass

                if command == "recommendations":
                    self.recommendations()
                if command == "swipe_right":
                    self.right_swipe()
                if command == "my_conversations":
                    self.get_conversations()
                if command == "view conversation":
                    self.get_conversation_messages()
                if command == "send_message":
                    self.send_message()
                    
                if command == "business":
                    self.get_businesses()

                if command == "reservation":
                    self.make_reservation()
Exemple #7
0
    def send_message(self):
        curr_user = current_user.get_cu()
        if curr_user is None:
            print("Something is wrong. Someone must be logged in, please login first")
            return
        current_user_id = curr_user.id
        while True:
            try:
                username_input = input("Who would you like to message?: ")
                target_user = User_Profile.query.filter_by(username=username_input).first()
                if target_user is None:
                    print("We couldn't find a user with that username, please check the username and try again")
                    return
                username_one = User_Profile.query.filter_by(id=current_user_id).first().id
                username_two = target_user.id
                if (Conversation.query.filter_by(username_one=username_one).filter_by(
                        username_two=username_two).first()) is not None:
                    room_id = Conversation.query.filter_by(username_one=username_one).filter_by(
                        username_two=username_two).first().room
                elif (Conversation.query.filter_by(username_two=username_one).filter_by(
                        username_one=username_two).first()) is not None:
                    room_id = Conversation.query.filter_by(username_two=username_one).filter_by(
                        username_one=username_two).first().room
                else:
                    print(
                        "Conversation with " + username_input + " does not exist in our system. Are you sure, its the right username?")
                    return
                message_sys = Message_System()
                conversation, messages = message_sys.getMessages(room_id, current_user_id)
                print("########################")
                print("Username: "******"***********************")
                for message in messages:
                    print("Message Sender: ", message['message_username'])
                    print("Message: ", message['message'])
                    print("Time: ", message['time_sent'])
            except KeyboardInterrupt:
                print() # newline
                break
            while True:
                try:
                    message_input = input("Message: ")
                except KeyboardInterrupt:
                    print() # newline
                    break
                json = {'user_name': username_input,
                        'message': message_input}


                username = User_Profile.query.filter_by(username=json['user_name']).first()
                if username is None:
                    # socketio.emit('my response', json, callback="Something is wrong, Username cannot be found")
                    # exit(100)
                    print("We couldn't find a user with that username, please check the username and try again")
                    return

                conversation = Conversation.query.filter_by(username_one=username.id).filter_by(
                    username_two=current_user_id).first()
                if conversation is None:
                    conversation = Conversation.query.filter_by(username_two=username.id).filter_by(
                        username_one=current_user_id).first()
                if conversation is None:
                    # socketio.emit('my response', json, callback="Something is wrong, Conversation Room cannot be found")
                    # exit(200)
                    print("Conversation with " + username_input + " does not exist in our system. Are you sure, its the right username?")
                    return
                room = conversation.room
                message = Messages(room=room,
                                   sender_username=current_user_id,
                                   time_sent=datetime.now(),
                                   message=json['message'])
                db.session.add(message)
                db.session.commit()
                message_sys = Message_System()
                conversation, messages = message_sys.getMessages(room, current_user_id)
                print("########################")
                print("Username: "******"***********************")
                for message in messages:
                    print("---------------------------------------")
                    print("Message Sender: ", message['message_username'])
                    print("Message: ", message['message'])
                    print("Time: ", message['time_sent'])
Exemple #8
0
    def right_swipe(self):
        curr_user = current_user.get_cu()
        if curr_user is None:
            print ("Something is wrong. Someone must be logged in, please login first")
            return
        current_user_id = curr_user.id
        user = User_Profile.query.filter_by(id=current_user_id).first()
        username = input("Username of person, you want to swipe on: ")
        target_user = User_Profile.query.filter_by(username=username).first()
        if target_user is None:
            print ("We couldn't find an user with that username, please check the username and try again")
            return
        distance = self.Google_Maps_Api.get_distance(user.location, target_user.location, 'driving')
        if distance == -1:
            print("Google Maps could not return a possible distance. Check the error message from Google")
            return
        match_dict = {"match_user_username": username,
                      "distance": distance}


        right_swipes = Right_Swipes()
        current_user_id = curr_user.id
        target_id = User_Profile.query.filter_by(username=match_dict['match_user_username']).first().id
        previous_swipe = right_swipes.right_swipes(match_dict, current_user_id, target_id)
        if previous_swipe == 1:
            second_right_swipe = Right_Swipe(time=datetime.now(),
                                             swiper_id=current_user_id,
                                             target_id=target_id,
                                             became_match=True)
            db.session.add(second_right_swipe)
            db.session.commit()
            room_id = str(target_id) + "+" + str(current_user_id)
            conversation = Conversation(room=room_id,
                                        username_one=target_id,
                                        username_two=current_user_id)
            db.session.add(conversation)
            db.session.commit()
            match = Match(distance=match_dict['distance'],
                          created=datetime.now(),
                          first_swiper=target_id,
                          second_swiper=current_user_id,
                          conversation_id=room_id)
            db.session.add(match)
            db.session.commit()
            found_match = {"succesful_error_message": "Found a match",
                           "successful_error_code": 0}
            code = found_match
            # socketio.emit("join_response", found_match)
        elif previous_swipe == -1:
            first_right_swipe = Right_Swipe(time=datetime.now(),
                                            swiper_id=current_user_id,
                                            target_id=target_id)
            db.session.add(first_right_swipe)
            db.session.commit()
            first_right_swipe = {"successful_error_message": "Request has been included into our system",
                                 "successful_error_code": 1}
            code = first_right_swipe
            # socketio.emit("join_response", first_right_swipe)
        else:
            error_code = {"successful_error_message": "Something went wrong",
                          "successful_error_code": -1}
            code = error_code
        return code