-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathroutes.py
47 lines (39 loc) · 1.31 KB
/
routes.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
#!/usr/bin/python
from app import flask_app, get_dog_pics
from flask import render_template, request, redirect, url_for, jsonify
@flask_app.route("/", methods=["GET", "POST"])
def index():
# we define dog breeds so the user chooses from this list
dog_breeds = [
"affenpinscher",
"dalmatian",
"germanshepherd",
"kelpie",
"labrador",
"husky",
"otterhound",
"pitbull",
"pug",
"rottweiler",
]
# we store links in this list
pictures = []
open_file = open("url.txt", "r")
for images in open_file:
image = images.replace(",", " ")
image = image.replace('"', "")
pictures.extend(image.split())
# on form submission, the task is ran
if request.method == "POST":
if request.form["submit"] == "getDogPics":
breed_type = request.form.get("breed")
limit = request.form.get("limit")
get_dog_pics.delay(breed_type, limit)
return redirect(url_for("index"))
# an option for clearing all the links
elif request.form["submit"] == "clearDogPics":
f = open("url.txt", "w")
f.close()
return redirect(url_for("index"))
# Results
return render_template("template.html", breeds=dog_breeds, link=pictures)