Exemplo n.º 1
0
def multiple_from_sub(sub, c):

    if c >= 50:
        return jsonify({
            'status_code': 400,
            'message': 'Please ensure the count is less than 50'
        })

    requested = get_meme(sub, 100)

    random.shuffle(requested)

    memes = []
    for post in requested:
        if check_image(post["Url"]) and len(memes) != c:

            t = {
                'Title': post["Title"],
                'Url': post["Url"],
                'Upvotes': post["Upvotes"],
                'Downvotes': post["Downvotes"],
                'Redditurl': post["Redditurl"],
                'Subreddit': post["Subreddit"]
            }
            memes.append(t)

    return jsonify({'memes': memes, 'count': len(memes)})
Exemplo n.º 2
0
def random_meme():  #Random and one
    sub = random.choice(randommeme)
    r = get_meme(sub, 100)
    requsted = random.choice(r)

    while not check_image(requsted["Url"]):
        requsted = random.choice(r)

    return jsonify({
        'Title': requsted["Title"],
        'Url': requsted["Url"],
        'Upvotes': requsted["Upvotes"],
        'Downvotes': requsted["Downvotes"],
        'Redditurl': requsted["Redditurl"],
        'Subreddit': requsted["Subreddit"]
    })
Exemplo n.º 3
0
def custom_meme(sub):  #Custom and one
    try:
        r = get_meme(sub, 100)

    except:
        return jsonify({'Status_code': 404, 'Message': 'Invalid Subeddit'})

    requsted = random.choice(r)

    while not check_image(requsted["Url"]):
        count = count + 1
        requsted = random.choice(r)
        if count == 100:
            break

    return jsonify({
        'Title': requsted["Title"],
        'Url': requsted["Url"],
        'Upvotes': requsted["Upvotes"],
        'Downvotes': requsted["Downvotes"],
        'Redditurl': requsted["Redditurl"],
        'Subreddit': requsted["Subreddit"]
    })