From 7948948631b5662c361bc2007c3741f6e647e012 Mon Sep 17 00:00:00 2001 From: DarkShy <30442729+DarkShyMW@users.noreply.github.com> Date: Mon, 8 Jan 2024 09:38:22 +0300 Subject: [PATCH] Add files via upload --- pony.py | 33 +++++++++++++++++++++++++++++++++ templates/index.html | 30 ++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 pony.py create mode 100644 templates/index.html diff --git a/pony.py b/pony.py new file mode 100644 index 0000000..a8e43dc --- /dev/null +++ b/pony.py @@ -0,0 +1,33 @@ +import requests +from flask import Flask, render_template +import random + +app = Flask(__name__) + +# Пишем свой API-key из https://derpibooru.org/registrations/edit +api_key = "nYTuAw8EHfHyfL6TgXPk" + +# Ищем картинки на derpi +def get_random_batpony_image(): + url = f"https://derpibooru.org/api/v1/json/search?q=batpony%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) \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..f4d16af --- /dev/null +++ b/templates/index.html @@ -0,0 +1,30 @@ + + +
+ + +Источник: {{ view_url }}
+Теги: {{ tags }}
+