
# semi random cuteness generator
# pulls redit.com/r/aww returns a random png or jpeg from the front page.
# more comments. 

from flask import Flask, redirect
import json, requests
import random


app = Flask(__name__)

def get_links():
    url = 'http://www.reddit.com/r/aww.json'
    resp = requests.get(url=url)
    f = open("aww_posts.json", 'w')
    f.write(data)
    f.close()
    data = json.loads(resp.text)
    raw_image_links = []

    for post in data['data']['children']:
        ending = post['data']['url'][-4:]
        if ending.lower() == ".jpg" or ending.lower() == ".png":
            raw_image_links.append(post['data']['url'])

    return raw_image_links

app = Flask(__name__)


@app.route('/')
def hello_world():
    links = get_links()
    print (links)
    return redirect(random.choice(links), code=302)


# semi random cuteness generator
# pulls redit.com/r/aww returns a random png or jpeg from the front page.
# more comments. 

from flask import Flask, redirect
import json, requests
import random


app = Flask(__name__)

def get_links():
    """
    url = 'http://www.reddit.com/r/aww.json'
    resp = requests.get(url=url)
    f = open("aww_posts.json", 'w')
    f.write(data)
    f.close()
    """
    f = open("aww_posts.json", 'r') 
    data = json.loads(f.read())
    f.close()
    raw_image_links = []

    for post in data['data']['children']:
        ending = post['data']['url'][-4:]
        if ending.lower() == ".jpg" or ending.lower() == ".png":
            raw_image_links.append(post['data']['url'])

    return raw_image_links

app = Flask(__name__)


@app.route('/')
def hello_world():
    links = get_links()
    print (links)
    return redirect(random.choice(links), code=302)

save data