コード例 #1
0
def post():
    """
  This function is used to add a created post to the database.
  :return: Return a boolean that determines successful creation.
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get the info from the json file sent with the request
        data = request.get_json()

        try:
            title = data['postTitle']
            userId = data['userId']
            postText = data['postText']
            topics = data['topics']
        except KeyError:
            return invalid_json_format_string

        db.newPost(userId, title, postText, topics)

    except Exception as e:
        log(str(e))

    return "Post successfully created!"
コード例 #2
0
def validate_username():
    """
  This function is used to validate a given user's username.
  :return: Return a boolean that determines validation
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get the info from the json file sent with the request
        data = request.get_json()

        try:
            username = data['user']
        except KeyError:
            return invalid_json_format_string

        db.validateUsername(username)
    except Exception as e:
        log(str(e))

    return """
  Username successfully validated!
  username: {}
  """.format(username)
コード例 #3
0
def update_description():
    """
  This function is called to update a user's description.
  :return: Display information about the updated information.
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get the info from the json file sent with the request
        data = request.get_json()

        try:
            userId = data['userId']
            newDescription = data['newDescription']
        except KeyError:
            log(invalid_json_format_string)
            return invalid_json_format_string

        # Send the info to the database
        db.updateDescription(userId, newDescription)
        log("Updated Description")
    except Exception as e:
        return str(e)
        log(str(e))
        return "Error"

    return """
Updated Description!
  userId: {}
  newDescription: {}
""".format(userId, newDescription)
コード例 #4
0
def follow_user_topics():
    """
  This function is used to update the database to include following a user's
    topics.
  :return: Display information about the action.
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get the info from the json file sent with the request
        data = request.get_json()

        try:
            userId = data['userId']
            followingId = data['followingId']
            topicsSelected = data['topicsSelected']

        except KeyError:
            return invalid_json_format_string

        db.updateFollow(userId, followingId, topics=topicsSelected)

    except Exception as e:
        log(str(e))

    return """
  Followed a user's topics!
  userId: {}
  followingId: {}
  topicsSelected: {}
  """.format(userId, followingId, topicsSelected)
コード例 #5
0
def validate_email():
    """
      This function is used to validate a given user's email.
      :return: Return a boolean that determines validation
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get the info from the json file sent with the request
        data = request.get_json()

        try:
            email = data['email']  # The user ID requesting a new follow
        except KeyError:
            return invalid_json_format_string

        db.validateEmail(email)

    except Exception as e:
        log(str(e))

    return """
  Email successfully validated!
    email: {}
  """.format(email)
コード例 #6
0
def dm_user():
    """
  This function is used to send a DM to the database
  :return: Display information message about the action.
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get the info from the json file sent with the request
        data = request.get_json()

        try:
            senderId = data['senderId']
            receiverId = data['receiverId']
            message = data['Message']
        except KeyError:
            return invalid_json_format_string

        db.newDM(senderId, receiverId, message)

    except Exception as e:
        log(str(e))

    return """
DM Sent!
  senderId: {}
  receiverId: {}
  message: {}
""".format(senderId, receiverId, message)
コード例 #7
0
def unfollow_user():
    """
  This function is used to unfollow a user.
  :return: Display information about the action.
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get the info from the json file sent with the request
        data = request.get_json()

        try:
            userId = data['userId']
            followingId = data['followingId']
        except KeyError:
            log(invalid_json_format_string)
            return invalid_json_format_string

        db.unfollowUser(userId, followingId)
        log("Unfollowed User")
    except Exception as e:
        log(str(e))
        log(traceback.format_exception(Exception, e, None))
        return "Error"

    return """
Unfollowed User!
  userId: {}
  followingId: {}
""".format(userId, followingId)
コード例 #8
0
def unlike_post():
    """
  This function takes user and post Id and subtracts to the like
  counter in the database
  :return: Returns that the post was successfully unliked
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        data = request.get_json()

        try:
            userId = data['userId']
            postId = data['postId']
        except KeyError:
            return invalid_json_format_string

        db.unlike(userId, postId)

    except Exception as e:
        log(str(e))

    return """
Unliked!
  userId: {}
  postId: {}
""".format(userId, postId)
コード例 #9
0
def follow_new_user():
    """
  This function is used to follow a new user.
  :return: Display information about the update.
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get the info from the json file sent with the request
        data = request.get_json()

        try:
            userId = data['userId']
            followingId = data['followingId']
            topics = data['topics'] = "G"
        except KeyError:
            return invalid_json_format_string

        db.updateFollow(userId, followingId)
        log("Followed new user")
    except Exception as e:
        log(str(e))
        log(traceback.format_exception(Exception, e, None))
        return "Error"

    return """
Followed a new user!
  userId: {}
  followingId: {}
