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,10 +1,6 @@
<!DOCTYPE html> {% extends "base.html" %}
<html lang="en"> {% block title %}Feed{% endblock %}
<head> {% block content %}
<meta charset="UTF-8">
<title>Feed</title>
</head>
<body>
URL: {{ feed.url }} <br> URL: {{ feed.url }} <br>
Title: {{ feed.title }} <br> Title: {{ feed.title }} <br>
Updated: {{ feed.updated }} <br> Updated: {{ feed.updated }} <br>
@ -29,5 +25,4 @@ Updates enabled: {{ feed.updates_enabled }} <br>
Remove feed. Remove feed.
</button> </button>
</form> </form>
</body> {% endblock %}
</html>

View File

@ -1,32 +1,9 @@
<!DOCTYPE html> {% extends "base.html" %}
<html lang="en"> {% block title %}Index{% endblock %}
<head> {% block content %}
<meta charset="UTF-8">
<title>Index</title>
<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 --> <!-- List all feeds -->
{% for tag in tags %} {% for tag in tags %}
{{ tag }} {{ tag }}
{% endfor %} {% endfor %}
<ul> <ul>
<!-- Check if any feeds --> <!-- Check if any feeds -->
@ -69,5 +46,4 @@
</li> </li>
</ul> </ul>
</body> {% endblock %}
</html>