Shorten string formatting.
This commit is contained in:
parent
d6dfbc339e
commit
6a78afd67f
2 changed files with 154 additions and 209 deletions
|
@ -158,39 +158,35 @@ class XmppChat:
|
|||
command_list = ''.join(command_list)
|
||||
response = (command_list)
|
||||
else:
|
||||
response = ('KeyError for {} {}'
|
||||
.format(command_root, command_name))
|
||||
response = f'KeyError for {command_root} {command_name}'
|
||||
elif len(command) == 1:
|
||||
command = command[0]
|
||||
command_list = Documentation.manual(
|
||||
'commands.toml', command)
|
||||
if command_list:
|
||||
command_list = ' '.join(command_list)
|
||||
response = ('Available command `{}` keys:\n'
|
||||
'```\n{}\n```\n'
|
||||
'Usage: `help {} <command>`'
|
||||
.format(command, command_list, command))
|
||||
response = (f'Available command `{command}` keys:\n'
|
||||
f'```\n{command_list}\n```\n'
|
||||
f'Usage: `help {command} <command>`')
|
||||
else:
|
||||
response = 'KeyError for {}'.format(command)
|
||||
response = f'KeyError for {command}'
|
||||
else:
|
||||
response = ('Invalid. Enter command key '
|
||||
'or command key & name')
|
||||
case 'info':
|
||||
entries = XmppCommands.print_info_list(self)
|
||||
response = ('Available command options:\n'
|
||||
'```\n{}\n```\n'
|
||||
'Usage: `info <option>`'
|
||||
.format(entries))
|
||||
f'```\n{entries}\n```\n'
|
||||
'Usage: `info <option>`')
|
||||
case _ if command_lowercase.startswith('info'):
|
||||
entry = command[5:].lower()
|
||||
response = XmppCommands.print_info_specific(self, entry)
|
||||
case _ if command_lowercase in ['greetings', 'hallo', 'hello',
|
||||
'hey', 'hi', 'hola', 'holla',
|
||||
'hollo']:
|
||||
response = ('Greeting. My name is {}.\n'
|
||||
response = (f'Greeting. My name is {self.alias}.\n'
|
||||
'I am an Atom/RSS News Bot.\n'
|
||||
'Send "help" for further instructions.\n'
|
||||
.format(self.alias))
|
||||
'Send "help" for further instructions.\n')
|
||||
case _ if command_lowercase.startswith('add'):
|
||||
command = command[4:]
|
||||
url = command.split(' ')[0]
|
||||
|
@ -202,24 +198,18 @@ class XmppChat:
|
|||
if val:
|
||||
await XmppCommands.set_filter_allow(
|
||||
db_file, val, True)
|
||||
response = ('Approved keywords\n'
|
||||
'```\n{}\n```'
|
||||
.format(val))
|
||||
response = f'Approved keywords\n```\n{val}\n```'
|
||||
else:
|
||||
response = ('No action has been taken.'
|
||||
'\n'
|
||||
response = ('No action has been taken.\n'
|
||||
'Missing keywords.')
|
||||
case _ if command_lowercase.startswith('allow -'):
|
||||
val = command[7:]
|
||||
if val:
|
||||
await XmppCommands.set_filter_allow(
|
||||
db_file, val, False)
|
||||
response = ('Approved keywords\n'
|
||||
'```\n{}\n```'
|
||||
.format(val))
|
||||
response = f'Approved keywords\n```\n{val}\n```'
|
||||
else:
|
||||
response = ('No action has been taken.'
|
||||
'\n'
|
||||
response = ('No action has been taken.\n'
|
||||
'Missing keywords.')
|
||||
case _ if command_lowercase.startswith('archive'):
|
||||
val = command[8:]
|
||||
|
@ -265,24 +255,18 @@ class XmppChat:
|
|||
if val:
|
||||
await XmppCommands.set_filter_allow(
|
||||
db_file, val, True)
|
||||
response = ('Rejected keywords\n'
|
||||
'```\n{}\n```'
|
||||
.format(val))
|
||||
response = f'Rejected keywords\n```\n{val}\n```'
|
||||
else:
|
||||
response = ('No action has been taken.'
|
||||
'\n'
|
||||
response = ('No action has been taken.\n'
|
||||
'Missing keywords.')
|
||||
case _ if command_lowercase.startswith('deny -'):
|
||||
val = command[6:]
|
||||
if val:
|
||||
await XmppCommands.set_filter_allow(
|
||||
db_file, val, False)
|
||||
response = ('Rejected keywords\n'
|
||||
'```\n{}\n```'
|
||||
.format(val))
|
||||
response = f'Rejected keywords\n```\n{val}\n```'
|
||||
else:
|
||||
response = ('No action has been taken.'
|
||||
'\n'
|
||||
response = ('No action has been taken.\n'
|
||||
'Missing keywords.')
|
||||
case _ if command_lowercase.startswith('disable'):
|
||||
response = await XmppCommands.feed_disable(
|
||||
|
@ -296,8 +280,7 @@ class XmppChat:
|
|||
if ext in ('md', 'opml'): # html xbel
|
||||
status_type = 'dnd'
|
||||
status_message = ('📤️ Procesing request to '
|
||||
'export feeds into {}...'
|
||||
.format(ext.upper()))
|
||||
f'export feeds into {ext.upper()}...')
|
||||
# pending_tasks_num = len(self.pending_tasks[jid_bare])
|
||||
pending_tasks_num = randrange(10000, 99999)
|
||||
self.pending_tasks[jid_bare][pending_tasks_num] = status_message
|
||||
|
@ -311,8 +294,8 @@ class XmppChat:
|
|||
encrypted = True if encrypt_omemo else False
|
||||
url = await XmppUpload.start(self, jid_bare, Path(pathname), encrypted=encrypted)
|
||||
# response = (
|
||||
# 'Feeds exported successfully to {}.\n{}'
|
||||
# ).format(ex, url)
|
||||
# f'Feeds exported successfully to {ex}.\n{url}'
|
||||
# )
|
||||
# XmppMessage.send_oob_reply_message(message, url, response)
|
||||
if url:
|
||||
chat_type = await XmppUtilities.get_chat_type(self, jid_bare)
|
||||
|
@ -335,11 +318,11 @@ class XmppChat:
|
|||
result, number = XmppCommands.list_feeds(db_file, query)
|
||||
if number:
|
||||
if query:
|
||||
first_line = 'Subscriptions containing "{}":\n\n```\n'.format(query)
|
||||
first_line = f'Subscriptions containing "{query}":\n\n```\n'
|
||||
else:
|
||||
first_line = 'Subscriptions:\n\n```\n'
|
||||
response = (first_line + result +
|
||||
'\n```\nTotal of {} feeds'.format(number))
|
||||
f'\n```\nTotal of {number} feeds')
|
||||
case 'goodbye':
|
||||
if message_type == 'groupchat':
|
||||
await XmppCommands.muc_leave(self, jid_bare)
|
||||
|
@ -367,7 +350,7 @@ class XmppChat:
|
|||
XmppStatusTask.restart_task(self, jid_bare)
|
||||
case _ if command_lowercase.startswith('pubsub list'):
|
||||
jid_full_pubsub = command[12:]
|
||||
response = 'List of nodes for {}:\n```\n'.format(jid_full_pubsub)
|
||||
response = f'List of nodes for {jid_full_pubsub}:\n```\n'
|
||||
response = await XmppCommands.pubsub_list(self, jid_full_pubsub)
|
||||
response += '```'
|
||||
case _ if command_lowercase.startswith('pubsub send'):
|
||||
|
@ -390,8 +373,7 @@ class XmppChat:
|
|||
command_lowercase.startswith('rss:/')):
|
||||
url = command
|
||||
status_type = 'dnd'
|
||||
status_message = ('📫️ Processing request to fetch data from {}'
|
||||
.format(url))
|
||||
status_message = f'📫️ Processing request to fetch data from {url}'
|
||||
# pending_tasks_num = len(self.pending_tasks[jid_bare])
|
||||
pending_tasks_num = randrange(10000, 99999)
|
||||
self.pending_tasks[jid_bare][pending_tasks_num] = status_message
|
||||
|
@ -406,9 +388,9 @@ class XmppChat:
|
|||
XmppStatusTask.restart_task(self, jid_bare)
|
||||
# except:
|
||||
# response = (
|
||||
# '> {}\nNews source is in the process '
|
||||
# f'> {url}\nNews source is in the process '
|
||||
# 'of being added to the subscription '
|
||||
# 'list.'.format(url)
|
||||
# 'list.'
|
||||
# )
|
||||
case _ if command_lowercase.startswith('interval'):
|
||||
val = command[9:]
|
||||
|
@ -497,7 +479,7 @@ class XmppChat:
|
|||
Task.stop(self, jid_bare, 'status')
|
||||
status_type = 'dnd'
|
||||
status_message = ('📫️ Processing request to fetch data '
|
||||
'from {}'.format(url))
|
||||
f'from {url}')
|
||||
pending_tasks_num = randrange(10000, 99999)
|
||||
self.pending_tasks[jid_bare][pending_tasks_num] = status_message
|
||||
response = await XmppCommands.feed_read(
|
||||
|
@ -513,7 +495,7 @@ class XmppChat:
|
|||
if not num: num = 5
|
||||
count, result = XmppCommands.print_recent(self, db_file, num)
|
||||
if count:
|
||||
response = 'Recent {} fetched titles:\n\n```'.format(num)
|
||||
response = f'Recent {num} fetched titles:\n\n```'
|
||||
response += result + '```\n'
|
||||
else:
|
||||
response = result
|
||||
|
@ -634,7 +616,7 @@ class XmppChat:
|
|||
else:
|
||||
XmppMessage.send_reply(self, message, response)
|
||||
if Config.get_setting_value(self, jid_bare, 'finished'):
|
||||
response_finished = 'Finished. Total time: {}s'.format(command_time_total)
|
||||
response_finished = f'Finished. Total time: {command_time_total}s'
|
||||
XmppMessage.send_reply(self, message, response_finished)
|
||||
|
||||
# if not response: response = 'EMPTY MESSAGE - ACTION ONLY'
|
||||
|
@ -651,10 +633,9 @@ class XmppChat:
|
|||
# jid_bare, response)
|
||||
|
||||
# print(
|
||||
# 'Message : {}\n'
|
||||
# 'JID : {}\n'
|
||||
# '{}\n'
|
||||
# .format(command, jid_bare, response)
|
||||
# f'Message : {command}\n'
|
||||
# f'JID : {jid_bare}\n'
|
||||
# f'{response}\n'
|
||||
# )
|
||||
|
||||
|
||||
|
@ -673,7 +654,7 @@ class XmppChatAction:
|
|||
Number. The default is None.
|
||||
"""
|
||||
function_name = sys._getframe().f_code.co_name
|
||||
logger.debug('{}: jid: {} num: {}'.format(function_name, jid_bare, num))
|
||||
logger.debug(f'{function_name}: jid: {jid_bare} num: {num}')
|
||||
db_file = config.get_pathname_to_database(jid_bare)
|
||||
encrypt_omemo = Config.get_setting_value(self, jid_bare, 'omemo')
|
||||
encrypted = True if encrypt_omemo else False
|
||||
|
@ -851,8 +832,7 @@ class XmppChatAction:
|
|||
|
||||
async def list_unread_entries(self, result, feed_title, jid):
|
||||
function_name = sys._getframe().f_code.co_name
|
||||
logger.debug('{}: feed_title: {} jid: {}'
|
||||
.format(function_name, feed_title, jid))
|
||||
logger.debug(f'{function_name}: feed_title: {feed_title} jid: {jid}')
|
||||
# TODO Add filtering
|
||||
# TODO Do this when entry is added to list and mark it as read
|
||||
# DONE!
|
||||
|
@ -868,7 +848,7 @@ class XmppChatAction:
|
|||
# print("accepted:", result[1])
|
||||
# results.extend([result])
|
||||
|
||||
# news_list = "You've got {} news items:\n".format(num)
|
||||
# news_list = f'You have got {num} news items:\n'
|
||||
# NOTE Why doesn't this work without list?
|
||||
# i.e. for result in results
|
||||
# for result in results.fetchall():
|
||||
|
@ -899,8 +879,7 @@ class XmppChatAction:
|
|||
link = Url.remove_tracking_parameters(link)
|
||||
link = await Url.replace_hostname(link, "link") or link
|
||||
feed_id = result[4]
|
||||
# news_item = ("\n{}\n{}\n{} [{}]\n").format(str(title), str(link),
|
||||
# str(feed_title), str(ix))
|
||||
# news_item = (f'\n{str(title)}\n{str(link)}\n{str(feed_title)} [{str(ix)}]\n')
|
||||
formatting = Config.get_setting_value(self, jid, 'formatting')
|
||||
news_item = formatting.format(feed_title=feed_title,
|
||||
title=title,
|
||||
|
@ -952,13 +931,12 @@ class XmppChatTask:
|
|||
return
|
||||
if jid_bare not in self.task_manager:
|
||||
self.task_manager[jid_bare] = {}
|
||||
logger.info('Creating new task manager for JID {}'.format(jid_bare))
|
||||
logger.info('Stopping task "interval" for JID {}'.format(jid_bare))
|
||||
logger.info(f'Creating new task manager for JID {jid_bare}')
|
||||
logger.info(f'Stopping task "interval" for JID {jid_bare}')
|
||||
try:
|
||||
self.task_manager[jid_bare]['interval'].cancel()
|
||||
except:
|
||||
logger.info('No task "interval" for JID {} (XmppChatTask.task_message)'
|
||||
.format(jid_bare))
|
||||
logger.info('Starting tasks "interval" for JID {}'.format(jid_bare))
|
||||
logger.info('No task "interval" for JID {jid_bare} (XmppChatTask.task_message)')
|
||||
logger.info('Starting tasks "interval" for JID {jid_bare}')
|
||||
self.task_manager[jid_bare]['interval'] = asyncio.create_task(
|
||||
XmppChatTask.task_message(self, jid_bare))
|
||||
|
|
|
@ -48,7 +48,7 @@ class XmppCommands:
|
|||
def print_help_list():
|
||||
command_list = Documentation.manual('commands.toml', section='all')
|
||||
message = ('Complete list of commands:\n'
|
||||
'```\n{}\n```'.format(command_list))
|
||||
f'```\n{command_list}\n```')
|
||||
return message
|
||||
|
||||
|
||||
|
@ -60,7 +60,7 @@ class XmppCommands:
|
|||
command_list = ''.join(command_list)
|
||||
message = (command_list)
|
||||
else:
|
||||
message = 'KeyError for {} {}'.format(command_root, command_name)
|
||||
message = f'KeyError for {command_root} {command_name}'
|
||||
return message
|
||||
|
||||
|
||||
|
@ -68,12 +68,11 @@ class XmppCommands:
|
|||
command_list = Documentation.manual('commands.toml', command)
|
||||
if command_list:
|
||||
command_list = ' '.join(command_list)
|
||||
message = ('Available command `{}` keys:\n'
|
||||
'```\n{}\n```\n'
|
||||
'Usage: `help {} <command>`'
|
||||
.format(command, command_list, command))
|
||||
message = (f'Available command `{command}` keys:\n'
|
||||
f'```\n{command_list}\n```\n'
|
||||
f'Usage: `help {command} <command>`')
|
||||
else:
|
||||
message = 'KeyError for {}'.format(command)
|
||||
message = f'KeyError for {command}'
|
||||
return message
|
||||
|
||||
|
||||
|
@ -93,7 +92,7 @@ class XmppCommands:
|
|||
# command_list = '\n'.join(command_list)
|
||||
message = (entries[entry]['info'])
|
||||
else:
|
||||
message = 'KeyError for {}'.format(entry)
|
||||
message = f'KeyError for {entry}'
|
||||
return message
|
||||
|
||||
|
||||
|
@ -187,18 +186,16 @@ class XmppCommands:
|
|||
# feed_id = feed_id[0]
|
||||
# await sqlite.mark_feed_as_read(db_file, feed_id)
|
||||
|
||||
message = ('> {}\n'
|
||||
message = (f'> {url}\n'
|
||||
'News source has been '
|
||||
'added to subscription list.'
|
||||
.format(url))
|
||||
'added to subscription list.')
|
||||
else:
|
||||
ix = exist[0]
|
||||
name = exist[1]
|
||||
message = ('> {}\n'
|
||||
'News source "{}" is already '
|
||||
message = (f'> {url}\n'
|
||||
f'News source "{name}" is already '
|
||||
'listed in the subscription list at '
|
||||
'index {}'
|
||||
.format(url, name, ix))
|
||||
f'index {ix}')
|
||||
else:
|
||||
message = ('No action has been taken. Missing URL.')
|
||||
return message
|
||||
|
@ -248,8 +245,8 @@ class XmppCommands:
|
|||
val_old = Config.get_setting_value(self, jid_bare, 'archive')
|
||||
await Config.set_setting_value(
|
||||
self, jid_bare, db_file, 'archive', val_new)
|
||||
message = ('Maximum archived items has been set to {} (was: {}).'
|
||||
.format(val_new, val_old))
|
||||
message = ('Maximum archived items has been set to {val_new} '
|
||||
'(was: {val_old}).')
|
||||
except:
|
||||
message = 'No action has been taken. Enter a numeric value only.'
|
||||
return message
|
||||
|
@ -257,15 +254,13 @@ class XmppCommands:
|
|||
|
||||
async def bookmark_add(self, muc_jid):
|
||||
await XmppBookmark.add(self, jid=muc_jid)
|
||||
message = ('Groupchat {} has been added to bookmarks.'
|
||||
.format(muc_jid))
|
||||
message = f'Groupchat {muc_jid} has been added to bookmarks.'
|
||||
return message
|
||||
|
||||
|
||||
async def bookmark_del(self, muc_jid):
|
||||
await XmppBookmark.remove(self, muc_jid)
|
||||
message = ('Groupchat {} has been removed from bookmarks.'
|
||||
.format(muc_jid))
|
||||
message = f'Groupchat {muc_jid} has been removed from bookmarks.'
|
||||
return message
|
||||
|
||||
|
||||
|
@ -274,8 +269,7 @@ class XmppCommands:
|
|||
self.settings[jid_bare][key] = None
|
||||
db_file = config.get_pathname_to_database(jid_bare)
|
||||
await sqlite.delete_setting(db_file, key)
|
||||
message = ('Setting {} has been restored to default value.'
|
||||
.format(key))
|
||||
message = f'Setting {key} has been restored to default value.'
|
||||
else:
|
||||
del self.settings[jid_bare]
|
||||
db_file = config.get_pathname_to_database(jid_bare)
|
||||
|
@ -286,7 +280,7 @@ class XmppCommands:
|
|||
|
||||
async def clear_filter(db_file, key):
|
||||
await sqlite.delete_filter(db_file, key)
|
||||
message = 'Filter {} has been purged.'.format(key)
|
||||
message = f'Filter {key} has been purged.'
|
||||
return message
|
||||
|
||||
|
||||
|
@ -294,11 +288,11 @@ class XmppCommands:
|
|||
conferences = await XmppBookmark.get_bookmarks(self)
|
||||
message = '\nList of groupchats:\n\n```\n'
|
||||
for conference in conferences:
|
||||
message += ('Name: {}\n'
|
||||
'Room: {}\n'
|
||||
'\n'
|
||||
.format(conference['name'], conference['jid']))
|
||||
message += ('```\nTotal of {} groupchats.\n'.format(len(conferences)))
|
||||
conference_name = conference['name']
|
||||
conference_jid = conference['jid']
|
||||
message += (f'Name: {conference_name}\n'
|
||||
f'Room: {conference_jid}\n\n')
|
||||
message += f'```\nTotal of {len(conferences)} groupchats.\n'
|
||||
return message
|
||||
|
||||
|
||||
|
@ -333,7 +327,7 @@ class XmppCommands:
|
|||
|
||||
def export_feeds(dir_cache, jid_bare, ext):
|
||||
pathname = Feed.export_feeds(dir_cache, jid_bare, ext)
|
||||
message = 'Feeds successfuly exported to {}.'.format(ext)
|
||||
message = f'Feeds successfuly exported to {ext}.'
|
||||
return pathname, message
|
||||
|
||||
|
||||
|
@ -347,8 +341,7 @@ class XmppCommands:
|
|||
result = await fetch.http(url)
|
||||
count = await Opml.import_from_file(db_file, result)
|
||||
if count:
|
||||
message = ('Successfully imported {} feeds.'
|
||||
.format(count))
|
||||
message = f'Successfully imported {count} feeds.'
|
||||
else:
|
||||
message = 'OPML file was not imported.'
|
||||
return message
|
||||
|
@ -360,7 +353,7 @@ class XmppCommands:
|
|||
for item in iq['disco_items']:
|
||||
item_id = item['node']
|
||||
item_name = item['name']
|
||||
message += 'Name: {}\nNode: {}\n\n'.format(item_name, item_id)
|
||||
message += f'Name: {item_name}\nNode: {item_id}\n\n'
|
||||
return message
|
||||
|
||||
|
||||
|
@ -403,8 +396,7 @@ class XmppCommands:
|
|||
break
|
||||
# task.clean_tasks_xmpp_chat(self, jid_bare, ['status'])
|
||||
status_type = 'dnd'
|
||||
status_message = ('📫️ Processing request to fetch data from {}'
|
||||
.format(url))
|
||||
status_message = '📫️ Processing request to fetch data from {url}'
|
||||
# pending_tasks_num = len(self.pending_tasks[jid_bare])
|
||||
pending_tasks_num = randrange(10000, 99999)
|
||||
self.pending_tasks[jid_bare][pending_tasks_num] = status_message
|
||||
|
@ -421,35 +413,36 @@ class XmppCommands:
|
|||
identifier)
|
||||
if isinstance(result, list):
|
||||
results = result
|
||||
message = "Syndication feeds found for {}\n\n```\n".format(url)
|
||||
message = f'Syndication feeds found for {url}\n\n```\n'
|
||||
for result in results:
|
||||
message += ("Title : {}\n"
|
||||
"Link : {}\n"
|
||||
"\n"
|
||||
.format(result['name'], result['link']))
|
||||
message += '```\nTotal of {} feeds.'.format(len(results))
|
||||
result_name = result['name']
|
||||
result_link = result['link']
|
||||
message += ('Title : {result_name}\n'
|
||||
'Link : {result_link}\n\n')
|
||||
message += '```\nTotal of {len(results)} feeds.'
|
||||
elif result['exist']:
|
||||
message = ('> {}\nNews source "{}" is already '
|
||||
result_link = result['link']
|
||||
result_name = result['name']
|
||||
result_index = result['index']
|
||||
message = (f'> {result_link}\nNews source "{result_name}" is already '
|
||||
'listed in the subscription list at '
|
||||
'index {}'
|
||||
.format(result['link'],
|
||||
result['name'],
|
||||
result['index']))
|
||||
f'index {result_index}')
|
||||
elif result['identifier']:
|
||||
message = ('> {}\nIdentifier "{}" is already '
|
||||
'allocated to index {}'
|
||||
.format(result['link'],
|
||||
result['identifier'],
|
||||
result['index']))
|
||||
result_link = result['link']
|
||||
result_identifier = result['identifier']
|
||||
result_index = result['index']
|
||||
message = (f'> {result_link}\nIdentifier "{result_identifier}" is already '
|
||||
f'allocated to index {result_index}')
|
||||
elif result['error']:
|
||||
message = ('> {}\nNo subscriptions were found. '
|
||||
'Reason: {} (status code: {})'
|
||||
.format(url, result['message'],
|
||||
result['code']))
|
||||
result_message = result['message']
|
||||
result_code = result['code']
|
||||
message = (f'> {url}\nNo subscriptions were found. '
|
||||
f'Reason: {result_message} (status code: {result_code})')
|
||||
else:
|
||||
message = ('> {}\nNews source "{}" has been '
|
||||
'added to subscription list.'
|
||||
.format(result['link'], result['name']))
|
||||
result_link = result['link']
|
||||
result_name = result['name']
|
||||
message = (f'> {result_link}\nNews source "{result_name}" has been '
|
||||
'added to subscription list.')
|
||||
# task.clean_tasks_xmpp_chat(self, jid_bare, ['status'])
|
||||
del self.pending_tasks[jid_bare][pending_tasks_num]
|
||||
# del self.pending_tasks[jid_bare][self.pending_tasks_counter]
|
||||
|
@ -457,9 +450,9 @@ class XmppCommands:
|
|||
XmppStatusTask.restart_task(self, jid_bare)
|
||||
# except:
|
||||
# response = (
|
||||
# '> {}\nNews source is in the process '
|
||||
# f'> {url}\nNews source is in the process '
|
||||
# 'of being added to the subscription '
|
||||
# 'list.'.format(url)
|
||||
# 'list.'
|
||||
# )
|
||||
else:
|
||||
message = ('No action has been taken.'
|
||||
|
@ -490,15 +483,13 @@ class XmppCommands:
|
|||
result = await Feed.add_feed(self, jid_bare, db_file, url, identifier)
|
||||
if isinstance(result, list):
|
||||
results = result
|
||||
message = ("Syndication feeds found for {}\n\n```\n"
|
||||
.format(url))
|
||||
message = f"Syndication feeds found for {url}\n\n```\n"
|
||||
for result in results:
|
||||
message += ("Title : {}\n"
|
||||
"Link : {}\n"
|
||||
"\n"
|
||||
.format(result['name'], result['link']))
|
||||
message += ('```\nTotal of {} feeds.'
|
||||
.format(len(results)))
|
||||
message += f'```\nTotal of {results} feeds.'
|
||||
elif result['exist']:
|
||||
message = ('> {}\nNews source "{}" is already '
|
||||
'listed in the subscription list at '
|
||||
|
@ -516,9 +507,9 @@ class XmppCommands:
|
|||
.format(result['link'], result['name']))
|
||||
# except:
|
||||
# response = (
|
||||
# '> {}\nNews source is in the process '
|
||||
# f'> {url}\nNews source is in the process '
|
||||
# 'of being added to the subscription '
|
||||
# 'list.'.format(url)
|
||||
# 'list.'
|
||||
# )
|
||||
return message
|
||||
|
||||
|
@ -532,12 +523,10 @@ class XmppCommands:
|
|||
message = ''
|
||||
if number:
|
||||
for id, title, url in feeds:
|
||||
message += ('\nName : {} [{}]'
|
||||
'\nURL : {}'
|
||||
'\n'
|
||||
.format(str(title), str(id), str(url)))
|
||||
message += (f'\nName : {str(title)} [{str(id)}]'
|
||||
f'\nURL : {str(url)}\n')
|
||||
elif query:
|
||||
message = "No feeds were found for: {}".format(query)
|
||||
message = f"No feeds were found for: {query}"
|
||||
else:
|
||||
url = Utilities.pick_a_feed()
|
||||
message = ('List of subscriptions is empty. '
|
||||
|
@ -559,8 +548,8 @@ class XmppCommands:
|
|||
val_old = Config.get_setting_value(self, jid_bare, 'interval')
|
||||
await Config.set_setting_value(
|
||||
self, jid_bare, db_file, 'interval', val_new)
|
||||
message = ('Updates will be sent every {} minutes '
|
||||
'(was: {}).'.format(val_new, val_old))
|
||||
message = (f'Updates will be sent every {val_new} minutes '
|
||||
f'(was: {val_old}).')
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
message = ('No action has been taken. Enter a numeric value only.')
|
||||
|
@ -580,12 +569,12 @@ class XmppCommands:
|
|||
result = await XmppMuc.join(self, muc_jid)
|
||||
# await XmppBookmark.add(self, jid=muc_jid)
|
||||
if result == 'ban':
|
||||
message = '{} is banned from {}'.format(self.alias, muc_jid)
|
||||
message = f'{self.alias} is banned from {muc_jid}'
|
||||
else:
|
||||
await XmppBookmark.add(self, muc_jid)
|
||||
message = 'Joined groupchat {}'.format(muc_jid)
|
||||
message = f'Joined groupchat {muc_jid}'
|
||||
else:
|
||||
message = '> {}\nGroupchat JID appears to be invalid.'.format(muc_jid)
|
||||
message = f'> {muc_jid}\nGroupchat JID appears to be invalid.'
|
||||
else:
|
||||
message = '> {}\nGroupchat JID is missing.'
|
||||
return message
|
||||
|
@ -606,11 +595,10 @@ class XmppCommands:
|
|||
if not val_new: # i.e. val_new == 0
|
||||
# TODO Add action to disable limit
|
||||
message = ('Summary length limit is disabled '
|
||||
'(was: {}).'.format(val_old))
|
||||
f'(was: {val_old}).')
|
||||
else:
|
||||
message = ('Summary maximum length is set to '
|
||||
'{} characters (was: {}).'
|
||||
.format(val_new, val_old))
|
||||
f'{val_new} characters (was: {val_old}).')
|
||||
except:
|
||||
message = ('No action has been taken.'
|
||||
'\n'
|
||||
|
@ -661,7 +649,7 @@ class XmppCommands:
|
|||
nid = info[1]
|
||||
if jid:
|
||||
XmppPubsub.delete_node(self, jid, nid)
|
||||
message = 'Deleted node: {}'.format(nid)
|
||||
message = f'Deleted node: {nid}'
|
||||
else:
|
||||
message = 'PubSub JID is missing. Enter PubSub JID.'
|
||||
else:
|
||||
|
@ -679,7 +667,7 @@ class XmppCommands:
|
|||
nid = info[1]
|
||||
if jid:
|
||||
XmppPubsub.purge_node(self, jid, nid)
|
||||
message = 'Purged node: {}'.format(nid)
|
||||
message = f'Purged node: {nid}'
|
||||
else:
|
||||
message = 'PubSub JID is missing. Enter PubSub JID.'
|
||||
else:
|
||||
|
@ -714,13 +702,12 @@ class XmppCommands:
|
|||
val_new = int(val)
|
||||
val_old = Config.get_setting_value(self, jid_bare, 'quantum')
|
||||
# response = (
|
||||
# 'Every update will contain {} news items.'
|
||||
# ).format(response)
|
||||
# f'Every update will contain {response} news items.'
|
||||
# )
|
||||
db_file = config.get_pathname_to_database(jid_bare)
|
||||
await Config.set_setting_value(
|
||||
self, jid_bare, db_file, 'quantum', val_new)
|
||||
message = ('Next update will contain {} news items (was: {}).'
|
||||
.format(val_new, val_old))
|
||||
message = f'Next update will contain {val_new} news items (was: {val_old}).'
|
||||
except:
|
||||
message = 'No action has been taken. Enter a numeric value only.'
|
||||
return message
|
||||
|
@ -754,25 +741,21 @@ class XmppCommands:
|
|||
result = await FeedDiscovery.probe_page(url, document)
|
||||
if isinstance(result, list):
|
||||
results = result
|
||||
message = ("Syndication feeds found for {}\n\n```\n"
|
||||
.format(url))
|
||||
message = f"Syndication feeds found for {url}\n\n```\n"
|
||||
for result in results:
|
||||
message += ("Title : {}\n"
|
||||
"Link : {}\n"
|
||||
"\n"
|
||||
.format(result['name'], result['link']))
|
||||
message += ('```\nTotal of {} feeds.'
|
||||
.format(len(results)))
|
||||
result_name = result['name']
|
||||
result_link = result['link']
|
||||
message += ("Title : {result_name}\n"
|
||||
"Link : {result_link}\n\n")
|
||||
message += f'```\nTotal of {results} feeds.'
|
||||
break
|
||||
elif not result:
|
||||
message = ('> {}\nNo subscriptions were found.'
|
||||
.format(url))
|
||||
message = f'> {url}\nNo subscriptions were found.'
|
||||
break
|
||||
else:
|
||||
url = result['link']
|
||||
else:
|
||||
message = ('> {}\nFailed to load URL. Reason: {}'
|
||||
.format(url, status))
|
||||
message = f'> {url}\nFailed to load URL. Reason: {status}'
|
||||
break
|
||||
else:
|
||||
message = ('No action has been taken. Missing URL.')
|
||||
|
@ -792,25 +775,21 @@ class XmppCommands:
|
|||
result = await FeedDiscovery.probe_page(url, document)
|
||||
if isinstance(result, list):
|
||||
results = result
|
||||
message = ("Syndication feeds found for {}\n\n```\n"
|
||||
.format(url))
|
||||
message = f"Syndication feeds found for {url}\n\n```\n"
|
||||
for result in results:
|
||||
message += ("Title : {}\n"
|
||||
"Link : {}\n"
|
||||
"\n"
|
||||
.format(result['name'], result['link']))
|
||||
message += ('```\nTotal of {} feeds.'
|
||||
.format(len(results)))
|
||||
result_name = result['name']
|
||||
result_link = result['link']
|
||||
message += (f"Title : {result_name}\n"
|
||||
f"Link : {result_link}\\n")
|
||||
message += f'```\nTotal of {len(results)} feeds.'
|
||||
break
|
||||
elif not result:
|
||||
message = ('> {}\nNo subscriptions were found.'
|
||||
.format(url))
|
||||
message = f'> {url}\nNo subscriptions were found.'
|
||||
break
|
||||
else:
|
||||
url = result['link']
|
||||
else:
|
||||
message = ('> {}\nFailed to load URL. Reason: {}'
|
||||
.format(url, status))
|
||||
message = f'> {url}\nFailed to load URL. Reason: {status}'
|
||||
break
|
||||
else:
|
||||
message = ('No action has been taken.'
|
||||
|
@ -837,7 +816,7 @@ class XmppCommands:
|
|||
message = ''
|
||||
for i in result:
|
||||
title, url, date = i
|
||||
message += ('\n{}\n{}\n'.format(title, url))
|
||||
message += f'\n{title}\n{url}\n'
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
count = False
|
||||
|
@ -877,13 +856,13 @@ class XmppCommands:
|
|||
if len(sub_removed):
|
||||
message += '\nThe following subscriptions have been removed:\n\n'
|
||||
for url in sub_removed:
|
||||
message += '{}\n'.format(url)
|
||||
message += f'{url}\n'
|
||||
if len(url_invalid):
|
||||
urls = ', '.join(url_invalid)
|
||||
message += '\nThe following URLs do not exist:\n\n{}\n'.format(urls)
|
||||
message += f'\nThe following URLs do not exist:\n\n{urls}\n'
|
||||
if len(ixs_invalid):
|
||||
ixs = ', '.join(ixs_invalid)
|
||||
message += '\nThe following indexes do not exist:\n\n{}\n'.format(ixs)
|
||||
message += f'\nThe following indexes do not exist:\n\n{ixs}\n'
|
||||
message += '\n```'
|
||||
else:
|
||||
message = ('No action has been taken.'
|
||||
|
@ -924,13 +903,13 @@ class XmppCommands:
|
|||
if len(sub_marked):
|
||||
message += '\nThe following subscriptions have been marked as read:\n\n'
|
||||
for url in sub_marked:
|
||||
message += '{}\n'.format(url)
|
||||
message += f'{url}\n'
|
||||
if len(url_invalid):
|
||||
urls = ', '.join(url_invalid)
|
||||
message += '\nThe following URLs do not exist:\n\n{}\n'.format(urls)
|
||||
message += f'\nThe following URLs do not exist:\n\n{urls}\n'
|
||||
if len(ixs_invalid):
|
||||
ixs = ', '.join(ixs_invalid)
|
||||
message += '\nThe following indexes do not exist:\n\n{}\n'.format(ixs)
|
||||
message += f'\nThe following indexes do not exist:\n\n{ixs}\n'
|
||||
message += '\n```'
|
||||
else:
|
||||
await sqlite.mark_all_as_read(db_file)
|
||||
|
@ -942,20 +921,17 @@ class XmppCommands:
|
|||
if query:
|
||||
if len(query) > 3:
|
||||
results = sqlite.search_entries(db_file, query)
|
||||
message = ("Search results for '{}':\n\n```"
|
||||
.format(query))
|
||||
message = f"Search results for '{query}':\n\n```"
|
||||
for result in results:
|
||||
message += ("\n{}\n{}\n"
|
||||
.format(str(result[0]), str(result[1])))
|
||||
message += f'\n{str(result[0])}\n{str(result[1])}\n'
|
||||
if len(results):
|
||||
message += "```\nTotal of {} results".format(len(results))
|
||||
message += f'```\nTotal of {len(results)} results'
|
||||
else:
|
||||
message = "No results were found for: {}".format(query)
|
||||
message = f'No results were found for: {query}'
|
||||
else:
|
||||
message = 'Enter at least 4 characters to search'
|
||||
else:
|
||||
message = ('No action has been taken.'
|
||||
'\n'
|
||||
message = ('No action has been taken.\n'
|
||||
'Missing search query.')
|
||||
return message
|
||||
|
||||
|
@ -1010,12 +986,9 @@ class XmppCommands:
|
|||
"\n"
|
||||
"```"
|
||||
"\n"
|
||||
"News items : {}/{}\n"
|
||||
"News sources : {}/{}\n"
|
||||
"```").format(entries_unread,
|
||||
entries,
|
||||
feeds_active,
|
||||
feeds_all)
|
||||
f"News items : {entries_unread}/{entries}\n"
|
||||
f"News sources : {feeds_active}/{feeds_all}\n"
|
||||
"```")
|
||||
return message
|
||||
|
||||
|
||||
|
@ -1028,11 +1001,9 @@ class XmppCommands:
|
|||
name = name[0]
|
||||
addr = sqlite.get_feed_url(db_file, feed_id)
|
||||
addr = addr[0]
|
||||
message = ('Updates are now disabled for subscription:\n{}\n{}'
|
||||
.format(addr, name))
|
||||
message = f'Updates are now disabled for subscription:\n{addr}\n{name}'
|
||||
except:
|
||||
message = ('No action has been taken. No news source with index {}.'
|
||||
.format(feed_id))
|
||||
message = f'No action has been taken. No news source with index {feed_id}.'
|
||||
XmppStatusTask.restart_task(self, jid_bare)
|
||||
return message
|
||||
|
||||
|
@ -1043,13 +1014,11 @@ class XmppCommands:
|
|||
await sqlite.set_enabled_status(db_file, feed_id, 1)
|
||||
name = sqlite.get_feed_title(db_file, feed_id)[0]
|
||||
addr = sqlite.get_feed_url(db_file, feed_id)[0]
|
||||
message = ('> {}\n'
|
||||
'Updates are now enabled for news source "{}"'
|
||||
.format(addr, name))
|
||||
message = (f'> {addr}\n'
|
||||
f'Updates are now enabled for news source "{name}"')
|
||||
except:
|
||||
message = ('No action has been taken.'
|
||||
'\n'
|
||||
'No news source with index {}.'.format(feed_id))
|
||||
message = ('No action has been taken.\n'
|
||||
f'No news source with index {feed_id}.')
|
||||
return message
|
||||
|
||||
|
||||
|
@ -1071,13 +1040,11 @@ class XmppCommands:
|
|||
else:
|
||||
await sqlite.set_feed_title(db_file, feed_id,
|
||||
name)
|
||||
message = ('> {}'
|
||||
'\n'
|
||||
'Subscription #{} has been '
|
||||
'renamed to "{}".'.format(
|
||||
name_old,feed_id, name))
|
||||
message = (f'> {name_old}\n'
|
||||
f'Subscription #{feed_id} has been '
|
||||
f'renamed to "{name}".')
|
||||
else:
|
||||
message = 'Subscription with Id {} does not exist.'.format(feed_id)
|
||||
message = f'Subscription with Id {feed_id} does not exist.'
|
||||
except:
|
||||
message = ('No action has been taken.'
|
||||
'\n'
|
||||
|
@ -1130,7 +1097,7 @@ class XmppCommands:
|
|||
|
||||
def print_support_jid():
|
||||
muc_jid = 'slixfeed@chat.woodpeckersnest.space'
|
||||
message = 'Join xmpp:{}?join'.format(muc_jid)
|
||||
message = f'Join xmpp:{muc_jid}?join'
|
||||
return message
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue