From 880909a0ab6504d1cdd964fdf93691dd1fe8d4cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Sun, 4 Dec 2022 19:37:58 +0100 Subject: [PATCH] Add favicon, /all has GET page for new feeds, and a base.html template --- discord_rss_bot/main.py | 27 ++++++- discord_rss_bot/static/favicon.ico | Bin 0 -> 4286 bytes discord_rss_bot/templates/add.html | 24 ++++++ discord_rss_bot/templates/base.html | 24 ++++++ discord_rss_bot/templates/feed.html | 57 ++++++-------- discord_rss_bot/templates/index.html | 114 +++++++++++---------------- 6 files changed, 143 insertions(+), 103 deletions(-) create mode 100644 discord_rss_bot/static/favicon.ico create mode 100644 discord_rss_bot/templates/add.html create mode 100644 discord_rss_bot/templates/base.html diff --git a/discord_rss_bot/main.py b/discord_rss_bot/main.py index abcf83e..21baaed 100644 --- a/discord_rss_bot/main.py +++ b/discord_rss_bot/main.py @@ -1,11 +1,11 @@ import enum import sys +from functools import cache import uvicorn from apscheduler.schedulers.background import BackgroundScheduler from fastapi import FastAPI, Form, Request -from fastapi.responses import HTMLResponse -from fastapi.staticfiles import StaticFiles +from fastapi.responses import FileResponse, HTMLResponse from fastapi.templating import Jinja2Templates 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 app = FastAPI() -app.mount("/static", StaticFiles(directory="static"), name="static") 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) def check_feed(request: Request, feed_url: str = Form()): """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} +@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__": uvicorn.run("main:app", log_level="debug") diff --git a/discord_rss_bot/static/favicon.ico b/discord_rss_bot/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..9e57c4bb8510fb9ff4db1d0b3d479eb47f89fe1b GIT binary patch literal 4286 zcmeI0>x)-K7{^clfvxs=VQJO)xM%t*kHPbNnX)O8W&2{8*%nE|@<3R3_tiJ~GHGKZbH0kD@yl46 zbey_5lKyjiv-i>WeVP7QBuz@Q^cUBLckyv~qBq#<4<-^Oa;F`;n8^!k!h#(hnd{5$ zpVK>gnC#VW*0I;q%L2LZM^>OO+7lbQx|r@9drfW)C5Q{h%*XcjL>^Y%*pDq9TM$V5 zuSNWAM-ss<;6Jk}kSn)}__KCJ#vd-GI|qNsw-vxuf)kfB8MY|*1AZQ(_W1pFk^fRX zYvbmn^`ZDtryi+powl_${yU#LhdPhTk7rXEqCT~;IamGdwn+UoxivEQ#M+xXihOQ{ zB4gG6$migy#IAv2P*Ghipo7}R#pZaMe_`_}ZtD5aA$$~Awwd3oW8yEg8>IKHS1BpDO zanIg?@AOaf7)`%{|IywBV*1tpNQ%Q=cZrESEp2;g8<$7VG$JJlopDAwiHBD?@)WSsv>h8{? zi5xhW%HSZmh% zxomT=sXfo?neOD9m1FR{!0;ZVdCVHM96rd#oct!okgptTV4uF4$+&gh%XN#*h`rFy zb}(6|rc&3wIFa6!-{8_ZRPS*g7T*aj@2<>wxA1l#_qjv4$GA)2U9PD)s+hZA|LN5D z2|INKr_vsD=C1igYbPk)Rj!f9_ zWsSKH)SpZAjq#S|{sgT#qgDjwT@3x-z;$J`H5DA}K?nDr*44$lKfm{y(No*m{{#G2 F<6r61=e_^{ literal 0 HcmV?d00001 diff --git a/discord_rss_bot/templates/add.html b/discord_rss_bot/templates/add.html new file mode 100644 index 0000000..54d13a8 --- /dev/null +++ b/discord_rss_bot/templates/add.html @@ -0,0 +1,24 @@ +{% extends "base.html" %} +{% block title %}Index{% endblock %} +{% block content %} +
+ + +
+ + +
+ +
+ +
+
+{% endblock %} \ No newline at end of file diff --git a/discord_rss_bot/templates/base.html b/discord_rss_bot/templates/base.html new file mode 100644 index 0000000..7c5b3e3 --- /dev/null +++ b/discord_rss_bot/templates/base.html @@ -0,0 +1,24 @@ + + + + {% block head %} + + + + RSS - {% block title %}{% endblock %} + {% endblock %} + + + +
{% block content %}{% endblock %}
+
+ {% block footer %} + RSS Bot by TheLovinator1 + {% endblock %} +
+ + \ No newline at end of file diff --git a/discord_rss_bot/templates/feed.html b/discord_rss_bot/templates/feed.html index fe0fb11..31db085 100644 --- a/discord_rss_bot/templates/feed.html +++ b/discord_rss_bot/templates/feed.html @@ -1,33 +1,28 @@ - - - - - Feed - - -URL: {{ feed.url }}
-Title: {{ feed.title }}
-Updated: {{ feed.updated }}
-Link: {{ feed.link }}
-Author: {{ feed.author }}
-Subtitle: {{ feed.subtitle }}
-Version: {{ feed.version }}
-User title: {{ feed.user_title }}
-Added on: {{ feed.added }}
-Last update: {{ feed.last_update }}
-Last exception: {{ feed.last_exception }}
-Updates enabled: {{ feed.updates_enabled }}
+{% extends "base.html" %} +{% block title %}Feed{% endblock %} +{% block content %} + URL: {{ feed.url }}
+ Title: {{ feed.title }}
+ Updated: {{ feed.updated }}
+ Link: {{ feed.link }}
+ Author: {{ feed.author }}
+ Subtitle: {{ feed.subtitle }}
+ Version: {{ feed.version }}
+ User title: {{ feed.user_title }}
+ Added on: {{ feed.added }}
+ Last update: {{ feed.last_update }}
+ Last exception: {{ feed.last_exception }}
+ Updates enabled: {{ feed.updates_enabled }}
-
- -
+
+ +
-
- -
- - \ No newline at end of file +
+ +
+{% endblock %} \ No newline at end of file diff --git a/discord_rss_bot/templates/index.html b/discord_rss_bot/templates/index.html index 56303ab..c445852 100644 --- a/discord_rss_bot/templates/index.html +++ b/discord_rss_bot/templates/index.html @@ -1,73 +1,49 @@ - - - - - Index - - - - - -
- - - - -
- - -{% for tag in tags %} - - {{ tag }} - -{% endfor %} -
    - - {% if feeds %} - {% for feed in feeds %} -
    - -
    - {% endfor %} - {% else %} -

    No feeds yet

    - {% endif %} -
+{% extends "base.html" %} +{% block title %}Index{% endblock %} +{% block content %} + + {% for tag in tags %} + {{ tag }} + {% endfor %} +
    + + {% if feeds %} + {% for feed in feeds %} +
    + +
    + {% endfor %} + {% else %} +

    No feeds yet

    + {% endif %} +
- -
-
    -
  • -

    Feed stats:

    -

    Total: {{ feed_count.total }} feeds

    -

    Broken: {{ feed_count.broken }} feeds

    -

    Enabled: {{ feed_count.updates_enabled }} feeds

    -
  • -
- -
    -
  • -

    Feed entries:

    -

    Total: {{ entry_count.total }} entries

    -

    Read: {{ entry_count.read }} entries

    -

    Important: {{ entry_count.important }} entries

    -

    Has enclosures: {{ entry_count.has_enclosures }} entries

    -

    1 Month: {{ entry_count.averages[0]|round(2) }} entries per day

    -

    3 Months: {{ entry_count.averages[1]|round(2) }} entries per day

    -

    12 Months: {{ entry_count.averages[2]|round(2) }} entries per day

    + +
    +
      +
    • +

      Feed stats:

      +

      Total: {{ feed_count.total }} feeds

      +

      Broken: {{ feed_count.broken }} feeds

      +

      Enabled: {{ feed_count.updates_enabled }} feeds

      +
    • +
    + +
      +
    • +

      Feed entries:

      +

      Total: {{ entry_count.total }} entries

      +

      Read: {{ entry_count.read }} entries

      +

      Important: {{ entry_count.important }} entries

      +

      Has enclosures: {{ entry_count.has_enclosures }} entries

      +

      1 Month: {{ entry_count.averages[0]|round(2) }} entries per day

      +

      3 Months: {{ entry_count.averages[1]|round(2) }} entries per day

      +

      12 Months: {{ entry_count.averages[2]|round(2) }} entries per day

      -
    • -
    +
  • +
- - \ No newline at end of file +{% endblock %} \ No newline at end of file