From 735ce581785aaebb8ce6e226a742acfeb27e6247 Mon Sep 17 00:00:00 2001 From: "Schimon Jehudah, Adv." Date: Fri, 13 Sep 2024 11:44:08 +0300 Subject: [PATCH] Improve PEP and PubSub publishing mechanism; Change label to value for fixed fields of data forms. --- slixfeed/syndication.py | 8 +++++++- slixfeed/version.py | 4 ++-- slixfeed/xmpp/client.py | 35 ++++++++++++++++++++--------------- slixfeed/xmpp/publish.py | 6 +++--- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/slixfeed/syndication.py b/slixfeed/syndication.py index 30090e7..efc3fba 100644 --- a/slixfeed/syndication.py +++ b/slixfeed/syndication.py @@ -1370,10 +1370,16 @@ class FeedTask: # self.check_updates(jid) # ) - # Consider an endless loop. See XmppPubsubTask.loop_task # def restart_task(self, jid_bare): + async def loop_task(self, jid_bare): + await asyncio.sleep(60) + while True: + logger.info('Looping task "check" for JID {}'.format(jid_bare)) + print('Looping task "check" for JID {}'.format(jid_bare)) + await FeedTask.check_updates(self, jid_bare) + await asyncio.sleep(60 * 60) def restart_task(self, jid_bare): if jid_bare not in self.task_manager: diff --git a/slixfeed/version.py b/slixfeed/version.py index da736d1..ea65daf 100644 --- a/slixfeed/version.py +++ b/slixfeed/version.py @@ -1,2 +1,2 @@ -__version__ = '0.1.96' -__version_info__ = (0, 1, 96) +__version__ = '0.1.97' +__version_info__ = (0, 1, 97) diff --git a/slixfeed/xmpp/client.py b/slixfeed/xmpp/client.py index abebe27..4a9b458 100644 --- a/slixfeed/xmpp/client.py +++ b/slixfeed/xmpp/client.py @@ -383,20 +383,25 @@ class XmppClient(slixmpp.ClientXMPP): print('POSIX sockets: Initiating IPC server...') self.ipc = asyncio.create_task(XmppIpcServer.ipc(self)) - while True: - results = await XmppPubsub.get_pubsub_services(self) - for result in results + [{'jid' : self.boundjid.bare, - 'name' : self.alias}]: - jid_bare = result['jid'] - if jid_bare not in self.settings: - db_file = config.get_pathname_to_database(jid_bare) - Config.add_settings_jid(self, jid_bare, db_file) - #await FeedTask.check_updates(self, jid_bare) - #await XmppPubsubTask.task_publish(self, jid_bare) - FeedTask.restart_task(self, jid_bare) - #XmppPubsubTask.loop_task(self, jid_bare) - XmppPubsubTask.restart_task(self, jid_bare) - await asyncio.sleep(60 * 180) + results = await XmppPubsub.get_pubsub_services(self) + for result in results + [{'jid' : self.boundjid.bare, + 'name' : self.alias}]: + jid_bare = result['jid'] + if jid_bare not in self.settings: + db_file = config.get_pathname_to_database(jid_bare) + Config.add_settings_jid(self, jid_bare, db_file) + #await XmppPubsubTask.task_publish(self, jid_bare) + #await FeedTask.check_updates(self, jid_bare) + #XmppPubsubTask.restart_task(self, jid_bare) + #FeedTask.restart_task(self, jid_bare) + #tasks = [ + # asyncio.create_task(XmppPubsubTask.loop_task(self, jid_bare)), + # asyncio.create_task(FeedTask.loop_task(self, jid_bare)) + #] + #await asyncio.gather(*tasks) + asyncio.create_task(FeedTask.loop_task(self, jid_bare)) + asyncio.create_task(XmppPubsubTask.loop_task(self, jid_bare)), + print('End') time_end = time.time() difference = time_end - time_begin @@ -2795,7 +2800,7 @@ class XmppClient(slixmpp.ClientXMPP): if e_key == 'Name': desc = entry['desc'] if 'desc' in entry and entry['desc'] else None form.add_field(ftype='fixed', - label=e_val, + value=e_val, desc=desc) continue if e_key == 'Desc': diff --git a/slixfeed/xmpp/publish.py b/slixfeed/xmpp/publish.py index 8b3cb2c..4599329 100644 --- a/slixfeed/xmpp/publish.py +++ b/slixfeed/xmpp/publish.py @@ -19,7 +19,6 @@ from slixfeed.syndication import Feed from slixfeed.utilities import String, Url, Utilities from slixfeed.xmpp.iq import XmppIQ import sys -import time logger = Logger(__name__) @@ -378,11 +377,12 @@ class XmppPubsubAction: class XmppPubsubTask: - def loop_task(self, jid_bare): + async def loop_task(self, jid_bare): db_file = config.get_pathname_to_database(jid_bare) if jid_bare not in self.settings: Config.add_settings_jid(self, jid_bare, db_file) while True: + print('Looping task "publish" for JID {}'.format(jid_bare)) if jid_bare not in self.task_manager: self.task_manager[jid_bare] = {} logger.info('Creating new task manager for JID {}'.format(jid_bare)) @@ -395,7 +395,7 @@ class XmppPubsubTask: logger.info('Starting tasks "publish" for JID {}'.format(jid_bare)) self.task_manager[jid_bare]['publish'] = asyncio.create_task( XmppPubsubAction.send_unread_items(self, jid_bare)) - time.sleep(60 * 180) + await asyncio.sleep(60 * 180) def restart_task(self, jid_bare):