Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add command next_run (n) to show the next scheduled poll time #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion rss/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from __future__ import annotations

from typing import Any, Iterable
from datetime import datetime
from datetime import datetime, timedelta
from string import Template
from time import mktime, time
import asyncio
Expand Down Expand Up @@ -75,6 +75,7 @@ class RSSBot(Plugin):
poll_task: asyncio.Future
http: aiohttp.ClientSession
power_level_cache: dict[RoomID, tuple[int, PowerLevelStateEventContent]]
next_run: datetime

@classmethod
def get_config_class(cls) -> type[BaseProxyConfig]:
Expand Down Expand Up @@ -185,6 +186,7 @@ async def _poll_feeds(self) -> None:
self.log.debug("Polling stopped")
except Exception:
self.log.exception("Error while polling feeds")
self.next_run = datetime.now() + timedelta(seconds=(self.config["update_interval"]*60))
await asyncio.sleep(self.config["update_interval"] * 60)

async def try_parse_feed(self, feed: Feed | None = None) -> tuple[Feed, list[Entry]]:
Expand Down Expand Up @@ -341,6 +343,13 @@ async def can_manage(self, evt: MessageEvent) -> bool:
async def rss(self) -> None:
pass

@rss.subcommand("nextrun", aliases=("n",), help="Get latest item for each feed.")
async def next_run(self, evt: MessageEvent) -> None:
await evt.reply(f"""Next polling in {self.next_run - datetime.now()}""")
# Next polling @ {self.next_run}
# Now: {datetime.now()}
# Delta: {self.next_run - datetime.now()}

@rss.subcommand("subscribe", aliases=("s", "sub"), help="Subscribe this room to a feed.")
@command.argument("url", "feed URL", pass_raw=True)
async def subscribe(self, evt: MessageEvent, url: str) -> None:
Expand Down