""".format(userId, followingId)
コード例 #10
0
def delete_user():
    """
  This function is called in order to delete a user.
  :return: Display information about deleted user
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get the info from the json file sent with the request
        data = request.get_json()

        try:
            userId = data['userId']
        except KeyError:
            log(invalid_json_format_string)
            return invalid_json_format_string

        db.deleteUser(userId)
    except Exception as e:
        log(str(e))
        return "Error"

    log("Deleted User")
    return """
Deleted User!
  userId: {}
""".format(userId)
コード例 #11
0
def add_user_topic():
    """
  This function is used to add a new topic to the user's profile.
  :return: Display information about the function call.
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get the info from the json file sent with the request
        data = request.get_json()

        try:
            userId = data['userId']
            newTopic = data['newTopic']
        except KeyError:
            log(invalid_json_format_string)
            return invalid_json_format_string

        db.newUserTopic(userId, newTopic)
        log("Added new user topic")
    except Exception as e:
        log(str(e))
        return "Error"

    return """
Added a new Topic!
  userId: {}
  newTopic: {}
""".format(userId, newTopic)
コード例 #12
0
def update_password():
    """
  This function is used to update the database with new password info.
  :return: Information about the update
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get the info from the json file sent with the request
        data = request.get_json()

        try:
            userId = data['userId']
            newPassword = data['newPassword']
        except KeyError:
            log(invalid_json_format_string)
            return invalid_json_format_string

        db.updatePassword(userId, newPassword)
        log("Updated password")
    except Exception as e:
        log(str(e))
        return "Error"

    return """
Updated Password!
  userId: {}
  newPassword: {}
""".format(userId, newPassword)
コード例 #13
0
def delete_post():
    """
  This function is used to delete a post from the database.
  :return: Display information about the action.
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get the info from the json file sent with the request
        data = request.get_json()

        try:
            postId = data['postId']
        except KeyError:
            return invalid_json_format_string

        db.deletePost(postId)
    except Exception as e:
        log(str(e))

    return """
Deleted Post!
  postId: {}
""".format(postId)
コード例 #14
0
def update_common_name():
    """
  This function is used to update a user's common name in the database.
  :return: Display information about about the call.
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))
    try:
        # Get the info from the json file sent with the request
        data = request.get_json()

        try:
            userId = data['userId']
            newCommonName = data['newCommonName']
        except KeyError:
            log(invalid_json_format_string)
            return invalid_json_format_string

        #  Push the info to the database
        db.updateCommonName(userId, newCommonName)
        log("Updated common name")
    except Exception as e:
        log(str(e))
        return "Error"

    return """
Updated Users Common Name!
  userID: {}
  newCommonName: {}
""".format(userId, newCommonName)
コード例 #15
0
def get_user():
    """
  This function is used to get a user's profile information.
  :return:
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        data = request.get_json()

        try:
            userId = data['userId']
        except KeyError:
            log(invalid_json_format_string)
            return invalid_json_format_string

        try:
            val = db.getUser(userId)
        except TypeError:
            log("Invalid User Id")
            return "Invalid User Id"

        log("Got User")
        return val
    except Exception as e:
        log(str(e))
        return "error"
コード例 #16
0
def get_user_posts():
    """
  This function is used to get all of the posts of the specific user.
  :return: Display information about the posts.
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get the info from the json file sent with the request
        data = request.get_json()

        try:
            userId = data['userId']
        except KeyError:
            log(invalid_json_format_string)
            return invalid_json_format_string

        val = db.getUserPosts(userId)
        log("Got user posts")
        return val
    except Exception as e:
        log(str(e))
        return "Error"
コード例 #17
0
def get_id_from_email():
    """
  This function is used to determine a user's Id based on
  a given email.
  :return: Return's the userId of the given email user.
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get the info from the json file sent with the request
        data = request.get_json()

        try:
            email = data['email']
        except KeyError:
            return invalid_json_format_string

        userId = db.getUserId(email)
    except Exception as e:
        log(str(e))

    return """
   Retrieved UserId from given email!
   userId: {}
   """.format(userId)
コード例 #18
0
def clearDMs():
    """
  This function wipes the database of any unused dms
  :return: Returns that the dms were successfully wiped
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        db.clearDMs()
    except Exception as e:
        log(str(e))
        return "DM Clear Error"

    return "DMs successfully cleared"
