From c1ef5acc7e97c4b3d7c9e3d832a54bee2278d105 Mon Sep 17 00:00:00 2001 From: Schimon Jehudah Date: Wed, 24 Jan 2024 20:28:14 +0000 Subject: [PATCH] More fixes --- slixfeed/__main__.py | 17 +++++++---------- slixfeed/action.py | 8 +++++++- slixfeed/xmpp/client.py | 11 +++++++++-- slixfeed/xmpp/component.py | 9 ++------- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/slixfeed/__main__.py b/slixfeed/__main__.py index 82954e4..1de4aa4 100644 --- a/slixfeed/__main__.py +++ b/slixfeed/__main__.py @@ -112,12 +112,12 @@ match xmpp_type: case "client": from slixfeed.xmpp.client import Slixfeed case "component": - from slixfeed.xmpp.component import Slixfeed + from slixfeed.xmpp.component import SlixfeedComponent class JabberComponent: - def __init__(self, jid, secret, hostname, port, alias): - xmpp = Slixfeed(jid, secret, hostname, port, alias) + def __init__(self, jid, secret, hostname, port, alias=None): + xmpp = SlixfeedComponent(jid, secret, hostname, port, alias) xmpp.register_plugin('xep_0004') # Data Forms xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0045') # Multi-User Chat @@ -139,11 +139,8 @@ class JabberComponent: class JabberClient: - def __init__(self, jid, password, alias): - # Setup the Slixfeed and register plugins. Note that while plugins may - # have interdependencies, the order in which you register them does - # not matter. - xmpp = Slixfeed(jid, password, alias) + def __init__(self, jid, password, hostname=None, port=None, alias=None): + xmpp = Slixfeed(jid, password, hostname, port, alias) xmpp.register_plugin('xep_0004') # Data Forms xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0045') # Multi-User Chat @@ -266,9 +263,9 @@ def main(): match xmpp_type: case "client": - JabberClient(jid, password, alias) + JabberClient(jid, password, hostname=hostname, port=port, alias=alias) case "component": - JabberComponent(jid, password, hostname, port, alias) + JabberComponent(jid, password, hostname, port, alias=alias) sys.exit(0) if __name__ == "__main__": diff --git a/slixfeed/action.py b/slixfeed/action.py index 3a1db5a..2060ff1 100644 --- a/slixfeed/action.py +++ b/slixfeed/action.py @@ -51,9 +51,15 @@ from slixfeed.url import ( import slixfeed.xmpp.bookmark as bookmark from urllib import error from urllib.parse import parse_qs, urlsplit -import xml2epub import xml.etree.ElementTree as ET +try: + import xml2epub +except: + logging.info( + "Package xml2epub was not found.\n" + "ePUB support is disabled.") + try: import html2text except: diff --git a/slixfeed/xmpp/client.py b/slixfeed/xmpp/client.py index 75ae1de..bb85aca 100644 --- a/slixfeed/xmpp/client.py +++ b/slixfeed/xmpp/client.py @@ -16,7 +16,14 @@ TODO 2) Assure message delivery before calling a new task. See https://slixmpp.readthedocs.io/en/latest/event_index.html#term-marker_acknowledged -3) XHTTML-IM +3) Check the lesyt message sent by the bot. + This is essential in case bot restarts within an update interval. + Example: + Bot is set to send an update every 5 hours. + Bot was disconnected and reconnected after an hour. + Bot will send an update when it is connected, which is lesser than 5 hours as it should. + +4) XHTTML-IM case _ if message_lowercase.startswith("html"): message['html']=" Parse me! @@ -91,7 +98,7 @@ class Slixfeed(slixmpp.ClientXMPP): ------- News bot that sends updates from RSS feeds. """ - def __init__(self, jid, password, alias): + def __init__(self, jid, password, hostname=None, port=None, alias=None): slixmpp.ClientXMPP.__init__(self, jid, password) # NOTE diff --git a/slixfeed/xmpp/component.py b/slixfeed/xmpp/component.py index 750f5b0..94cffe3 100644 --- a/slixfeed/xmpp/component.py +++ b/slixfeed/xmpp/component.py @@ -85,13 +85,8 @@ loop = asyncio.get_event_loop() # return current_time -class Slixfeed(slixmpp.ComponentXMPP): - """ - Slixmpp - ------- - News bot that sends updates from RSS feeds. - """ - def __init__(self, jid, secret, hostname, port, alias): +class SlixfeedComponent(slixmpp.ComponentXMPP): + def __init__(self, jid, secret, hostname, port, alias=None): slixmpp.ComponentXMPP.__init__(self, jid, secret, hostname, port) # The session_start event will be triggered when