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 zcmZQzU}RuqP*4ET3Jfa*7#PGD7#K7d7#I{77#JKFAmR)lAi%(&tOvm$E(j~NeE&a+ z2Ui#{Xcu{um7rT-@$5i zyT1P~-}38!>u!X6$bz3>Ib?H?*&u&|>|T84&;Or){=>ob7ythI&H0HE4(jdS|L?!^ z7p?}xIC$spe~>uHpSF{K{D1o4A4nLE`wsjDhbyw3$ZSw}rLX$=|Hp5*7C2+ml|TR0 z+92@&3Jb%YAOEjBN40;$cach1lM@4um%Kk*R6e;{)r7ytbK{TJN%|Ns8`|37a%Vf*X0BWXft z|9|q~-~T#Y-~WT+2xNZy9#nV!`t$#P`l?^x@CBu{s;#KzeEIqRf9QgrV0mOeBeOx_ zW;X>hTtWV**zyY;{~$Hy{XhO+Mhp7~@BaO_nfwE+24v=n^GFHk|Ns9F-~Ib;|PPkl#Ui`Vap8{|`0j|1UZ7=f83bB(IwF{{Y7q zQtx>Q0kRiHr>*+=|LI3GkN^Mwf8psr|5aKcX+yK)`~RIcP{aQ1*MI*( z=@sODWb^T{LH2_D4RW(d-;e*@`+olinS<;n5F3;SL1_l2HhIO*|Dd!6l7rzL*Z=(2 zXouuoe0IX*Kz;$Gbx|3S^_V547r`u9I}>CgWle}TftsQ1VJ;}1|3 ze*gU+o-bhLsp zy3^@|#0@TcVd9{$2AP3o6$ba#>wo_fmqW^Okli467p(vF|I-gtrJ(XDdI|nK53?IY z6SDv7&;S3|Ui|alWjZ7u!|YC7`SU+0E|6^prPAp~e}l_oklDmwZ1#il`I|5Q{%^hZ z2kd81IRNr6DBM9|4)Qm;-5_@yzWet-DBXh85o0$<4anSv9lyb42Phq_I{)W??Y3Y4 zy=MIY*J~j6f&2`jL1}H$;olfx4ze3mZh6l70Zx}7b4kJ4oj?AA%+~6F?G{km0hISabttGF1JxxUv(d{`n7yDha`gURa6Ey+i4^;g z)q?yCs%xHo{0DA3fa*O^I)>SUjRxhpIVXPq2ZawPo{-HWl?@7OPe`w1@lDe*VVogn)`ZAo;ykoh409=P-Of8M%Z|Mj{dZDg2!N@7-!^W~?1 z;Bp;QHiFtPTAdJkL3xo + + +
+ + +
+ +
+ +
+ +{% 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