Add favicon, /all has GET page for new feeds, and a base.html template

This commit is contained in:
2022-12-04 19:37:58 +01:00
parent c2645effdb
commit 880909a0ab
6 changed files with 143 additions and 103 deletions

View File

@ -1,11 +1,11 @@
import enum import enum
import sys import sys
from functools import cache
import uvicorn import uvicorn
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
from fastapi import FastAPI, Form, Request from fastapi import FastAPI, Form, Request
from fastapi.responses import HTMLResponse from fastapi.responses import FileResponse, HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates from fastapi.templating import Jinja2Templates
from reader import FeedExistsError from reader import FeedExistsError
@ -13,10 +13,16 @@ from discord_rss_bot.feeds import _check_feed
from discord_rss_bot.settings import logger, read_settings_file, reader from discord_rss_bot.settings import logger, read_settings_file, reader
app = FastAPI() app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates") templates = Jinja2Templates(directory="templates")
@cache
@app.get("/favicon.ico", include_in_schema=False)
async def favicon():
"""Return favicon."""
return FileResponse('static/favicon.ico')
@app.post("/check", response_class=HTMLResponse) @app.post("/check", response_class=HTMLResponse)
def check_feed(request: Request, feed_url: str = Form()): def check_feed(request: Request, feed_url: str = Form()):
"""Check all feeds""" """Check all feeds"""
@ -178,5 +184,20 @@ async def create_feed(feed_url: str = Form(), webhook_dropdown: str = Form()):
return {"feed_url": str(feed_url), "status": "added", "webhook": webhook_url} return {"feed_url": str(feed_url), "status": "added", "webhook": webhook_url}
@app.get("/add", response_class=HTMLResponse)
def get_add(request: Request):
"""
This is the root of the website.
Args:
request:
Returns:
HTMLResponse: The HTML response.
"""
context = make_context_index(request)
return templates.TemplateResponse("add.html", context)
if __name__ == "__main__": if __name__ == "__main__":
uvicorn.run("main:app", log_level="debug") uvicorn.run("main:app", log_level="debug")

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -0,0 +1,24 @@
{% extends "base.html" %}
{% block title %}Index{% endblock %}
{% block content %}
<form action="/add" method="post">
<label>
<input type="text" name="feed_url" placeholder="Feed URL" class="form-control" aria-label="Feed url">
</label>
<div class="input-group mb-3">
<label for="webhook_dropdown" class="input-group-text">Webhook</label>
<select class="form-select" aria-label="Default webhook" id="webhook_dropdown"
name="webhook_dropdown">
<option selected>Choose...</option>
{% for hook in webhooks %}
<option value="{{ hook.name }}">{{ hook.name }}</option>
{% endfor %}
</select>
</div>
<div class="input-group mb-3">
<input type="submit" value="Add feed">
</div>
</form>
{% endblock %}

View File

@ -0,0 +1,24 @@
<!doctype html>
<html lang="en">
<head>
{% block head %}
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"
crossorigin="anonymous">
<title>RSS - {% block title %}{% endblock %}</title>
{% endblock %}
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4"
crossorigin="anonymous"></script>
<div id="content">{% block content %}{% endblock %}</div>
<footer>
{% block footer %}
<a href="https://github.com/TheLovinator1/discord-rss-bot">RSS Bot</a> by TheLovinator1
{% endblock %}
</footer>
</body>
</html>

View File

