Add missing functions for ad-hoc command Browse.

Set 50 seconds delay between each URL.
This commit is contained in:
Schimon Jehudah 2024-03-08 14:21:22 +00:00
parent ae89521d9b
commit 8d9b060314
6 changed files with 96 additions and 11 deletions

View file

@ -290,7 +290,6 @@ def manual(filename, section=None, command=None):
elif section: elif section:
try: try:
cmd_list = [] cmd_list = []
breakpoint()
for cmd in cmds[section]: for cmd in cmds[section]:
cmd_list.extend([cmd]) cmd_list.extend([cmd])
except KeyError as e: except KeyError as e:

View file

@ -10,8 +10,6 @@ FIXME
TODO TODO
0) Improve function http to return sensible value (the list is not good enough)
1) Support Gemini and Gopher. 1) Support Gemini and Gopher.
2) Check also for HTML, not only feed.bozo. 2) Check also for HTML, not only feed.bozo.

View file

@ -1122,6 +1122,82 @@ def get_number_of_entries_unread(db_file):
return count 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): def get_unread_entries(db_file, num):
""" """
Extract information from unread entries. Extract information from unread entries.

View file

@ -284,6 +284,7 @@ async def check_updates(self, jid):
urls = sqlite.get_active_feeds_url(db_file) urls = sqlite.get_active_feeds_url(db_file)
for url in urls: for url in urls:
await action.scan(self, jid, db_file, url) await action.scan(self, jid, db_file, url)
await asyncio.sleep(50)
val = self.settings['default']['check'] val = self.settings['default']['check']
await asyncio.sleep(60 * float(val)) await asyncio.sleep(60 * float(val))
# Schedule to call this function again in 90 minutes # Schedule to call this function again in 90 minutes

View file

@ -1,2 +1,2 @@
__version__ = '0.1.33' __version__ = '0.1.34'
__version_info__ = (0, 1, 33) __version_info__ = (0, 1, 34)

View file

@ -959,7 +959,7 @@ class Slixfeed(slixmpp.ClientXMPP):
options.addOption('All news', 'all') options.addOption('All news', 'all')
# options.addOption('News by subscription', 'feed') # options.addOption('News by subscription', 'feed')
# options.addOption('News by tag', 'tag') # options.addOption('News by tag', 'tag')
options.addOption('Rejected news', 'rejected') options.addOption('Rejected news', 'reject')
options.addOption('Unread news', 'unread') 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['allow_prev'] = False # Cheogram changes style if that button - which should not be on this form - is present
session['has_next'] = True session['has_next'] = True
@ -980,14 +980,20 @@ class Slixfeed(slixmpp.ClientXMPP):
num = 100 num = 100
match payload['values']['action']: match payload['values']['action']:
case 'all': case 'all':
results = sqlite.get_entries(db_file, num) # FIXME results = sqlite.get_entries(db_file, num)
case 'rejected': subtitle = 'Recent {} updates'.format(num)
results = sqlite.get_entries_rejected(db_file, num) # FIXME 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': case 'unread':
results = sqlite.get_unread_entries(db_file, num) results = sqlite.get_unread_entries(db_file, num)
subtitle = 'Recent {} updates (unread)'.format(num)
message = 'There are no unread news.'
if results: if results:
form = self['xep_0004'].make_form('form', 'Updates') form = self['xep_0004'].make_form('form', 'Updates')
form['instructions'] = 'Recent {} updates'.format(num) form['instructions'] = subtitle
options = form.add_field(var='update', options = form.add_field(var='update',
ftype='list-single', ftype='list-single',
label='News', label='News',
@ -1003,8 +1009,13 @@ class Slixfeed(slixmpp.ClientXMPP):
session['payload'] = form session['payload'] = form
session['prev'] = None # Cheogram works as expected with 'allow_prev' set to False Just in case session['prev'] = None # Cheogram works as expected with 'allow_prev' set to False Just in case
else: 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['notes'] = [['info', text_info]]
session['payload'] = None
session['prev'] = self._handle_recent
return session return session