コード例 #19
0
def validate_login():
    """
  This function is used to validate login information from the
    database.
  :return: -1 if no user exists, if the user exists it returns the userId
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get the info from the json file sent with POST request
        data = request.get_json()

        try:
            username = data['username']
            password = data['password']
        except KeyError:
            log(invalid_json_format_string)
            return invalid_json_format_string

        val = str(db.validateLogin(username, password)) + "\n"
        log("Validated User")
        return val
    except Exception as e:
        log(str(e))
        return "Error"
コード例 #20
0
def create_user():
    """
  This function is used to create a new user and push it to the database. In
    order to use this function, make a POST request to function url above and
    send a json file with the appropriate information.
  :return: Display information about the newly created user.
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        #  Get the from the json file sent with the request
        data = request.get_json()

        try:
            username = data['username']
            password = data['password']
            commonName = data['commonName']
            email = data['email']
            description = data['description']
        except KeyError:
            log(invalid_json_format_string)
            return invalid_json_format_string

        #  Push the info to the database
        db.newUser(username, password, commonName, email, description)
        log("Created new user")
    except Exception as e:
        log(str(e))
        return "Error"

    return '''
    Created User!
      username: {}
      commonName: {}
      email: {}
      description: {}
    '''.format(username, commonName, email, description)
コード例 #21
0
def deleteDMs():
    """
  This function deletes the dms for a particular user
  :return: Returns that the dms were successfully deleted.
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        data = request.get_json()

        try:
            userId = data['userId']
            receiverId = data['receiverId']
        except KeyError:
            return invalid_json_format_string

        db.deleteDMs(userId, receiverId)
    except Exception as e:
        log(str(e))

    return """
コード例 #22
0
def retweet():
    """
  This function retweets a post and adds it to the database
  :return: Returns that the post was successfully retweeted
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        data = request.get_json()

        try:
            userId = data['userId']
            postId = data['postId']
        except KeyError:
            return invalid_json_format_string

        db.retweet(userId, postId)
    except Exception as e:
        log(str(e))

    return """
コード例 #23
0
def get_all_posts():
    """
  This function is used to get all of the posts from all of the topics from
    the database.
  :return: Display Information about the action.
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        val = db.getAllPosts()
    except Exception as e:
        log(str(e))

    #return val
    return Response(val, mimetype='application/json')
コード例 #24
0
def get_all_topic_posts():
    """
  This function is used to retrieve all of the posts of a certain topic
    from the database.
  :return: Display information about the action.
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get the info from the json file sent with the request
        data = request.get_json()

        try:
            topic = data['topic']
        except KeyError:
            return invalid_json_format_string
    except Exception as e:
        log(str(e))

    return db.getAllTopicPosts(topic)
コード例 #25
0
def get_DMList():
    """
  This function is used to get a list of dms from the database
  :return: Returns the associated userId and a list of DMs
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        # Get info from json file
        data = request.get_json()

        try:
            userID = data['userId']
        except KeyError:
            return invalid_json_format_string

        dmList = db.getDMList(userID)
    except Exception as e:
        log(str(e))

    return dmList
コード例 #26
0
def get_DMConvo():
    """
  This function gets a dm conversation between two users
  :return: Returns the conversation between the two users
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        data = request.get_json()

        try:
            userId = data['userId']
            receiverId = data['receiverId']
        except KeyError:
            return invalid_json_format_string

        convo = db.getDMConvo(userId, receiverId)
    except Exception as e:
        log(str(e))

    return convo
コード例 #27
0
def get_user_topics():
    """
  This function is used to retrieve the user posts from the database.
  :return: List of user topics
  """

    log("Request - {}".format(
        inspect.getframeinfo(inspect.currentframe()).function))

    try:
        data = request.get_json()

        try:
            userId = data['userId']
        except KeyError:
            log(invalid_json_format_string)
            return invalid_json_format_string

        val = db.getUserTopics(userId)
        log("Got User Topics")
        return val
    except Exception as e:
        log(str(e))
        return "Error"
コード例 #28
0
ファイル: 307test.py プロジェクト: cohenchris/twistter-team25
#time.sleep(1.5)
#d.newPost(1, "Title 3", "Post 3", "Gaming,Entertainment")
#time.sleep(1.5)
#d.newPost(2, "Title 4", "Post 4", "Gaming")
#time.sleep(1.5)
#d.newPost(2, "Title 5", "Post 5", "Sports,News")
#time.sleep(1.5)
#d.newPost(2, "Title 6", "Post 6", "Gaming,Entertainment")
#time.sleep(1.5)
#d.newPost(3, "Title 7", "Post 7", "Gaming")
#time.sleep(1.5)
#d.newPost(3, "Title 8", "Post 8", "Sports,News")
#time.sleep(1.5)
#d.newPost(3, "Title 9", "Post 9", "Gaming,Entertainment")
#time.sleep(1.5)
d.newPost(1, "work?", "idk", "Gaming")

#print(d.getAllPosts())

#print(d.getAllTopicPosts("Sports"))

#print(d.getUserPosts(1))

#d.newFollow(1, 2, "Gaming")
#d.newFollow(1, 3, "News")
#print(d.getUserTimeline(1))

#d.newFollow(2, 3, "All")
#print(d.getUserTimeline(2))

#d.unfollowUser(2, 3)