@ -1,33 +1,28 @@
<!DOCTYPE html> {% extends "base.html" %}
<html lang="en"> {% block title %}Feed{% endblock %}
<head> {% block content %}
<meta charset="UTF-8"> URL: {{ feed.url }} <br>
<title>Feed</title> Title: {{ feed.title }} <br>
</head> Updated: {{ feed.updated }} <br>
<body> Link: {{ feed.link }} <br>
URL: {{ feed.url }} <br> Author: {{ feed.author }} <br>
Title: {{ feed.title }} <br> Subtitle: {{ feed.subtitle }} <br>
Updated: {{ feed.updated }} <br> Version: {{ feed.version }} <br>
Link: {{ feed.link }} <br> User title: {{ feed.user_title }} <br>
Author: {{ feed.author }} <br> Added on: {{ feed.added }} <br>
Subtitle: {{ feed.subtitle }} <br> Last update: {{ feed.last_update }} <br>
Version: {{ feed.version }} <br> Last exception: {{ feed.last_exception }} <br>
User title: {{ feed.user_title }} <br> Updates enabled: {{ feed.updates_enabled }} <br>
Added on: {{ feed.added }} <br>
Last update: {{ feed.last_update }} <br>
Last exception: {{ feed.last_exception }} <br>
Updates enabled: {{ feed.updates_enabled }} <br>
<form action="/check" method="post"> <form action="/check" method="post">
<button type="submit" name="feed_url" value="{{ feed.url }}"> <button type="submit" name="feed_url" value="{{ feed.url }}">
Send new entries to Discord. Send new entries to Discord.
</button> </button>
</form> </form>
<form action="/remove" method="post"> <form action="/remove" method="post">
<button type="submit" name="feed_url" value="{{ feed.url }}"> <button type="submit" name="feed_url" value="{{ feed.url }}">
Remove feed. Remove feed.
</button> </button>
</form> </form>
</body> {% endblock %}
</html>

View File

@ -1,34 +1,11 @@
<!DOCTYPE html> {% extends "base.html" %}
<html lang="en"> {% block title %}Index{% endblock %}
<head> {% block content %}
<meta charset="UTF-8"> <!-- List all feeds -->
<title>Index</title> {% for tag in tags %}
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<!-- Create a new feed -->
<form action="/add" method="post">
<label>
<input type="text" name="feed_url" placeholder="Feed URL">
</label>
<label for="webhook_dropdown">Choose:</label>
<select id="webhook_dropdown" name="webhook_dropdown">
{% for hook in webhooks %}
<!-- {{ hook.name }} {{ hook.value }} -->
<option value="{{ hook.name }}">{{ hook.name }}</option>
{% endfor %}
</select>
<input type="submit" value="Add feed">
</form>
<!-- List all feeds -->
{% for tag in tags %}
{{ tag }} {{ tag }}
{% endfor %}
{% endfor %} <ul>
<ul>
<!-- Check if any feeds --> <!-- Check if any feeds -->
{% if feeds %} {% if feeds %}
{% for feed in feeds %} {% for feed in feeds %}
@ -41,21 +18,21 @@
{% else %} {% else %}
<p>No feeds yet</p> <p>No feeds yet</p>
{% endif %} {% endif %}
</ul> </ul>
<!-- Feed stats --> <!-- Feed stats -->
<hr> <hr>
<ul> <ul>
<li> <li>
<p>Feed stats:</p> <p>Feed stats:</p>
<p>Total: {{ feed_count.total }} feeds</p> <p>Total: {{ feed_count.total }} feeds</p>
<p>Broken: {{ feed_count.broken }} feeds</p> <p>Broken: {{ feed_count.broken }} feeds</p>
<p>Enabled: {{ feed_count.updates_enabled }} feeds</p> <p>Enabled: {{ feed_count.updates_enabled }} feeds</p>
</li> </li>
</ul> </ul>
<!-- Feed entries stats --> <!-- Feed entries stats -->
<ul> <ul>
<li> <li>
<p>Feed entries:</p> <p>Feed entries:</p>
<p>Total: {{ entry_count.total }} entries</p> <p>Total: {{ entry_count.total }} entries</p>
@ -67,7 +44,6 @@
<p>12 Months: {{ entry_count.averages[2]|round(2) }} entries per day</p> <p>12 Months: {{ entry_count.averages[2]|round(2) }} entries per day</p>
</li> </li>
</ul> </ul>
</body> {% endblock %}
</html>