/
app.py
76 lines (59 loc) · 1.9 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import requests
import os
import json
from flask import Flask, render_template
from random import choice
from pattern.text.en import pluralize
from dotenv import load_dotenv
load_dotenv()
UNSPLASH_API_KEY = os.getenv("UNSPLASH_API_KEY")
app = Flask(__name__)
@app.route("/")
def index():
"""Display the home page for generating ideas"""
key = UNSPLASH_API_KEY
idea = ""
with open('words/base.txt') as f:
bases = f.readlines()
with open('words/noun.txt') as f:
nouns = f.readlines()
base = choice(bases)
noun = pluralize(choice(nouns).strip())
idea = f"{base} but for {noun}"
params = {
"client_id": key,
"query": noun,
}
r = requests.get("https://api.unsplash.com/photos/random/", params=params)
img = json.loads(r.content)
return render_template('index.html', idea=idea, img=img)
@app.route("/possibilities")
def word_list():
"""Display an editable list of words that can appear"""
with open('words/noun.txt') as f:
words = f.readlines()
with open('words/base.txt') as f:
bases = f.readlines()
params = {
"client_id": UNSPLASH_API_KEY,
"query": 'possibilities'
}
r = requests.get("https://api.unsplash.com/photos/random", params=params)
img = json.loads(r.content)
return render_template('word_list.html', words=words, bases=bases, img=img)
@app.route("/saved")
def saved():
"""Display the words saved by the user"""
ideas = [
"here's an idea that was saved",
"here is another",
"here is one that's really long but not too long probably",
"more ideas go here and below"
]
params = {
"client_id": UNSPLASH_API_KEY,
"query": 'saved'
}
r = requests.get("https://api.unsplash.com/photos/random", params=params)
img = json.loads(r.content)
return render_template('saved.html', ideas=ideas, img=img)