From 37444c9d4e41034fd875c9027920baf7eab75ead Mon Sep 17 00:00:00 2001 From: "Schimon Jehudah, Adv." Date: Mon, 24 Jun 2024 12:46:05 +0300 Subject: [PATCH] Fix default alias upon joining to an MUC groupchat; Scan subscriptions by last scanned time; Update file README. --- README.md | 6 +-- slixfeed/sqlite.py | 33 +++++++++++++ slixfeed/syndication.py | 4 +- slixfeed/utilities.py | 101 ++++++++++++++++++++++++++++++++++++++++ slixfeed/version.py | 4 +- slixfeed/xmpp/muc.py | 2 +- 6 files changed, 142 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 510b71f..f2dfc22 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ It is possible to install Slixfeed using pip and pipx. ``` $ python3 -m venv .venv $ source .venv/bin/activate -$ pip install git+https://gitgud.io/sjehuda/slixfeed +$ pip install git+https://git.xmpp-it.net/sch/Slixfeed ``` #### pipx @@ -64,14 +64,14 @@ $ pip install git+https://gitgud.io/sjehuda/slixfeed ##### Install ``` -$ pipx install git+https://gitgud.io/sjehuda/slixfeed +$ pipx install git+https://git.xmpp-it.net/sch/Slixfeed ``` ##### Update ``` $ pipx uninstall slixfeed -$ pipx install git+https://gitgud.io/sjehuda/slixfeed +$ pipx install git+https://git.xmpp-it.net/sch/Slixfeed ``` ### Start diff --git a/slixfeed/sqlite.py b/slixfeed/sqlite.py index 09e6e8e..9813601 100644 --- a/slixfeed/sqlite.py +++ b/slixfeed/sqlite.py @@ -2762,6 +2762,39 @@ def get_active_feeds_url(db_file): return result +def get_active_feeds_url_sorted_by_last_scanned(db_file): + """ + Query table feeds for active URLs and sort them by last scanned time. + + Parameters + ---------- + db_file : str + Path to database file. + + Returns + ------- + result : tuple + URLs of active feeds. + """ + function_name = sys._getframe().f_code.co_name + logger.debug('{}: db_file: {}' + .format(function_name, db_file)) + with create_connection(db_file) as conn: + cur = conn.cursor() + sql = ( + """ + SELECT feeds_properties.url + FROM feeds_properties + INNER JOIN feeds_preferences ON feeds_properties.id = feeds_preferences.feed_id + INNER JOIN feeds_state ON feeds_properties.id = feeds_state.feed_id + WHERE feeds_preferences.enabled = 1 + ORDER BY feeds_state.scanned + """ + ) + result = cur.execute(sql).fetchall() + return result + + def get_tags(db_file): """ Query table tags and list items. diff --git a/slixfeed/syndication.py b/slixfeed/syndication.py index d220189..622b21f 100644 --- a/slixfeed/syndication.py +++ b/slixfeed/syndication.py @@ -1276,7 +1276,7 @@ class FeedTask: logger.info('Scanning for updates for JID {}'.format(jid_bare)) while True: db_file = config.get_pathname_to_database(jid_bare) - urls = sqlite.get_active_feeds_url(db_file) + urls = sqlite.get_active_feeds_url_sorted_by_last_scanned(db_file) for url in urls: Message.printer('Scanning updates for URL {} ...'.format(url)) url = url[0] @@ -1360,7 +1360,7 @@ class FeedTask: # TODO return number of archived entries and add if statement to run archive maintainence function await sqlite.maintain_archive(db_file, limit) # await sqlite.process_invalid_entries(db_file, ixs) - await asyncio.sleep(50) + await asyncio.sleep(60 * 2) val = Config.get_setting_value(self.settings, jid_bare, 'check') await asyncio.sleep(60 * float(val)) # Schedule to call this function again in 90 minutes diff --git a/slixfeed/utilities.py b/slixfeed/utilities.py index 7655386..0504231 100644 --- a/slixfeed/utilities.py +++ b/slixfeed/utilities.py @@ -67,6 +67,107 @@ except: logger = Logger(__name__) +class Config: + + + def get_default_data_directory(): + if os.environ.get('HOME'): + data_home = os.path.join(os.environ.get('HOME'), '.local', 'share') + return os.path.join(data_home, 'kaikout') + elif sys.platform == 'win32': + data_home = os.environ.get('APPDATA') + if data_home is None: + return os.path.join( + os.path.dirname(__file__) + '/kaikout_data') + else: + return os.path.join(os.path.dirname(__file__) + '/kaikout_data') + + + def get_default_config_directory(): + """ + Determine the directory path where configuration will be stored. + + * If $XDG_CONFIG_HOME is defined, use it; + * else if $HOME exists, use it; + * else if the platform is Windows, use %APPDATA%; + * else use the current directory. + + Returns + ------- + str + Path to configuration directory. + """ + # config_home = xdg.BaseDirectory.xdg_config_home + config_home = os.environ.get('XDG_CONFIG_HOME') + if config_home is None: + if os.environ.get('HOME') is None: + if sys.platform == 'win32': + config_home = os.environ.get('APPDATA') + if config_home is None: + return os.path.abspath('.') + else: + return os.path.abspath('.') + else: + config_home = os.path.join( + os.environ.get('HOME'), '.config' + ) + return os.path.join(config_home, 'kaikout') + + + def get_setting_value(db_file, key): + value = sqlite.get_setting_value(db_file, key) + if value: + value = value[0] + else: + value = Config.get_value('settings', 'Settings', key) + return value + + + def get_values(filename, key=None): + config_dir = Config.get_default_config_directory() + if not os.path.isdir(config_dir): + config_dir = '/usr/share/slixfeed/' + if not os.path.isdir(config_dir): + config_dir = os.path.dirname(__file__) + "/assets" + config_file = os.path.join(config_dir, filename) + with open(config_file, mode="rb") as defaults: + result = tomllib.load(defaults) + values = result[key] if key else result + return values + + +class Database: + + + def instantiate(jid_bare): + """ + Callback function to instantiate action on database. + + Parameters + ---------- + jid_file : str + Filename. + callback : ? + Function name. + message : str, optional + Optional kwarg when a message is a part or + required argument. The default is None. + + Returns + ------- + object + Coroutine object. + """ + db_dir = Config.get_default_data_directory() + if not os.path.isdir(db_dir): + os.mkdir(db_dir) + if not os.path.isdir(db_dir + "/sqlite"): + os.mkdir(db_dir + "/sqlite") + db_file = os.path.join(db_dir, "sqlite", r"{}.db".format(jid_bare)) + sqlite.create_tables(db_file) + return db_file + + class DateAndTime: #https://feedparser.readthedocs.io/en/latest/date-parsing.html diff --git a/slixfeed/version.py b/slixfeed/version.py index 53c16e8..a0c6369 100644 --- a/slixfeed/version.py +++ b/slixfeed/version.py @@ -1,2 +1,2 @@ -__version__ = '0.1.85' -__version_info__ = (0, 1, 85) +__version__ = '0.1.86' +__version_info__ = (0, 1, 86) diff --git a/slixfeed/xmpp/muc.py b/slixfeed/xmpp/muc.py index 55ed444..c9a1f9b 100644 --- a/slixfeed/xmpp/muc.py +++ b/slixfeed/xmpp/muc.py @@ -46,7 +46,7 @@ class XmppMuc: # ) logger.info('Joining groupchat\nJID : {}\n'.format(jid)) jid_from = str(self.boundjid) if self.is_component else None - if alias == None: self.alias + if not alias: alias = self.alias try: await self.plugin['xep_0045'].join_muc_wait(jid, alias,