-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpony.py
38 lines (30 loc) · 1.14 KB
/
pony.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
import requests
from flask import Flask, render_template
import random
from flask_bootstrap import Bootstrap
app = Flask(__name__)
Bootstrap(app)
# Пишем свой API-key из https://derpibooru.org/registrations/edit
api_key = "ваш_токен"
querry = 'batpony,safe,cute'
# Ищем картинки на derpi
def get_random_batpony_image():
url = f"https://derpibooru.org/api/v1/json/search?q={querry}%2Csafe&key={api_key}"
response = requests.get(url)
data = response.json()
images = data["images"]
random_image = random.choice(images)
return {
"image_url": random_image["representations"]["full"],
"view_url": random_image["view_url"],
"tags": random_image["tags"]
}
#Обрабатываем маршрут
@app.route("/")
def index():
random_batpony_image = get_random_batpony_image()
return render_template("index.html", image_url=random_batpony_image["image_url"],
view_url=random_batpony_image["view_url"],
tags=random_batpony_image["tags"])
if __name__ == "__main__":
app.run(debug=True)