Add support for changing the update interval for feeds
Some checks failed
Test and build Docker image / docker (push) Has been cancelled
Some checks failed
Test and build Docker image / docker (push) Has been cancelled
This commit is contained in:
parent
567273678e
commit
24d4d7a293
18 changed files with 803 additions and 119 deletions
|
|
@ -98,7 +98,7 @@ def extract_domain(url: str) -> str: # noqa: PLR0911
|
|||
return "Other"
|
||||
|
||||
|
||||
def send_entry_to_discord(entry: Entry, custom_reader: Reader | None = None) -> str | None: # noqa: PLR0912
|
||||
def send_entry_to_discord(entry: Entry, custom_reader: Reader | None = None) -> str | None: # noqa: C901, PLR0912
|
||||
"""Send a single entry to Discord.
|
||||
|
||||
Args:
|
||||
|
|
@ -240,7 +240,7 @@ def set_title(custom_embed: CustomEmbed, discord_embed: DiscordEmbed) -> None:
|
|||
discord_embed.set_title(embed_title) if embed_title else None
|
||||
|
||||
|
||||
def create_embed_webhook(webhook_url: str, entry: Entry) -> DiscordWebhook:
|
||||
def create_embed_webhook(webhook_url: str, entry: Entry) -> DiscordWebhook: # noqa: C901
|
||||
"""Create a webhook with an embed.
|
||||
|
||||
Args:
|
||||
|
|
@ -341,7 +341,7 @@ def set_entry_as_read(reader: Reader, entry: Entry) -> None:
|
|||
logger.exception("Error setting entry to read: %s", entry.id)
|
||||
|
||||
|
||||
def send_to_discord(custom_reader: Reader | None = None, feed: Feed | None = None, *, do_once: bool = False) -> None: # noqa: PLR0912
|
||||
def send_to_discord(custom_reader: Reader | None = None, feed: Feed | None = None, *, do_once: bool = False) -> None: # noqa: C901, PLR0912
|
||||
"""Send entries to Discord.
|
||||
|
||||
If response was not ok, we will log the error and mark the entry as unread, so it will be sent again next time.
|
||||
|
|
@ -520,7 +520,7 @@ def truncate_webhook_message(webhook_message: str) -> str:
|
|||
return webhook_message
|
||||
|
||||
|
||||
def create_feed(reader: Reader, feed_url: str, webhook_dropdown: str) -> None:
|
||||
def create_feed(reader: Reader, feed_url: str, webhook_dropdown: str) -> None: # noqa: C901
|
||||
"""Add a new feed, update it and mark every entry as read.
|
||||
|
||||
Args:
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ from pathlib import Path
|
|||
from typing import TYPE_CHECKING
|
||||
from typing import Any
|
||||
|
||||
from reader import TagNotFoundError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from reader import Reader
|
||||
|
||||
|
|
@ -66,6 +68,7 @@ _FEED_TAGS: tuple[str, ...] = (
|
|||
"regex_whitelist_summary",
|
||||
"regex_whitelist_content",
|
||||
"regex_whitelist_author",
|
||||
".reader.update",
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -178,10 +181,21 @@ def export_state(reader: Reader, backup_path: Path) -> None:
|
|||
webhooks: list[str | int | float | bool | dict[str, Any] | list[Any] | None] = list(
|
||||
reader.get_tag((), "webhooks", [])
|
||||
)
|
||||
except Exception: # noqa: BLE001
|
||||
except TagNotFoundError:
|
||||
webhooks = []
|
||||
|
||||
# Export global update interval if set
|
||||
global_update_interval: dict[str, Any] | None = None
|
||||
try:
|
||||
global_update_config = reader.get_tag((), ".reader.update", None)
|
||||
if isinstance(global_update_config, dict):
|
||||
global_update_interval = global_update_config
|
||||
except TagNotFoundError:
|
||||
pass
|
||||
|
||||
state: dict = {"feeds": feeds_state, "webhooks": webhooks}
|
||||
if global_update_interval is not None:
|
||||
state["global_update_interval"] = global_update_interval
|
||||
state_file: Path = backup_path / "state.json"
|
||||
state_file.write_text(json.dumps(state, indent=2, default=str), encoding="utf-8")
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ import contextlib
|
|||
import json
|
||||
import logging
|
||||
import re
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import Any
|
||||
|
||||
import requests
|
||||
from discord_webhook import DiscordEmbed, DiscordWebhook
|
||||
from discord_webhook import DiscordEmbed
|
||||
from discord_webhook import DiscordWebhook
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from reader import Entry
|
||||
|
|
|
|||
|
|
@ -100,6 +100,46 @@ logging.config.dictConfig(LOGGING_CONFIG)
|
|||
logger: logging.Logger = logging.getLogger(__name__)
|
||||
reader: Reader = get_reader()
|
||||
|
||||
# Time constants for relative time formatting
|
||||
SECONDS_PER_MINUTE = 60
|
||||
SECONDS_PER_HOUR = 3600
|
||||
SECONDS_PER_DAY = 86400
|
||||
|
||||
|
||||
def relative_time(dt: datetime | None) -> str:
|
||||
"""Convert a datetime to a relative time string (e.g., '2 hours ago', 'in 5 minutes').
|
||||
|
||||
Args:
|
||||
dt: The datetime to convert (should be timezone-aware).
|
||||
|
||||
Returns:
|
||||
A human-readable relative time string.
|
||||
"""
|
||||
if dt is None:
|
||||
return "Never"
|
||||
|
||||
now = datetime.now(tz=UTC)
|
||||
diff = dt - now
|
||||
seconds = int(abs(diff.total_seconds()))
|
||||
is_future = diff.total_seconds() > 0
|
||||
|
||||
# Determine the appropriate unit and value
|
||||
if seconds < SECONDS_PER_MINUTE:
|
||||
value = seconds
|
||||
unit = "s"
|
||||
elif seconds < SECONDS_PER_HOUR:
|
||||
value = seconds // SECONDS_PER_MINUTE
|
||||
unit = "m"
|
||||
elif seconds < SECONDS_PER_DAY:
|
||||
value = seconds // SECONDS_PER_HOUR
|
||||
unit = "h"
|
||||
else:
|
||||
value = seconds // SECONDS_PER_DAY
|
||||
unit = "d"
|
||||
|
||||
# Format based on future or past
|
||||
return f"in {value}{unit}" if is_future else f"{value}{unit} ago"
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI) -> AsyncGenerator[None]:
|
||||
|
|
@ -131,6 +171,7 @@ templates.env.filters["encode_url"] = lambda url: urllib.parse.quote(url) if url
|
|||
templates.env.filters["entry_is_whitelisted"] = entry_is_whitelisted
|
||||
templates.env.filters["entry_is_blacklisted"] = entry_is_blacklisted
|
||||
templates.env.filters["discord_markdown"] = markdownify
|
||||
templates.env.filters["relative_time"] = relative_time
|
||||
templates.env.globals["get_backup_path"] = get_backup_path
|
||||
|
||||
|
||||
|
|
@ -613,6 +654,102 @@ async def post_use_text(feed_url: Annotated[str, Form()]) -> RedirectResponse:
|
|||
return RedirectResponse(url=f"/feed?feed_url={urllib.parse.quote(clean_feed_url)}", status_code=303)
|
||||
|
||||
|
||||
@app.post("/set_update_interval")
|
||||
async def post_set_update_interval(
|
||||
feed_url: Annotated[str, Form()],
|
||||
interval_minutes: Annotated[int | None, Form()] = None,
|
||||
redirect_to: Annotated[str, Form()] = "",
|
||||
) -> RedirectResponse:
|
||||
"""Set the update interval for a feed.
|
||||
|
||||
Args:
|
||||
feed_url: The feed to change.
|
||||
interval_minutes: The update interval in minutes (None to reset to global default).
|
||||
redirect_to: Optional redirect URL (defaults to feed page).
|
||||
|
||||
Returns:
|
||||
RedirectResponse: Redirect to the specified page or feed page.
|
||||
"""
|
||||
clean_feed_url: str = feed_url.strip()
|
||||
|
||||
# If no interval specified, reset to global default
|
||||
if interval_minutes is None:
|
||||
try:
|
||||
reader.delete_tag(clean_feed_url, ".reader.update")
|
||||
commit_state_change(reader, f"Reset update interval to default for {clean_feed_url}")
|
||||
except TagNotFoundError:
|
||||
pass
|
||||
else:
|
||||
# Validate interval (minimum 1 minute, no maximum)
|
||||
interval_minutes = max(interval_minutes, 1)
|
||||
reader.set_tag(clean_feed_url, ".reader.update", {"interval": interval_minutes}) # pyright: ignore[reportArgumentType]
|
||||
commit_state_change(reader, f"Set update interval to {interval_minutes} minutes for {clean_feed_url}")
|
||||
|
||||
# Update the feed immediately to recalculate update_after with the new interval
|
||||
try:
|
||||
reader.update_feed(clean_feed_url)
|
||||
logger.info("Updated feed after interval change: %s", clean_feed_url)
|
||||
except Exception:
|
||||
logger.exception("Failed to update feed after interval change: %s", clean_feed_url)
|
||||
|
||||
if redirect_to:
|
||||
return RedirectResponse(url=redirect_to, status_code=303)
|
||||
return RedirectResponse(url=f"/feed?feed_url={urllib.parse.quote(clean_feed_url)}", status_code=303)
|
||||
|
||||
|
||||
@app.post("/reset_update_interval")
|
||||
async def post_reset_update_interval(
|
||||
feed_url: Annotated[str, Form()],
|
||||
redirect_to: Annotated[str, Form()] = "",
|
||||
) -> RedirectResponse:
|
||||
"""Reset the update interval for a feed to use the global default.
|
||||
|
||||
Args:
|
||||
feed_url: The feed to change.
|
||||
redirect_to: Optional redirect URL (defaults to feed page).
|
||||
|
||||
Returns:
|
||||
RedirectResponse: Redirect to the specified page or feed page.
|
||||
"""
|
||||
clean_feed_url: str = feed_url.strip()
|
||||
|
||||
try:
|
||||
reader.delete_tag(clean_feed_url, ".reader.update")
|
||||
commit_state_change(reader, f"Reset update interval to default for {clean_feed_url}")
|
||||
except TagNotFoundError:
|
||||
# Tag doesn't exist, which is fine
|
||||
pass
|
||||
|
||||
# Update the feed immediately to recalculate update_after with the new interval
|
||||
try:
|
||||
reader.update_feed(clean_feed_url)
|
||||
logger.info("Updated feed after interval reset: %s", clean_feed_url)
|
||||
except Exception:
|
||||
logger.exception("Failed to update feed after interval reset: %s", clean_feed_url)
|
||||
|
||||
if redirect_to:
|
||||
return RedirectResponse(url=redirect_to, status_code=303)
|
||||
return RedirectResponse(url=f"/feed?feed_url={urllib.parse.quote(clean_feed_url)}", status_code=303)
|
||||
|
||||
|
||||
@app.post("/set_global_update_interval")
|
||||
async def post_set_global_update_interval(interval_minutes: Annotated[int, Form()]) -> RedirectResponse:
|
||||
"""Set the global default update interval.
|
||||
|
||||
Args:
|
||||
interval_minutes: The update interval in minutes.
|
||||
|
||||
Returns:
|
||||
RedirectResponse: Redirect to the settings page.
|
||||
"""
|
||||
# Validate interval (minimum 1 minute, no maximum)
|
||||
interval_minutes = max(interval_minutes, 1)
|
||||
|
||||
reader.set_tag((), ".reader.update", {"interval": interval_minutes}) # pyright: ignore[reportArgumentType]
|
||||
commit_state_change(reader, f"Set global update interval to {interval_minutes} minutes")
|
||||
return RedirectResponse(url="/settings", status_code=303)
|
||||
|
||||
|
||||
@app.get("/add", response_class=HTMLResponse)
|
||||
def get_add(request: Request):
|
||||
"""Page for adding a new feed.
|
||||
|
|
@ -631,7 +768,7 @@ def get_add(request: Request):
|
|||
|
||||
|
||||
@app.get("/feed", response_class=HTMLResponse)
|
||||
async def get_feed(feed_url: str, request: Request, starting_after: str = ""):
|
||||
async def get_feed(feed_url: str, request: Request, starting_after: str = ""): # noqa: C901, PLR0912, PLR0914, PLR0915
|
||||
"""Get a feed by URL.
|
||||
|
||||
Args:
|
||||
|
|
@ -656,7 +793,7 @@ async def get_feed(feed_url: str, request: Request, starting_after: str = ""):
|
|||
|
||||
# Only show button if more than 10 entries.
|
||||
total_entries: int = reader.get_entry_counts(feed=feed).total or 0
|
||||
show_more_entires_button: bool = total_entries > entries_per_page
|
||||
is_show_more_entries_button_visible: bool = total_entries > entries_per_page
|
||||
|
||||
# Get entries from the feed.
|
||||
if starting_after:
|
||||
|
|
@ -669,6 +806,27 @@ async def get_feed(feed_url: str, request: Request, starting_after: str = ""):
|
|||
msg: str = f"{e}\n\n{[entry.id for entry in current_entries]}"
|
||||
html: str = create_html_for_feed(current_entries)
|
||||
|
||||
# Get feed and global intervals for error case too
|
||||
feed_interval: int | None = None
|
||||
try:
|
||||
feed_update_config = reader.get_tag(feed, ".reader.update")
|
||||
if isinstance(feed_update_config, dict) and "interval" in feed_update_config:
|
||||
interval_value = feed_update_config["interval"]
|
||||
if isinstance(interval_value, int):
|
||||
feed_interval = interval_value
|
||||
except TagNotFoundError:
|
||||
pass
|
||||
|
||||
global_interval: int = 60
|
||||
try:
|
||||
global_update_config = reader.get_tag((), ".reader.update")
|
||||
if isinstance(global_update_config, dict) and "interval" in global_update_config:
|
||||
interval_value = global_update_config["interval"]
|
||||
if isinstance(interval_value, int):
|
||||
global_interval = interval_value
|
||||
except TagNotFoundError:
|
||||
pass
|
||||
|
||||
context = {
|
||||
"request": request,
|
||||
"feed": feed,
|
||||
|
|
@ -678,8 +836,10 @@ async def get_feed(feed_url: str, request: Request, starting_after: str = ""):
|
|||
"should_send_embed": False,
|
||||
"last_entry": None,
|
||||
"messages": msg,
|
||||
"show_more_entires_button": show_more_entires_button,
|
||||
"is_show_more_entries_button_visible": is_show_more_entries_button_visible,
|
||||
"total_entries": total_entries,
|
||||
"feed_interval": feed_interval,
|
||||
"global_interval": global_interval,
|
||||
}
|
||||
return templates.TemplateResponse(request=request, name="feed.html", context=context)
|
||||
|
||||
|
|
@ -708,6 +868,29 @@ async def get_feed(feed_url: str, request: Request, starting_after: str = ""):
|
|||
add_missing_tags(reader)
|
||||
should_send_embed: bool = bool(reader.get_tag(feed, "should_send_embed"))
|
||||
|
||||
# Get the update interval for this feed
|
||||
feed_interval: int | None = None
|
||||
try:
|
||||
feed_update_config = reader.get_tag(feed, ".reader.update")
|
||||
if isinstance(feed_update_config, dict) and "interval" in feed_update_config:
|
||||
interval_value = feed_update_config["interval"]
|
||||
if isinstance(interval_value, int):
|
||||
feed_interval = interval_value
|
||||
except TagNotFoundError:
|
||||
# No custom interval set for this feed, will use global default
|
||||
pass
|
||||
|
||||
# Get the global default update interval
|
||||
global_interval: int = 60 # Default to 60 minutes if not set
|
||||
try:
|
||||
global_update_config = reader.get_tag((), ".reader.update")
|
||||
if isinstance(global_update_config, dict) and "interval" in global_update_config:
|
||||
interval_value = global_update_config["interval"]
|
||||
if isinstance(interval_value, int):
|
||||
global_interval = interval_value
|
||||
except TagNotFoundError:
|
||||
pass
|
||||
|
||||
context = {
|
||||
"request": request,
|
||||
"feed": feed,
|
||||
|
|
@ -716,8 +899,10 @@ async def get_feed(feed_url: str, request: Request, starting_after: str = ""):
|
|||
"html": html,
|
||||
"should_send_embed": should_send_embed,
|
||||
"last_entry": last_entry,
|
||||
"show_more_entires_button": show_more_entires_button,
|
||||
"is_show_more_entries_button_visible": is_show_more_entries_button_visible,
|
||||
"total_entries": total_entries,
|
||||
"feed_interval": feed_interval,
|
||||
"global_interval": global_interval,
|
||||
}
|
||||
return templates.TemplateResponse(request=request, name="feed.html", context=context)
|
||||
|
||||
|
|
@ -847,6 +1032,56 @@ def get_data_from_hook_url(hook_name: str, hook_url: str) -> WebhookInfo:
|
|||
return our_hook
|
||||
|
||||
|
||||
@app.get("/settings", response_class=HTMLResponse)
|
||||
async def get_settings(request: Request):
|
||||
"""Settings page.
|
||||
|
||||
Args:
|
||||
request: The request object.
|
||||
|
||||
Returns:
|
||||
HTMLResponse: The settings page.
|
||||
"""
|
||||
# Get the global default update interval
|
||||
global_interval: int = 60 # Default to 60 minutes if not set
|
||||
try:
|
||||
global_update_config = reader.get_tag((), ".reader.update")
|
||||
if isinstance(global_update_config, dict) and "interval" in global_update_config:
|
||||
interval_value = global_update_config["interval"]
|
||||
if isinstance(interval_value, int):
|
||||
global_interval = interval_value
|
||||
except TagNotFoundError:
|
||||
pass
|
||||
|
||||
# Get all feeds with their intervals
|
||||
feeds: Iterable[Feed] = reader.get_feeds()
|
||||
feed_intervals = []
|
||||
for feed in feeds:
|
||||
feed_interval: int | None = None
|
||||
try:
|
||||
feed_update_config = reader.get_tag(feed, ".reader.update")
|
||||
if isinstance(feed_update_config, dict) and "interval" in feed_update_config:
|
||||
interval_value = feed_update_config["interval"]
|
||||
if isinstance(interval_value, int):
|
||||
feed_interval = interval_value
|
||||
except TagNotFoundError:
|
||||
pass
|
||||
|
||||
feed_intervals.append({
|
||||
"feed": feed,
|
||||
"interval": feed_interval,
|
||||
"effective_interval": feed_interval or global_interval,
|
||||
"domain": extract_domain(feed.url),
|
||||
})
|
||||
|
||||
context = {
|
||||
"request": request,
|
||||
"global_interval": global_interval,
|
||||
"feed_intervals": feed_intervals,
|
||||
}
|
||||
return templates.TemplateResponse(request=request, name="settings.html", context=context)
|
||||
|
||||
|
||||
@app.get("/webhooks", response_class=HTMLResponse)
|
||||
async def get_webhooks(request: Request):
|
||||
"""Page for adding a new webhook.
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from pathlib import Path
|
|||
|
||||
from platformdirs import user_data_dir
|
||||
from reader import Reader
|
||||
from reader import TagNotFoundError
|
||||
from reader import make_reader
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
|
|
@ -39,7 +40,12 @@ def get_reader(custom_location: Path | None = None) -> Reader:
|
|||
reader: Reader = make_reader(url=str(db_location))
|
||||
|
||||
# https://reader.readthedocs.io/en/latest/api.html#reader.types.UpdateConfig
|
||||
# Set the update interval to 15 minutes
|
||||
reader.set_tag((), ".reader.update", {"interval": 15})
|
||||
# Set the default update interval to 15 minutes if not already configured
|
||||
# Users can change this via the Settings page or per-feed in the feed page
|
||||
try:
|
||||
reader.get_tag((), ".reader.update")
|
||||
except TagNotFoundError:
|
||||
# Set default
|
||||
reader.set_tag((), ".reader.update", {"interval": 15})
|
||||
|
||||
return reader
|
||||
|
|
|
|||
|
|
@ -13,3 +13,7 @@ body {
|
|||
.form-text {
|
||||
color: #acabab;
|
||||
}
|
||||
|
||||
.interval-input {
|
||||
max-width: 120px;
|
||||
}
|
||||
|
|
@ -1,90 +1,145 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}
|
||||
| {{ feed.title }}
|
||||
| {{ feed.title }}
|
||||
{% endblock title %}
|
||||
{% block content %}
|
||||
<div class="card mb-3 border border-dark p-3 text-light">
|
||||
<!-- Feed Title -->
|
||||
<h2>
|
||||
<a class="text-muted" href="{{ feed.url }}">{{ feed.title }}</a> ({{ total_entries }} entries)
|
||||
</h2>
|
||||
{% if not feed.updates_enabled %}
|
||||
<span class="badge bg-danger">Disabled</span>
|
||||
{% endif %}
|
||||
|
||||
{% if feed.last_exception %}
|
||||
<div class="mt-3">
|
||||
<h5 class="text-danger">{{ feed.last_exception.type_name }}:</h5>
|
||||
<code class="d-block">{{ feed.last_exception.value_str }}</code>
|
||||
<button class="btn btn-secondary btn-sm mt-2" type="button" data-bs-toggle="collapse"
|
||||
data-bs-target="#exceptionDetails" aria-expanded="false" aria-controls="exceptionDetails">
|
||||
Show Traceback
|
||||
</button>
|
||||
<div class="collapse" id="exceptionDetails">
|
||||
<pre><code>{{ feed.last_exception.traceback_str }}</code></pre>
|
||||
<div class="card mb-3 border border-dark p-3 text-light">
|
||||
<!-- Feed Title -->
|
||||
<h2>
|
||||
<a class="text-muted" href="{{ feed.url }}">{{ feed.title }}</a> ({{ total_entries }} entries)
|
||||
</h2>
|
||||
{% if not feed.updates_enabled %}<span class="badge bg-danger">Disabled</span>{% endif %}
|
||||
{% if feed.last_exception %}
|
||||
<div class="mt-3">
|
||||
<h5 class="text-danger">{{ feed.last_exception.type_name }}:</h5>
|
||||
<code class="d-block">{{ feed.last_exception.value_str }}</code>
|
||||
<button class="btn btn-secondary btn-sm mt-2"
|
||||
type="button"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#exceptionDetails"
|
||||
aria-expanded="false"
|
||||
aria-controls="exceptionDetails">Show Traceback</button>
|
||||
<div class="collapse" id="exceptionDetails">
|
||||
<pre><code>{{ feed.last_exception.traceback_str }}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<!-- Feed Actions -->
|
||||
<div class="mt-3 d-flex flex-wrap gap-2">
|
||||
<a href="/update?feed_url={{ feed.url|encode_url }}"
|
||||
class="btn btn-primary btn-sm">Update</a>
|
||||
<form action="/remove" method="post" class="d-inline">
|
||||
<button class="btn btn-danger btn-sm"
|
||||
name="feed_url"
|
||||
value="{{ feed.url }}"
|
||||
onclick="return confirm('Are you sure you want to delete this feed?')">Remove</button>
|
||||
</form>
|
||||
{% if not feed.updates_enabled %}
|
||||
<form action="/unpause" method="post" class="d-inline">
|
||||
<button class="btn btn-secondary btn-sm"
|
||||
name="feed_url"
|
||||
value="{{ feed.url }}">Unpause</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<form action="/pause" method="post" class="d-inline">
|
||||
<button class="btn btn-danger btn-sm" name="feed_url" value="{{ feed.url }}">Pause</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% if not "youtube.com/feeds/videos.xml" in feed.url %}
|
||||
{% if should_send_embed %}
|
||||
<form action="/use_text" method="post" class="d-inline">
|
||||
<button class="btn btn-dark btn-sm" name="feed_url" value="{{ feed.url }}">Send text message instead of embed</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<form action="/use_embed" method="post" class="d-inline">
|
||||
<button class="btn btn-dark btn-sm" name="feed_url" value="{{ feed.url }}">Send embed instead of text message</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
<!-- Additional Links -->
|
||||
<div class="mt-3">
|
||||
<a class="text-muted d-block"
|
||||
href="/whitelist?feed_url={{ feed.url|encode_url }}">Whitelist</a>
|
||||
<a class="text-muted d-block"
|
||||
href="/blacklist?feed_url={{ feed.url|encode_url }}">Blacklist</a>
|
||||
<a class="text-muted d-block"
|
||||
href="/custom?feed_url={{ feed.url|encode_url }}">
|
||||
Customize message
|
||||
{% if not should_send_embed %}(Currently active){% endif %}
|
||||
</a>
|
||||
{% if not "youtube.com/feeds/videos.xml" in feed.url %}
|
||||
<a class="text-muted d-block"
|
||||
href="/embed?feed_url={{ feed.url|encode_url }}">
|
||||
Customize embed
|
||||
{% if should_send_embed %}(Currently active){% endif %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<!-- Feed Metadata -->
|
||||
<div class="mt-4 border-top border-secondary pt-3">
|
||||
<h5 class="mb-3">Feed Information</h5>
|
||||
<div class="row text-muted">
|
||||
<div class="col-md-6 mb-2">
|
||||
<small><strong>Added:</strong> {{ feed.added | relative_time }}</small>
|
||||
</div>
|
||||
<div class="col-md-6 mb-2">
|
||||
<small><strong>Last Updated:</strong> {{ feed.last_updated | relative_time }}</small>
|
||||
</div>
|
||||
<div class="col-md-6 mb-2">
|
||||
<small><strong>Last Retrieved:</strong> {{ feed.last_retrieved | relative_time }}</small>
|
||||
</div>
|
||||
<div class="col-md-6 mb-2">
|
||||
<small><strong>Next Update:</strong> {{ feed.update_after | relative_time }}</small>
|
||||
</div>
|
||||
<div class="col-md-6 mb-2">
|
||||
<small><strong>Updates:</strong> <span class="badge {{ 'bg-success' if feed.updates_enabled else 'bg-danger' }}">{{ 'Enabled' if feed.updates_enabled else 'Disabled' }}</span></small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Update Interval Configuration -->
|
||||
<div class="mt-4 border-top border-secondary pt-3">
|
||||
<h5 class="mb-3">Update Interval</h5>
|
||||
{% if feed_interval %}
|
||||
<p class="text-muted mb-2">
|
||||
Current: <strong>{{ feed_interval }} minutes</strong>
|
||||
{% if feed_interval >= 60 %}({{ (feed_interval / 60) | round(1) }} hours){% endif %}
|
||||
<span class="badge bg-info">Custom</span>
|
||||
</p>
|
||||
{% else %}
|
||||
<p class="text-muted mb-2">
|
||||
Current: <strong>{{ global_interval }} minutes</strong>
|
||||
{% if global_interval >= 60 %}({{ (global_interval / 60) | round(1) }} hours){% endif %}
|
||||
<span class="badge bg-secondary">Using global default</span>
|
||||
</p>
|
||||
{% endif %}
|
||||
<form action="/set_update_interval" method="post" class="mb-2">
|
||||
<input type="hidden" name="feed_url" value="{{ feed.url }}" />
|
||||
<div class="input-group input-group-sm mb-2">
|
||||
<input type="number"
|
||||
class="form-control form-control-sm interval-input"
|
||||
name="interval_minutes"
|
||||
placeholder="Minutes"
|
||||
min="1"
|
||||
value="{{ feed_interval if feed_interval else global_interval }}"
|
||||
required />
|
||||
<button class="btn btn-primary" type="submit">Set Interval</button>
|
||||
</div>
|
||||
</form>
|
||||
{% if feed_interval %}
|
||||
<form action="/reset_update_interval" method="post" class="d-inline">
|
||||
<input type="hidden" name="feed_url" value="{{ feed.url }}" />
|
||||
<button class="btn btn-secondary btn-sm" type="submit">Reset to Global Default</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{# Rendered HTML content #}
|
||||
<pre>{{ html|safe }}</pre>
|
||||
{% if is_show_more_entries_button_visible %}
|
||||
<a class="btn btn-dark mt-3"
|
||||
href="/feed?feed_url={{ feed.url|encode_url }}&starting_after={{ last_entry.id|encode_url }}">
|
||||
Show more entries
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<!-- Feed Actions -->
|
||||
<div class="mt-3 d-flex flex-wrap gap-2">
|
||||
<a href="/update?feed_url={{ feed.url|encode_url }}" class="btn btn-primary btn-sm">Update</a>
|
||||
|
||||
<form action="/remove" method="post" class="d-inline">
|
||||
<button class="btn btn-danger btn-sm" name="feed_url" value="{{ feed.url }}"
|
||||
onclick="return confirm('Are you sure you want to delete this feed?')">Remove</button>
|
||||
</form>
|
||||
|
||||
{% if not feed.updates_enabled %}
|
||||
<form action="/unpause" method="post" class="d-inline">
|
||||
<button class="btn btn-secondary btn-sm" name="feed_url" value="{{ feed.url }}">Unpause</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<form action="/pause" method="post" class="d-inline">
|
||||
<button class="btn btn-danger btn-sm" name="feed_url" value="{{ feed.url }}">Pause</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
{% if not "youtube.com/feeds/videos.xml" in feed.url %}
|
||||
{% if should_send_embed %}
|
||||
<form action="/use_text" method="post" class="d-inline">
|
||||
<button class="btn btn-dark btn-sm" name="feed_url" value="{{ feed.url }}">
|
||||
Send text message instead of embed
|
||||
</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<form action="/use_embed" method="post" class="d-inline">
|
||||
<button class="btn btn-dark btn-sm" name="feed_url" value="{{ feed.url }}">
|
||||
Send embed instead of text message
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Additional Links -->
|
||||
<div class="mt-3">
|
||||
<a class="text-muted d-block" href="/whitelist?feed_url={{ feed.url|encode_url }}">Whitelist</a>
|
||||
<a class="text-muted d-block" href="/blacklist?feed_url={{ feed.url|encode_url }}">Blacklist</a>
|
||||
<a class="text-muted d-block" href="/custom?feed_url={{ feed.url|encode_url }}">
|
||||
Customize message {% if not should_send_embed %}(Currently active){% endif %}
|
||||
</a>
|
||||
{% if not "youtube.com/feeds/videos.xml" in feed.url %}
|
||||
<a class="text-muted d-block" href="/embed?feed_url={{ feed.url|encode_url }}">
|
||||
Customize embed {% if should_send_embed %}(Currently active){% endif %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# Rendered HTML content #}
|
||||
<pre>{{ html|safe }}</pre>
|
||||
|
||||
{% if show_more_entires_button %}
|
||||
<a class="btn btn-dark mt-3"
|
||||
href="/feed?feed_url={{ feed.url|encode_url }}&starting_after={{ last_entry.id|encode_url }}">
|
||||
Show more entries
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
{% endblock content %}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@
|
|||
<li class="nav-item">
|
||||
<a class="nav-link" href="/webhooks">Webhooks</a>
|
||||
</li>
|
||||
<li class="nav-item nav-link d-none d-md-block">|</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/settings">Settings</a>
|
||||
</li>
|
||||
{% if get_backup_path() %}
|
||||
<li class="nav-item nav-link d-none d-md-block">|</li>
|
||||
<li class="nav-item">
|
||||
|
|
|
|||
122
discord_rss_bot/templates/settings.html
Normal file
122
discord_rss_bot/templates/settings.html
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}
|
||||
| Settings
|
||||
{% endblock title %}
|
||||
{% block content %}
|
||||
<section>
|
||||
<div class="text-light">
|
||||
<div class="d-flex flex-wrap justify-content-between align-items-center gap-2">
|
||||
<h2 class="mb-0">Global Settings</h2>
|
||||
</div>
|
||||
<p class="text-muted mt-2 mb-4">
|
||||
Set a default interval for all feeds. Individual feeds can still override this value.
|
||||
</p>
|
||||
<div class="mb-4">
|
||||
<div>
|
||||
Current default is {{ global_interval }} min.
|
||||
Even though we check ETags and Last-Modified headers, choosing a very low interval may cause issues with some feeds or cause excessive load on the server hosting the feed. Remember to be kind.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form action="/set_global_update_interval" method="post" class="mb-2">
|
||||
<div class="settings-form-row mb-2">
|
||||
<label for="interval_minutes" class="form-label mb-1">Default interval (minutes)</label>
|
||||
<div class="input-group input-group-lg">
|
||||
<input id="interval_minutes"
|
||||
type="number"
|
||||
class="form-control settings-input"
|
||||
name="interval_minutes"
|
||||
placeholder="Minutes"
|
||||
min="1"
|
||||
value="{{ global_interval }}"
|
||||
required />
|
||||
<button class="btn btn-primary px-4" type="submit">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
<section class="mt-5">
|
||||
<div class="text-light">
|
||||
<div class="d-flex flex-wrap justify-content-between align-items-center gap-2">
|
||||
<h2 class="mb-0">Feed Update Intervals</h2>
|
||||
</div>
|
||||
<p class="text-muted mt-2 mb-4">
|
||||
Customize the update interval for individual feeds. Leave empty or reset to use the global default.
|
||||
</p>
|
||||
</div>
|
||||
{% if feed_intervals %}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-dark table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Feed</th>
|
||||
<th>Domain</th>
|
||||
<th>Status</th>
|
||||
<th>Interval</th>
|
||||
<th>Last Updated</th>
|
||||
<th>Next Update</th>
|
||||
<th>Set Interval (min)</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for item in feed_intervals %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="/feed?feed_url={{ item.feed.url|encode_url }}"
|
||||
class="text-light text-decoration-none">{{ item.feed.title }}</a>
|
||||
</td>
|
||||
<td>
|
||||
<span class="text-muted small">{{ item.domain }}</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge {{ 'bg-success' if item.feed.updates_enabled else 'bg-danger' }}">
|
||||
{{ 'Enabled' if item.feed.updates_enabled else 'Disabled' }}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<span>{{ item.effective_interval }} min</span>
|
||||
{% if item.interval %}
|
||||
<span class="badge bg-info ms-1">Custom</span>
|
||||
{% else %}
|
||||
<span class="badge bg-secondary ms-1">Global</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<small class="text-muted">{{ item.feed.last_updated | relative_time }}</small>
|
||||
</td>
|
||||
<td>
|
||||
<small class="text-muted">{{ item.feed.update_after | relative_time }}</small>
|
||||
</td>
|
||||
<td>
|
||||
<form action="/set_update_interval" method="post" class="d-flex gap-2">
|
||||
<input type="hidden" name="feed_url" value="{{ item.feed.url }}" />
|
||||
<input type="hidden" name="redirect_to" value="/settings" />
|
||||
<input type="number"
|
||||
class="form-control form-control-sm interval-input"
|
||||
name="interval_minutes"
|
||||
placeholder="Minutes"
|
||||
min="1"
|
||||
value="{{ item.interval if item.interval else global_interval }}" />
|
||||
<button class="btn btn-primary btn-sm" type="submit">Set</button>
|
||||
</form>
|
||||
</td>
|
||||
<td>
|
||||
{% if item.interval %}
|
||||
<form action="/reset_update_interval" method="post" class="d-inline">
|
||||
<input type="hidden" name="feed_url" value="{{ item.feed.url }}" />
|
||||
<input type="hidden" name="redirect_to" value="/settings" />
|
||||
<button class="btn btn-outline-secondary btn-sm" type="submit">Reset</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="text-muted">No feeds added yet.</p>
|
||||
{% endif %}
|
||||
</section>
|
||||
{% endblock content %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue