From 8d9b060314e70c0f219b4f8c758fbf38979f961b Mon Sep 17 00:00:00 2001 From: Schimon Jehudah Date: Fri, 8 Mar 2024 14:21:22 +0000 Subject: [PATCH] Add missing functions for ad-hoc command Browse. Set 50 seconds delay between each URL. --- slixfeed/action.py | 1 - slixfeed/fetch.py | 2 -- slixfeed/sqlite.py | 76 +++++++++++++++++++++++++++++++++++++++++ slixfeed/task.py | 1 + slixfeed/version.py | 4 +-- slixfeed/xmpp/client.py | 23 +++++++++---- 6 files changed, 96 insertions(+), 11 deletions(-) diff --git a/slixfeed/action.py b/slixfeed/action.py index e1f77fa..f681b77 100644 --- a/slixfeed/action.py +++ b/slixfeed/action.py @@ -290,7 +290,6 @@ def manual(filename, section=None, command=None): elif section: try: cmd_list = [] - breakpoint() for cmd in cmds[section]: cmd_list.extend([cmd]) except KeyError as e: diff --git a/slixfeed/fetch.py b/slixfeed/fetch.py index b7fdc52..d24b54d 100644 --- a/slixfeed/fetch.py +++ b/slixfeed/fetch.py @@ -10,8 +10,6 @@ FIXME TODO -0) Improve function http to return sensible value (the list is not good enough) - 1) Support Gemini and Gopher. 2) Check also for HTML, not only feed.bozo. diff --git a/slixfeed/sqlite.py b/slixfeed/sqlite.py index 431fe51..d9e31b0 100644 --- a/slixfeed/sqlite.py +++ b/slixfeed/sqlite.py @@ -1122,6 +1122,82 @@ def get_number_of_entries_unread(db_file): return count +def get_entries(db_file, num): + """ + Extract information from entries. + + Parameters + ---------- + db_file : str + Path to database file. + num : str, optional + Number. The default is None. + + Returns + ------- + result : tuple + News items. + """ + function_name = sys._getframe().f_code.co_name + logger.debug('{}: db_file: {} num: {}' + .format(function_name, db_file, num)) + with create_connection(db_file) as conn: + cur = conn.cursor() + sql = ( + """ + SELECT id, title, link, summary, enclosure, feed_id, timestamp + FROM entries + UNION ALL + SELECT id, title, link, summary, enclosure, feed_id, timestamp + FROM archive + ORDER BY timestamp DESC + LIMIT :num + """ + ) + par = (num,) + result = cur.execute(sql, par).fetchall() + return result + + +def get_entries_rejected(db_file, num): + """ + Extract information from rejected entries. + + Parameters + ---------- + db_file : str + Path to database file. + num : str, optional + Number. The default is None. + + Returns + ------- + result : tuple + News items. + """ + function_name = sys._getframe().f_code.co_name + logger.debug('{}: db_file: {} num: {}' + .format(function_name, db_file, num)) + with create_connection(db_file) as conn: + cur = conn.cursor() + sql = ( + """ + SELECT id, title, link, summary, enclosure, feed_id, timestamp + FROM entries + WHERE reject = 1 + UNION ALL + SELECT id, title, link, summary, enclosure, feed_id, timestamp + FROM archive + WHERE reject = 1 + ORDER BY timestamp DESC + LIMIT :num + """ + ) + par = (num,) + result = cur.execute(sql, par).fetchall() + return result + + def get_unread_entries(db_file, num): """ Extract information from unread entries. diff --git a/slixfeed/task.py b/slixfeed/task.py index 75328bb..6ebfd75 100644 --- a/slixfeed/task.py +++ b/slixfeed/task.py @@ -284,6 +284,7 @@ async def check_updates(self, jid): urls = sqlite.get_active_feeds_url(db_file) for url in urls: await action.scan(self, jid, db_file, url) + await asyncio.sleep(50) val = self.settings['default']['check'] await asyncio.sleep(60 * float(val)) # Schedule to call this function again in 90 minutes diff --git a/slixfeed/version.py b/slixfeed/version.py index 936f958..67586a2 100644 --- a/slixfeed/version.py +++ b/slixfeed/version.py @@ -1,2 +1,2 @@ -__version__ = '0.1.33' -__version_info__ = (0, 1, 33) +__version__ = '0.1.34' +__version_info__ = (0, 1, 34) diff --git a/slixfeed/xmpp/client.py b/slixfeed/xmpp/client.py index f596324..36817c2 100644 --- a/slixfeed/xmpp/client.py +++ b/slixfeed/xmpp/client.py @@ -959,7 +959,7 @@ class Slixfeed(slixmpp.ClientXMPP): options.addOption('All news', 'all') # options.addOption('News by subscription', 'feed') # options.addOption('News by tag', 'tag') - options.addOption('Rejected news', 'rejected') + options.addOption('Rejected news', 'reject') options.addOption('Unread news', 'unread') session['allow_prev'] = False # Cheogram changes style if that button - which should not be on this form - is present session['has_next'] = True @@ -980,14 +980,20 @@ class Slixfeed(slixmpp.ClientXMPP): num = 100 match payload['values']['action']: case 'all': - results = sqlite.get_entries(db_file, num) # FIXME - case 'rejected': - results = sqlite.get_entries_rejected(db_file, num) # FIXME + results = sqlite.get_entries(db_file, num) + subtitle = 'Recent {} updates'.format(num) + message = 'There are no news' + case 'reject': + results = sqlite.get_entries_rejected(db_file, num) + subtitle = 'Recent {} updates (rejected)'.format(num) + message = 'There are no rejected news' case 'unread': results = sqlite.get_unread_entries(db_file, num) + subtitle = 'Recent {} updates (unread)'.format(num) + message = 'There are no unread news.' if results: form = self['xep_0004'].make_form('form', 'Updates') - form['instructions'] = 'Recent {} updates'.format(num) + form['instructions'] = subtitle options = form.add_field(var='update', ftype='list-single', label='News', @@ -1003,8 +1009,13 @@ class Slixfeed(slixmpp.ClientXMPP): session['payload'] = form session['prev'] = None # Cheogram works as expected with 'allow_prev' set to False Just in case else: - text_info = 'There are no unread news.' + text_info = message + session['allow_prev'] = True + session['has_next'] = False + session['next'] = None session['notes'] = [['info', text_info]] + session['payload'] = None + session['prev'] = self._handle_recent return session