Show feeds that has no corresponding webhook
This commit is contained in:
@ -1,14 +1,24 @@
|
|||||||
import urllib.parse
|
import urllib.parse
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Iterable
|
from typing import Dict, Iterable
|
||||||
|
|
||||||
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, HTTPException, Request
|
||||||
from fastapi.responses import HTMLResponse
|
from fastapi.responses import HTMLResponse
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
from reader import Entry, EntryCounts, EntrySearchCounts, EntrySearchResult, Feed, FeedCounts, Reader, TagNotFoundError
|
from reader import (
|
||||||
|
Entry,
|
||||||
|
EntryCounts,
|
||||||
|
EntrySearchCounts,
|
||||||
|
EntrySearchResult,
|
||||||
|
Feed,
|
||||||
|
FeedCounts,
|
||||||
|
FeedNotFoundError,
|
||||||
|
Reader,
|
||||||
|
TagNotFoundError,
|
||||||
|
)
|
||||||
from starlette.responses import RedirectResponse
|
from starlette.responses import RedirectResponse
|
||||||
|
|
||||||
from discord_rss_bot import settings
|
from discord_rss_bot import settings
|
||||||
@ -650,21 +660,27 @@ def make_context_index(request: Request):
|
|||||||
"""
|
"""
|
||||||
# Get webhooks name and url from the database.
|
# Get webhooks name and url from the database.
|
||||||
try:
|
try:
|
||||||
hooks = reader.get_tag((), "webhooks")
|
hooks: list[dict] = reader.get_tag((), "webhooks")
|
||||||
except TagNotFoundError:
|
except TagNotFoundError:
|
||||||
hooks = []
|
hooks = []
|
||||||
|
|
||||||
feed_list = []
|
feed_list = []
|
||||||
broken_feeds = []
|
broken_feeds = []
|
||||||
|
feeds_without_corresponding_webhook = []
|
||||||
|
|
||||||
feeds: Iterable[Feed] = reader.get_feeds()
|
feeds: Iterable[Feed] = reader.get_feeds()
|
||||||
for feed in feeds:
|
for feed in feeds:
|
||||||
try:
|
try:
|
||||||
hook = reader.get_tag(feed.url, "webhook")
|
webhook = reader.get_tag(feed.url, "webhook")
|
||||||
feed_list.append({"feed": feed, "webhook": hook})
|
feed_list.append({"feed": feed, "webhook": webhook})
|
||||||
except TagNotFoundError:
|
except TagNotFoundError:
|
||||||
broken_feeds.append(feed)
|
broken_feeds.append(feed)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
webhook_list = [hook["url"] for hook in hooks]
|
||||||
|
if webhook not in webhook_list:
|
||||||
|
feeds_without_corresponding_webhook.append(feed)
|
||||||
|
|
||||||
# Sort feed_list by when the feed was added.
|
# Sort feed_list by when the feed was added.
|
||||||
feed_list.sort(key=lambda x: x["feed"].added)
|
feed_list.sort(key=lambda x: x["feed"].added)
|
||||||
|
|
||||||
@ -677,6 +693,7 @@ def make_context_index(request: Request):
|
|||||||
"entry_count": entry_count,
|
"entry_count": entry_count,
|
||||||
"webhooks": hooks,
|
"webhooks": hooks,
|
||||||
"broken_feeds": broken_feeds,
|
"broken_feeds": broken_feeds,
|
||||||
|
"feeds_without_corresponding_webhook": feeds_without_corresponding_webhook,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,5 +73,16 @@ Thanks!
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<!-- Show feeds that has no corresponding webhook -->
|
||||||
|
{% if feeds_without_corresponding_webhook %}
|
||||||
|
<div class="p-2 mb-2 border border-dark">
|
||||||
|
<ul class="list-group text-danger">
|
||||||
|
Feeds without corresponding webhook:
|
||||||
|
{% for feed in feeds_without_corresponding_webhook %}
|
||||||
|
<a class="text-muted" href="/feed?feed_url={{ feed.url|encode_url }}">{{ feed.url }}</a>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
Reference in New Issue
Block a user