Exemple #1
0
async def view(request):
    r = request.json

    if r is None:
        return json(general_response("Json not sent in. Please enter it.", {},
                                     title="No JSON"),
                    status=400)

    category = r.get("category")
    page = r.get("page")

    # We'll have a background process getting the trending
    if page is None:
        return json(general_response("No page number given", {},
                                     title="No Page Number"),
                    status=400)

    if category is None:
        return json(general_response("Page category required", {},
                                     title="No category given"),
                    status=400)

    # If the category is home, we get all posts. Some information wont be had
    # if category == "home":
    #   all_posts = list(store.query_latest({"type": "post"})) # Put a page limit of 10
    #   Get stats by post (need to get the stats of each post (votes, author information, etc))
    # else:
    #   post_by_category = list(store.query_latest({"type": "post", "tag": category}, pagination=True, page_num=page, page_size=10))
    #   Get stats by post (iterate through each)
    # Return the information here
    all_posts = list(store.query_latest({"type": "post"}))

    return json({"msg": "Return a list of post", "data": all_posts})
Exemple #2
0
async def view(request):
    r = request.json
    logger.debug("Getting a list of posts")

    if r is None:
        return json(general_response("Json not sent in. Please enter it.", {},
                                     title="No JSON"),
                    status=400)

    category = r.get("category")
    page = r.get("page")

    logger.info("{} {}".format(category, page))
    if category is None:
        return json(general_response("Page category required", {},
                                     title="No category given"),
                    status=400)

    if (page is None and category != "home"):
        return json(general_response("No page number given", {},
                                     title="No Page Number"),
                    status=400)

    logger.log("SNAKY", "Category: {} Page: {}".format(category, page))
    # If the category is home, we get all posts. Some information wont be had
    # if category == "home":
    #   all_posts = list(store.query_latest({"type": "post"})) # Put a page limit of 10
    #   Get stats by post (need to get the stats of each post (votes, author information, etc))
    # else:
    #   post_by_category = list(store.query_latest({"type": "post", "tag": category}, pagination=True, page_num=page, page_size=10))
    #   Get stats by post (iterate through each)
    # Return the information here
    all_posts = list(store.query_latest({"type": "post"}))

    return json({"msg": "Return a list of post", "data": all_posts})
Exemple #3
0
async def view(request):
    r = request.json

    if r is None:
        return json(general_response("Json not sent in. Please enter it.", {},
                                     title="No JSON"),
                    status=400)

    # all_posts = list(store.query_latest({"type": "post"}))

    transactions_base = {
        "id": 1,
        "hash": "b2iudBSLIYDjgK",
        "amount": 0.05,
        "date": 10,
        "address": 300
    }

    transactions = []
    for i in range(30):
        transactions.append(transactions_base)

    gg = {
        "transactions": {
            "incoming": transactions,
            "outgoing": transactions
        },
        "pubkey": "sahkhbw2wheusb72hdbyav"
    }

    return json({"msg": "Return a list of post", "data": gg})
Exemple #4
0
async def pview(request):
    r = request.json

    if r is None:
        return json(general_response("Json not sent in. Please enter it.", {},
                                     "JSON Not Found"),
                    status=400)

    _id = r.get("id", None)

    if _id is None:
        return json(general_response("User Id is missing. Please enter it", {},
                                     "User Id Missing"),
                    status=400)

    # Find the latest user with the given user id. If nothing is found, return that nothing was found.
    user_list = list(store.query({"type": "user", "sid": _id}))
    if len(user_list) == 0:
        return json(general_response("No user found with that id", {},
                                     "User not found"),
                    status=404)

    # Check to see if we have any account data added in yet.
    account_info = list(store.query({"type": "account", "uid": _id}))
    account_dict = {
        "type": "account",
        "uid": _id,
        "description": "",
        "pubkey": "...............",
        "timestamp": time.time()
    }
    if len(account_info) == 0:
        store.store(account_dict)
        # return json(general_response("No account information found", {}, "Account Not Found"), status=404)

    # TODO: Check for every user's post as well

    query_object = {"type": "post", "author": _id}

    user_posts = list(store.query_latest(query_object))

    return json({
        "msg": "User was found. Getting the account data too.",
        "data": user_list[0],
        "account": account_dict,
        "posts": user_posts
    })
Exemple #5
0
async def search(request):
    r = request.json

    if r is None:
        return json(general_response("Json not sent in. Please enter it.", {}),
                    status=400)

    return json({"msg": "We get the session id to see what the user has done"})
Exemple #6
0
async def follow(request, user):
    r = request.json

    if r is None:
        return json(general_response("Json not sent in. Please enter it.", {}),
                    status=400)
    return json({
        "msg":
        "Here we get the authorization code to determine what the user should do."
    })
Exemple #7
0
async def edit(request, user):
    r = request.json

    if r is None:
        return json(general_response("Json not sent in. Please enter it.", {}),
                    status=400)

    # Figure out what to change based on what we recieve
    # print(user, file=sys.stderr)
    return json({
        "msg":
        "Here we get the authorization code to determine what the user should do."
    })
Exemple #8
0
async def search(request):
    r = request.json

    if r is None:
        return json(general_response("Json not sent in. Please enter it.", {}),
                    status=400)

    return json({"msg": "We get the session id to see what the user has done"})


# @profile.route("/publish", methods=["POST"])
# @authorized()
# @inject()
# async def publish(request, user):
#     r = request.json

#     if r is None:
#         return json(general_response("Json not sent in. Please enter it.", {}), status=400)
#     # make sure post text exist
#     # Get the post-text
#     # get the get the post title
#     # create post id
#     # Store post with user-id as reference
#     # Explain to use that the post was created
#     # print(user, file=sys.stderr)
#     return json({"msg": "Here we get the authorization code to determine what the user should do."})

# @profile.route("/edit", methods=["POST"])
# @authorized()
# @inject()
# async def edit(request, user):
#     r = request.json

#     if r is None:
#         return json(general_response("Json not sent in. Please enter it.", {}), status=400)
#     # print(user, file=sys.stderr)
#     return json({"msg": "Here we get the authorization code to determine what the user should do."})

# @profile.route("/editable", methods=["POST"])
# @authorized()
# @inject()
# async def editable(request, user):
#     r = request.json

#     if r is None:
#         return json(general_response("Json not sent in. Please enter it.", {}), status=400)
#     # Get the post id
#     #
#     # print(user, file=sys.stderr)
#     return json({"msg": "Here we get the authorization code to determine what the user should do."})