Ejemplo n.º 1
0
def get_a_comm():
    req = request.headers
    cookie = req["cookie123"]
    user_id = gu1(cookie)
    if (user_id is None):
        return "Invalid user"
    else:
        req = request.form.to_dict()
        postid = req["postid"]
        commentid = req["commentid"]
        post = gp2(postid)
        comment = gc1(commentid)
        comment_liked = gcl1(commentid)
        comment_disliked = gcdl1(commentid)
        num_of_upvotes = len(comment_liked)
        num_of_downvotes = len(comment_disliked)
        total_like = num_of_upvotes - num_of_downvotes
        dic = {
            "post": post[0][0],
            "upvote": num_of_upvotes,
            "downvote": num_of_downvotes,
            "comment": comment[0][0],
            "post_id": postid,
            "comment_id": commentid
        }
        dump = json.dumps(dic)
        return dump
Ejemplo n.º 2
0
def get_username():
    req = request.headers
    cookie = req["cookie123"]
    user_id = gu1(cookie)
    if (user_id is None):
        return "Invaid cookie"
    else:
        return user_id
Ejemplo n.º 3
0
def get_all_comment_user():
    head = request.headers
    user_id = gu1(head["cookie123"])
    if (user_id is None):
        return "failure"
    else:
        req = request.form.to_dict()
        ans = gacbu(user_id)
        return json.dumps(ans)
Ejemplo n.º 4
0
def get_all_dislikes_user():
    head = request.headers
    user_id = gu1(head["cookie123"])
    if (user_id is None):
        return "failure"
    else:
        req = request.form.to_dict()
        C_P_disliked = gadlbu(user_id)
        C_P_disliked = json.dumps(C_P_disliked)
        return C_P_disliked
Ejemplo n.º 5
0
def check_subs():
    req = request.headers
    cookie = req["cookie123"]
    user_id = gu1(cookie)
    if (user_id is None):
        return "Invaid cookie"
    else:
        req = request.form.to_dict()
        subreddit_name = req["subreddit_name"]
        ANS = check_sub(user_id, subreddit_name)
        return ANS
Ejemplo n.º 6
0
def get_comment_post_count():
    head = request.headers
    user_id = gu1(head["cookie123"])
    if (user_id is None):
        return "failure"
    else:
        req = request.form.to_dict()
        post_id = req["post_id"]
        ANS = gcldcopbu(user_id, post_id)
        ANS = json.dumps(ANS)
        return ANS
Ejemplo n.º 7
0
def post_disliked():
    req = request.headers
    cookie = req["cookie123"]
    user_id = gu1(cookie)
    if (user_id is None):
        return "Invaid cookie"
    else:
        req = request.form.to_dict()
        comment_id = req["post_id"]
        ret = ipdl(user_id, comment_id)
        return str(ret)
Ejemplo n.º 8
0
def recv_post_cmnt():
    req = request.form.to_dict()
    postid = str(uuid1())
    created_at = datetime.now()
    content = req["post"]
    user_id = gu1(request.headers["cookie123"])
    subreddit_name = req["subreddit"]
    if (user_id is not None):
        ret = ip1(postid, content, created_at, user_id, subreddit_name)
        sendmail(s, subreddit_name, postid)
        return ret
    return "<h>Failure</h>"
Ejemplo n.º 9
0
def unsubscribe():
    req = request.headers
    cookie = req["cookie123"]
    user_id = gu1(cookie)
    if (user_id is None):
        return "Invaid cookie"
    else:
        req = request.form.to_dict()
        subreddit_name = req["subreddit_name"]
        ans = UNSUBSCRIBE(user_id, subreddit_name)
        if (ans == 1):
            return "success"
        else:
            return "ERROR"
Ejemplo n.º 10
0
def create_subreddit():
    # import pdb;pdb.set_trace()
    req = request.headers
    cookie = req["cookie123"]
    user_id = gu1(cookie)
    if (user_id is None):
        return "Invalid user"
    else:
        req1 = request.form.to_dict()
        # import pdb;pdb.set_trace()
        subreddit_name = req1["subreddit_name"]
        ret = cs1(name1=subreddit_name,
                  subreddit_created_at=datetime.now(),
                  user_id=user_id)
        return "{} created Succefully".format(subreddit_name)
Ejemplo n.º 11
0
def comment():
    req1 = request.headers
    cookie = req1["cookie123"]
    user_id = gu1(cookie)
    if (user_id is None):
        return "Invalid cookie"
    else:
        # comment_id=req["comment_id"]
        #COMMENT ID TO BE CREATED BY HASH OF PARENT ID AND TIMESTAMP
        req = request.form.to_dict()
        comment_content = req["comment_content"]
        # created_at=str(datetime.now())
        created_at = datetime.now()
        comment_id = str(uuid1())
        parent_id = req["parent_id"]
        post_id = req["post_id"]
        ret = icm(comment_id, user_id, comment_content, created_at, parent_id,
                  post_id)
        #WRITE RETURN VALUE
        return "<h>Succefully commentted</h>"