from flask import Flask, render_template, jsonify
from reddit_handler import *

app = Flask(__name__)

meme_subreddits = ['izlam']


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/meme')
def one_post():
    sub = random.choice(meme_subreddits)
    re = get_posts(sub, 100)

    r = random.choice(re)

    while not is_img_link(r[1]):
        r = random.choice(re)

    return jsonify({
        'title': r[0],
        'url': r[1],
        'postLink': r[2],
        'subreddit': sub
    })


@app.route('/sample')
def sample():
    re = get_posts(random.choice(meme_subreddits), 100)

    r = random.choice(re)

    while not is_img_link(r[1]):
        r = random.choice(re)

    return render_template('sample.html', title=r[0], img_url=r[1], shortlink=r[2])


@app.route('/test')
def test():
    re = get_posts(random.choice(meme_subreddits), 100)

    return render_template('test.html', re=re)


@app.route('/<something>')
def not_found(something):
    return render_template('not_found.html')

[((4, 6, 4, 21), 'flask.Flask', 'Flask', ({(4, 12, 4, 20): '__name__'}, {}), '(__name__)', False, 'from flask import Flask, render_template, jsonify\n'), ((11, 11, 11, 40), 'flask.render_template', 'render_template', ({(11, 27, 11, 39): '"""index.html"""'}, {}), "('index.html')", False, 'from flask import Flask, render_template, jsonify\n'), ((24, 11, 29, 6), 'flask.jsonify', 'jsonify', ({(24, 19, 29, 5): "{'title': r[0], 'url': r[1], 'postLink': r[2], 'subreddit': sub}"}, {}), "({'title': r[0], 'url': r[1], 'postLink': r[2], 'subreddit': sub})", False, 'from flask import Flask, render_template, jsonify\n'), ((41, 11, 41, 83), 'flask.render_template', 'render_template', (), '', False, 'from flask import Flask, render_template, jsonify\n'), ((48, 11, 48, 46), 'flask.render_template', 'render_template', (), '', False, 'from flask import Flask, render_template, jsonify\n'), ((53, 11, 53, 44), 'flask.render_template', 'render_template', ({(53, 27, 53, 43): '"""not_found.html"""'}, {}), "('not_found.html')", False, 'from flask import Flask, render_template, jsonify\n')]