Add files via upload
This commit is contained in:
33
pony.py
Normal file
33
pony.py
Normal file
@@ -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)
|
||||
30
templates/index.html
Normal file
30
templates/index.html
Normal file
@@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Рандом бетпони поисковик</title>
|
||||
<style>
|
||||
.container {
|
||||
max-width: 600px;
|
||||
max-height: 400px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.batpony-image {
|
||||
width: 30%;
|
||||
height: 30%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Рандом бетпони поисковик</h1>
|
||||
<content class="container">
|
||||
<img class="batpony-image" src="{{ image_url }}" alt="Random Batpony Image">
|
||||
<p>Источник: <a href="{{ view_url }}" target="_blank">{{ view_url }}</a></p>
|
||||
<p>Теги: {{ tags }}</p>
|
||||
</content>
|
||||
<footer>
|
||||
<h3>Весь контент является публичным и случайно найденным для каждого пользователя. <br /> Администрация сайта не несет ответственности за картинки.</h3>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user