Reduce amount of Python keywords async and await

This commit is contained in:
Schimon Jehudah 2024-03-08 09:14:36 +00:00
parent 8388cf5084
commit ae89521d9b
7 changed files with 164 additions and 162 deletions

View file

@ -97,7 +97,7 @@ async def export_feeds(self, jid, jid_file, ext):
filename = os.path.join(
cache_dir, ext, 'slixfeed_' + dt.timestamp() + '.' + ext)
db_file = config.get_pathname_to_database(jid_file)
results = await sqlite.get_feeds(db_file)
results = sqlite.get_feeds(db_file)
match ext:
# case 'html':
# response = 'Not yet implemented.'
@ -128,13 +128,13 @@ async def xmpp_send_status(self, jid):
status_mode = 'xa'
status_text = '📪️ Send "Start" to receive updates'
else:
feeds = await sqlite.get_number_of_items(db_file, 'feeds')
feeds = sqlite.get_number_of_items(db_file, 'feeds')
# print(await current_time(), jid, "has", feeds, "feeds")
if not feeds:
status_mode = 'available'
status_text = '📪️ Send a URL from a blog or a news website'
else:
unread = await sqlite.get_number_of_entries_unread(db_file)
unread = sqlite.get_number_of_entries_unread(db_file)
if unread:
status_mode = 'chat'
status_text = '📬️ There are {} news items'.format(str(unread))
@ -182,7 +182,7 @@ async def xmpp_send_update(self, jid, num=None):
num = self.settings[jid]['quantum'] or self.settings['default']['quantum']
else:
num = int(num)
results = await sqlite.get_unread_entries(db_file, num)
results = sqlite.get_unread_entries(db_file, num)
news_digest = ''
media = None
chat_type = await get_chat_type(self, jid)
@ -290,6 +290,7 @@ 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:
@ -580,12 +581,12 @@ async def list_statistics(db_file):
function_name = sys._getframe().f_code.co_name
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
entries_unread = await sqlite.get_number_of_entries_unread(db_file)
entries = await sqlite.get_number_of_items(db_file, 'entries')
archive = await sqlite.get_number_of_items(db_file, 'archive')
entries_unread = sqlite.get_number_of_entries_unread(db_file)
entries = sqlite.get_number_of_items(db_file, 'entries')
archive = sqlite.get_number_of_items(db_file, 'archive')
entries_all = entries + archive
feeds_active = await sqlite.get_number_of_feeds_active(db_file)
feeds_all = await sqlite.get_number_of_items(db_file, 'feeds')
feeds_active = sqlite.get_number_of_feeds_active(db_file)
feeds_all = sqlite.get_number_of_items(db_file, 'feeds')
# msg = """You have {} unread news items out of {} from {} news sources.
# """.format(unread_entries, entries, feeds)
@ -726,8 +727,7 @@ async def import_opml(db_file, url):
if not result['error']:
document = result['content']
root = ET.fromstring(document)
before = await sqlite.get_number_of_items(
db_file, 'feeds')
before = sqlite.get_number_of_items(db_file, 'feeds')
feeds = []
for child in root.findall(".//outline"):
url = child.get("xmlUrl")
@ -737,8 +737,7 @@ async def import_opml(db_file, url):
feeds.extend([(url, title)])
await sqlite.import_feeds(db_file, feeds)
await sqlite.add_metadata(db_file)
after = await sqlite.get_number_of_items(
db_file, 'feeds')
after = sqlite.get_number_of_items(db_file, 'feeds')
difference = int(after) - int(before)
return difference
@ -748,7 +747,7 @@ async def add_feed(self, jid_bare, db_file, url):
logger.debug('{}: db_file: {} url: {}'
.format(function_name, db_file, url))
while True:
exist = await sqlite.get_feed_id_and_name(db_file, url)
exist = sqlite.get_feed_id_and_name(db_file, url)
if not exist:
status_code = None
result = await fetch.http(url)
@ -790,7 +789,7 @@ async def add_feed(self, jid_bare, db_file, url):
updated=updated)
await scan(self, jid_bare, db_file, url)
old = self.settings[jid_bare]['old'] or self.settings['default']['old']
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]
if not old:
await sqlite.mark_feed_as_read(db_file, feed_id)
@ -841,7 +840,7 @@ async def add_feed(self, jid_bare, db_file, url):
await scan_json(self, jid_bare, db_file, url)
old = self.settings[jid_bare]['old'] or self.settings['default']['old']
if not old:
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]
await sqlite.mark_feed_as_read(db_file, feed_id)
result_final = {'link' : url,
@ -926,7 +925,7 @@ async def scan_json(self, jid_bare, db_file, url):
entries = feed["items"]
await remove_nonexistent_entries_json(self, jid_bare, db_file, url, feed)
try:
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]
# await sqlite.update_feed_validity(
# db_file, feed_id, valid)
@ -938,7 +937,7 @@ async def scan_json(self, jid_bare, db_file, url):
updated = ''
else:
updated = ''
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]
await sqlite.update_feed_properties(
db_file, feed_id, len(feed["items"]), updated)
@ -972,7 +971,7 @@ async def scan_json(self, jid_bare, db_file, url):
# title = "{}: *{}*".format(feed["feed"]["title"], entry.title)
title = entry["title"] if "title" in entry.keys() else date
entry_id = entry["id"] if "id" in entry.keys() else link
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]
exist = sqlite.check_entry_exist(db_file, feed_id,
entry_id=entry_id,
@ -1046,7 +1045,7 @@ async def scan_json(self, jid_bare, db_file, url):
# url, date, read_status)
# await sqlite.set_date(db_file, url)
if len(new_entries):
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]
await sqlite.add_entries_and_update_timestamp(db_file, feed_id,
new_entries)
@ -1203,7 +1202,7 @@ async def scan(self, jid_bare, db_file, url):
.format(function_name, db_file, url))
if isinstance(url, tuple): url = url[0]
result = await fetch.http(url)
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]
status_code = result['status_code']
await sqlite.update_feed_status(db_file, feed_id, status_code)
@ -1227,7 +1226,7 @@ async def scan(self, jid_bare, db_file, url):
valid = 0
else:
valid = 1
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]
await sqlite.update_feed_validity(
db_file, feed_id, valid)
@ -1239,7 +1238,7 @@ async def scan(self, jid_bare, db_file, url):
updated = ''
else:
updated = ''
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]
await sqlite.update_feed_properties(db_file, feed_id,
len(feed["entries"]), updated)
@ -1268,7 +1267,7 @@ async def scan(self, jid_bare, db_file, url):
# title = "{}: *{}*".format(feed["feed"]["title"], entry.title)
title = entry.title if entry.has_key("title") else date
entry_id = entry.id if entry.has_key("id") else link
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]
exist = sqlite.check_entry_exist(db_file, feed_id,
entry_id=entry_id,
@ -1337,7 +1336,7 @@ async def scan(self, jid_bare, db_file, url):
# url, date, read_status)
# await sqlite.set_date(db_file, url)
if len(new_entries):
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]
await sqlite.add_entries_and_update_timestamp(db_file, feed_id,
new_entries)
@ -1605,9 +1604,9 @@ async def remove_nonexistent_entries(self, jid_bare, db_file, url, feed):
function_name = sys._getframe().f_code.co_name
logger.debug('{}: db_file: {} url: {}'
.format(function_name, db_file, url))
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]
items = await sqlite.get_entries_of_feed(db_file, feed_id)
items = sqlite.get_entries_of_feed(db_file, feed_id)
entries = feed.entries
limit = self.settings[jid_bare]['archive'] or self.settings['default']['archive']
for item in items:
@ -1714,9 +1713,9 @@ async def remove_nonexistent_entries_json(self, jid_bare, db_file, url, feed):
function_name = sys._getframe().f_code.co_name
logger.debug('{}: db_file: {}: url: {}'
.format(function_name, db_file, url))
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]
items = await sqlite.get_entries_of_feed(db_file, feed_id)
items = sqlite.get_entries_of_feed(db_file, feed_id)
entries = feed["items"]
limit = self.settings[jid_bare]['archive'] or self.settings['default']['archive']
for item in items:

View file

@ -989,7 +989,7 @@ async def set_new_tag(db_file, tag):
cur.execute(sql, par)
async def get_feed_id_and_name(db_file, url):
def get_feed_id_and_name(db_file, url):
"""
Get Id and Name of feed.
Check whether a feed exists.
@ -1024,7 +1024,7 @@ async def get_feed_id_and_name(db_file, url):
return result
async def get_number_of_items(db_file, table):
def get_number_of_items(db_file, table):
"""
Return number of entries or feeds.
@ -1055,7 +1055,7 @@ async def get_number_of_items(db_file, table):
return count
async def get_number_of_feeds_active(db_file):
def get_number_of_feeds_active(db_file):
"""
Return number of active feeds.
@ -1085,7 +1085,7 @@ async def get_number_of_feeds_active(db_file):
return count
async def get_number_of_entries_unread(db_file):
def get_number_of_entries_unread(db_file):
"""
Return number of unread items.
@ -1122,7 +1122,7 @@ async def get_number_of_entries_unread(db_file):
return count
async def get_unread_entries(db_file, num):
def get_unread_entries(db_file, num):
"""
Extract information from unread entries.
@ -1193,7 +1193,7 @@ def get_feed_id_by_entry_index(db_file, ix):
return feed_id
async def get_feed_id(db_file, url):
def get_feed_id(db_file, url):
"""
Get index of given feed.
@ -1572,9 +1572,9 @@ async def update_statistics(cur):
function_name = sys._getframe().f_code.co_name
logger.debug('{}'.format(function_name))
stat_dict = {}
stat_dict["feeds"] = await get_number_of_items(cur, 'feeds')
stat_dict["entries"] = await get_number_of_items(cur, 'entries')
stat_dict["unread"] = await get_number_of_entries_unread(cur=cur)
stat_dict["feeds"] = get_number_of_items(cur, 'feeds')
stat_dict["entries"] = get_number_of_items(cur, 'entries')
stat_dict["unread"] = get_number_of_entries_unread(cur=cur)
for i in stat_dict:
sql = (
"SELECT id "
@ -1959,7 +1959,7 @@ async def maintain_archive(db_file, limit):
# NOTE Entries that are read from archive are deleted.
# NOTE Unlike entries from table entries, entries from
# table archive are not marked as read.
async def get_entries_of_feed(db_file, feed_id):
def get_entries_of_feed(db_file, feed_id):
"""
Get entries of given feed.
@ -1989,7 +1989,7 @@ async def get_entries_of_feed(db_file, feed_id):
# TODO What is this function for? 2024-01-02
# async def get_feeds(db_file):
# def get_feeds(db_file):
# """
# Query table feeds for Title, URL, Categories, Tags.
@ -2014,7 +2014,7 @@ async def get_entries_of_feed(db_file, feed_id):
# TODO select by "feed_id" (of table "status") from
# "feed" urls that are enabled in table "status"
async def get_feeds_url(db_file):
def get_feeds_url(db_file):
"""
Query table feeds for URLs.
@ -2081,7 +2081,7 @@ def get_feeds_by_enabled_state(db_file, enabled_state):
return result
async def get_active_feeds_url(db_file):
def get_active_feeds_url(db_file):
"""
Query table feeds for active URLs.
@ -2141,7 +2141,7 @@ def get_tags(db_file):
return result
async def get_feeds(db_file):
def get_feeds(db_file):
"""
Query table feeds and list items.
@ -2175,7 +2175,7 @@ async def get_feeds(db_file):
return result
async def last_entries(db_file, num):
def get_last_entries(db_file, num):
"""
Query entries.
@ -2789,25 +2789,26 @@ async def set_last_update_time(db_file):
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 = (
"""
INSERT
INTO status(
key, value)
VALUES(
:key, :value)
"""
)
par = {
"key": "last_update",
"value": time.time()
}
cur.execute(sql, par)
async with DBLOCK:
with create_connection(db_file) as conn:
cur = conn.cursor()
sql = (
"""
INSERT
INTO status(
key, value)
VALUES(
:key, :value)
"""
)
par = {
"key": "last_update",
"value": time.time()
}
cur.execute(sql, par)
async def get_last_update_time(db_file):
def get_last_update_time(db_file):
"""
Get value of last_update.
@ -2859,19 +2860,20 @@ async def update_last_update_time(db_file):
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 = (
"""
UPDATE status
SET value = :value
WHERE key = "last_update"
"""
)
par = {
"value": time.time()
}
cur.execute(sql, par)
async with DBLOCK:
with create_connection(db_file) as conn:
cur = conn.cursor()
sql = (
"""
UPDATE status
SET value = :value
WHERE key = "last_update"
"""
)
par = {
"value": time.time()
}
cur.execute(sql, par)
########################################

View file

@ -164,7 +164,7 @@ async def start_tasks_xmpp(self, jid_bare, tasks=None):
async def task_status(self, jid):
await action.xmpp_send_status(self, jid)
await refresh_task(self, jid, task_status, 'status', '90')
refresh_task(self, jid, task_status, 'status', '90')
async def task_send(self, jid_bare):
@ -174,7 +174,7 @@ async def task_send(self, jid_bare):
Config.add_settings_jid(self.settings, jid_bare, db_file)
update_interval = self.settings[jid_bare]['interval'] or self.settings['default']['interval']
update_interval = 60 * int(update_interval)
last_update_time = await sqlite.get_last_update_time(db_file)
last_update_time = sqlite.get_last_update_time(db_file)
if last_update_time:
last_update_time = float(last_update_time)
diff = time.time() - last_update_time
@ -196,7 +196,7 @@ async def task_send(self, jid_bare):
else:
await sqlite.set_last_update_time(db_file)
await action.xmpp_send_update(self, jid_bare)
await refresh_task(self, jid_bare, task_send, 'interval')
refresh_task(self, jid_bare, task_send, 'interval')
await start_tasks_xmpp(self, jid_bare, ['status'])
@ -213,7 +213,7 @@ def clean_tasks_xmpp(self, jid, tasks=None):
.format(task, jid))
async def refresh_task(self, jid_bare, callback, key, val=None):
def refresh_task(self, jid_bare, callback, key, val=None):
"""
Apply new setting at runtime.
@ -281,7 +281,7 @@ async def check_updates(self, jid):
while True:
jid_file = jid.replace('/', '_')
db_file = config.get_pathname_to_database(jid_file)
urls = await sqlite.get_active_feeds_url(db_file)
urls = sqlite.get_active_feeds_url(db_file)
for url in urls:
await action.scan(self, jid, db_file, url)
val = self.settings['default']['check']

View file

@ -256,20 +256,21 @@ class Slixfeed(slixmpp.ClientXMPP):
function_name = sys._getframe().f_code.co_name
message_log = '{}'
logger.debug(message_log.format(function_name))
# self.send_presence()
bookmarks = await self.plugin['xep_0048'].get_bookmarks()
XmppGroupchat.autojoin(self, bookmarks)
jid_operator = config.get_value('accounts', 'XMPP', 'operator')
if jid_operator:
status_message = 'Slixfeed version {}'.format(__version__)
status_message = ('Wait while Slixfeed {} is being loaded...'
.format(__version__))
XmppPresence.send(self, jid_operator, status_message)
await profile.update(self)
profile.set_identity(self, 'client')
await self['xep_0115'].update_caps()
# self.send_presence()
# await self.get_roster()
bookmarks = await self.plugin['xep_0048'].get_bookmarks()
XmppGroupchat.autojoin(self, bookmarks)
# XmppCommand.adhoc_commands(self)
self.adhoc_commands()
self.service_reactions()
await self['xep_0115'].update_caps()
await self.get_roster()
await profile.update(self)
# self.service_reactions()
task.task_ping(self)
time_end = time.time()
difference = time_end - time_begin
@ -721,21 +722,21 @@ class Slixfeed(slixmpp.ClientXMPP):
.format(jid_bare))
form.add_field(ftype='fixed',
value='News')
feeds_all = str(await sqlite.get_number_of_items(db_file, 'feeds'))
feeds_all = str(sqlite.get_number_of_items(db_file, 'feeds'))
form.add_field(label='Subscriptions',
ftype='text-single',
value=feeds_all)
feeds_act = str(await sqlite.get_number_of_feeds_active(db_file))
feeds_act = str(sqlite.get_number_of_feeds_active(db_file))
form.add_field(label='Active',
ftype='text-single',
value=feeds_act)
entries = await sqlite.get_number_of_items(db_file, 'entries')
archive = await sqlite.get_number_of_items(db_file, 'archive')
entries = sqlite.get_number_of_items(db_file, 'entries')
archive = sqlite.get_number_of_items(db_file, 'archive')
entries_all = str(entries + archive)
form.add_field(label='Items',
ftype='text-single',
value=entries_all)
unread = str(await sqlite.get_number_of_entries_unread(db_file))
unread = str(sqlite.get_number_of_entries_unread(db_file))
form.add_field(label='Unread',
ftype='text-single',
value=unread)
@ -779,7 +780,7 @@ class Slixfeed(slixmpp.ClientXMPP):
update_interval = self.settings[jid_bare]['interval'] or self.settings['default']['interval']
update_interval = str(update_interval)
update_interval = 60 * int(update_interval)
last_update_time = await sqlite.get_last_update_time(db_file)
last_update_time = sqlite.get_last_update_time(db_file)
if last_update_time:
last_update_time = float(last_update_time)
dt_object = datetime.fromtimestamp(last_update_time)
@ -979,11 +980,11 @@ class Slixfeed(slixmpp.ClientXMPP):
num = 100
match payload['values']['action']:
case 'all':
results = await sqlite.get_entries(db_file, num) # FIXME
results = sqlite.get_entries(db_file, num) # FIXME
case 'rejected':
results = await sqlite.get_entries_rejected(db_file, num) # FIXME
results = sqlite.get_entries_rejected(db_file, num) # FIXME
case 'unread':
results = await sqlite.get_unread_entries(db_file, num)
results = sqlite.get_unread_entries(db_file, num)
if results:
form = self['xep_0004'].make_form('form', 'Updates')
form['instructions'] = 'Recent {} updates'.format(num)
@ -1539,7 +1540,7 @@ class Slixfeed(slixmpp.ClientXMPP):
label='Subscription',
desc=('Select a subscription to edit.'),
required=True)
subscriptions = await sqlite.get_feeds(db_file)
subscriptions = sqlite.get_feeds(db_file)
subscriptions = sorted(subscriptions, key=lambda x: x[0])
for subscription in subscriptions:
title = subscription[0]
@ -1558,7 +1559,7 @@ class Slixfeed(slixmpp.ClientXMPP):
label='Subscriptions',
desc=('Select subscriptions to remove.'),
required=True)
subscriptions = await sqlite.get_feeds(db_file)
subscriptions = sqlite.get_feeds(db_file)
subscriptions = sorted(subscriptions, key=lambda x: x[0])
for subscription in subscriptions:
title = subscription[0]
@ -1672,7 +1673,7 @@ class Slixfeed(slixmpp.ClientXMPP):
# label='Interval period')
jid_file = jid_bare
db_file = config.get_pathname_to_database(jid_file)
subscriptions = await sqlite.get_feeds(db_file)
subscriptions = sqlite.get_feeds(db_file)
# subscriptions = set(subscriptions)
categorized_subscriptions = {}
for subscription in subscriptions:
@ -1732,7 +1733,7 @@ class Slixfeed(slixmpp.ClientXMPP):
# elif isinstance(urls, str):
else:
url = urls
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
if feed_id:
feed_id = feed_id[0]
title = sqlite.get_feed_title(db_file, feed_id)
@ -1812,7 +1813,7 @@ class Slixfeed(slixmpp.ClientXMPP):
jid_file = jid_bare
db_file = config.get_pathname_to_database(jid_file)
# url = values['url']
# feed_id = await sqlite.get_feed_id(db_file, url)
# feed_id = sqlite.get_feed_id(db_file, url)
# feed_id = feed_id[0]
# if feed_id: feed_id = feed_id[0]
feed_id = values['id']
@ -1888,7 +1889,7 @@ class Slixfeed(slixmpp.ClientXMPP):
required=True)
jid_file = jid_bare
db_file = config.get_pathname_to_database(jid_file)
subscriptions = await sqlite.get_feeds(db_file)
subscriptions = sqlite.get_feeds(db_file)
subscriptions = sorted(subscriptions, key=lambda x: x[0])
for subscription in subscriptions:
title = subscription[0]
@ -2361,7 +2362,7 @@ class Slixfeed(slixmpp.ClientXMPP):
jid_bare = session['from'].bare
jid_file = jid_bare
db_file = config.get_pathname_to_database(jid_file)
subscriptions = await sqlite.get_feeds(db_file)
subscriptions = sqlite.get_feeds(db_file)
subscriptions = sorted(subscriptions, key=lambda x: x[0])
form = self['xep_0004'].make_form('form', 'Subscriptions')
match payload['values']['action']:

View file

@ -96,21 +96,21 @@ class XmppCommand:
.format(jid_bare))
form.add_field(ftype='fixed',
value='News')
feeds_all = str(await sqlite.get_number_of_items(db_file, 'feeds'))
feeds_all = str(sqlite.get_number_of_items(db_file, 'feeds'))
form.add_field(label='Subscriptions',
ftype='text-single',
value=feeds_all)
feeds_act = str(await sqlite.get_number_of_feeds_active(db_file))
feeds_act = str(sqlite.get_number_of_feeds_active(db_file))
form.add_field(label='Active',
ftype='text-single',
value=feeds_act)
entries = await sqlite.get_number_of_items(db_file, 'entries')
archive = await sqlite.get_number_of_items(db_file, 'archive')
entries = sqlite.get_number_of_items(db_file, 'entries')
archive = sqlite.get_number_of_items(db_file, 'archive')
entries_all = str(entries + archive)
form.add_field(label='Items',
ftype='text-single',
value=entries_all)
unread = str(await sqlite.get_number_of_entries_unread(db_file))
unread = str(sqlite.get_number_of_entries_unread(db_file))
form.add_field(label='Unread',
ftype='text-single',
value=unread)
@ -154,7 +154,7 @@ class XmppCommand:
update_interval = self.settings[jid_bare]['interval'] or self.settings['default']['interval']
update_interval = str(update_interval)
update_interval = 60 * int(update_interval)
last_update_time = await sqlite.get_last_update_time(db_file)
last_update_time = sqlite.get_last_update_time(db_file)
if last_update_time:
last_update_time = float(last_update_time)
dt_object = datetime.fromtimestamp(last_update_time)
@ -354,11 +354,11 @@ class XmppCommand:
num = 100
match payload['values']['action']:
case 'all':
results = await sqlite.get_entries(db_file, num) # FIXME
results = sqlite.get_entries(db_file, num) # FIXME
case 'rejected':
results = await sqlite.get_entries_rejected(db_file, num) # FIXME
results = sqlite.get_entries_rejected(db_file, num) # FIXME
case 'unread':
results = await sqlite.get_unread_entries(db_file, num)
results = sqlite.get_unread_entries(db_file, num)
if results:
form = self['xep_0004'].make_form('form', 'Updates')
form['instructions'] = 'Recent {} updates'.format(num)
@ -914,7 +914,7 @@ class XmppCommand:
label='Subscription',
desc=('Select a subscription to edit.'),
required=True)
subscriptions = await sqlite.get_feeds(db_file)
subscriptions = sqlite.get_feeds(db_file)
subscriptions = sorted(subscriptions, key=lambda x: x[0])
for subscription in subscriptions:
title = subscription[0]
@ -933,7 +933,7 @@ class XmppCommand:
label='Subscriptions',
desc=('Select subscriptions to remove.'),
required=True)
subscriptions = await sqlite.get_feeds(db_file)
subscriptions = sqlite.get_feeds(db_file)
subscriptions = sorted(subscriptions, key=lambda x: x[0])
for subscription in subscriptions:
title = subscription[0]
@ -1047,7 +1047,7 @@ class XmppCommand:
# label='Interval period')
jid_file = jid_bare
db_file = config.get_pathname_to_database(jid_file)
subscriptions = await sqlite.get_feeds(db_file)
subscriptions = sqlite.get_feeds(db_file)
# subscriptions = set(subscriptions)
categorized_subscriptions = {}
for subscription in subscriptions:
@ -1107,7 +1107,7 @@ class XmppCommand:
# elif isinstance(urls, str):
else:
url = urls
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
if feed_id:
feed_id = feed_id[0]
title = sqlite.get_feed_title(db_file, feed_id)
@ -1187,7 +1187,7 @@ class XmppCommand:
jid_file = jid_bare
db_file = config.get_pathname_to_database(jid_file)
# url = values['url']
# feed_id = await sqlite.get_feed_id(db_file, url)
# feed_id = sqlite.get_feed_id(db_file, url)
# feed_id = feed_id[0]
# if feed_id: feed_id = feed_id[0]
feed_id = values['id']
@ -1263,7 +1263,7 @@ class XmppCommand:
required=True)
jid_file = jid_bare
db_file = config.get_pathname_to_database(jid_file)
subscriptions = await sqlite.get_feeds(db_file)
subscriptions = sqlite.get_feeds(db_file)
subscriptions = sorted(subscriptions, key=lambda x: x[0])
for subscription in subscriptions:
title = subscription[0]
@ -1736,7 +1736,7 @@ class XmppCommand:
jid_bare = session['from'].bare
jid_file = jid_bare
db_file = config.get_pathname_to_database(jid_file)
subscriptions = await sqlite.get_feeds(db_file)
subscriptions = sqlite.get_feeds(db_file)
subscriptions = sorted(subscriptions, key=lambda x: x[0])
form = self['xep_0004'].make_form('form', 'Subscriptions')
match payload['values']['action']:

View file

@ -681,21 +681,21 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
.format(jid_bare))
form.add_field(ftype='fixed',
value='News')
feeds_all = str(await sqlite.get_number_of_items(db_file, 'feeds'))
feeds_all = str(sqlite.get_number_of_items(db_file, 'feeds'))
form.add_field(label='Subscriptions',
ftype='text-single',
value=feeds_all)
feeds_act = str(await sqlite.get_number_of_feeds_active(db_file))
feeds_act = str(sqlite.get_number_of_feeds_active(db_file))
form.add_field(label='Active',
ftype='text-single',
value=feeds_act)
entries = await sqlite.get_number_of_items(db_file, 'entries')
archive = await sqlite.get_number_of_items(db_file, 'archive')
entries = sqlite.get_number_of_items(db_file, 'entries')
archive = sqlite.get_number_of_items(db_file, 'archive')
entries_all = str(entries + archive)
form.add_field(label='Items',
ftype='text-single',
value=entries_all)
unread = str(await sqlite.get_number_of_entries_unread(db_file))
unread = str(sqlite.get_number_of_entries_unread(db_file))
form.add_field(label='Unread',
ftype='text-single',
value=unread)
@ -739,7 +739,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
update_interval = self.settings[jid_bare]['interval'] or self.settings['default']['interval']
update_interval = str(update_interval)
update_interval = 60 * int(update_interval)
last_update_time = await sqlite.get_last_update_time(db_file)
last_update_time = sqlite.get_last_update_time(db_file)
if last_update_time:
last_update_time = float(last_update_time)
dt_object = datetime.fromtimestamp(last_update_time)
@ -939,11 +939,11 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
num = 100
match payload['values']['action']:
case 'all':
results = await sqlite.get_entries(db_file, num) # FIXME
results = sqlite.get_entries(db_file, num) # FIXME
case 'rejected':
results = await sqlite.get_entries_rejected(db_file, num) # FIXME
results = sqlite.get_entries_rejected(db_file, num) # FIXME
case 'unread':
results = await sqlite.get_unread_entries(db_file, num)
results = sqlite.get_unread_entries(db_file, num)
if results:
form = self['xep_0004'].make_form('form', 'Updates')
form['instructions'] = 'Recent {} updates'.format(num)
@ -1105,7 +1105,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
error_count = 0
exist_count = 0
for url in urls:
result = await action.add_feed(db_file, url)
result = await action.add_feed(self, jid_bare, db_file, url)
if result['error']:
error_count += 1
elif result['exist']:
@ -1129,7 +1129,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
else:
if isinstance(url, list):
url = url[0]
result = await action.add_feed(db_file, url)
result = await action.add_feed(self, jid_bare, db_file, url)
if isinstance(result, list):
results = result
form = self['xep_0004'].make_form('form', 'Subscriptions')
@ -1499,7 +1499,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
label='Subscription',
desc=('Select a subscription to edit.'),
required=True)
subscriptions = await sqlite.get_feeds(db_file)
subscriptions = sqlite.get_feeds(db_file)
subscriptions = sorted(subscriptions, key=lambda x: x[0])
for subscription in subscriptions:
title = subscription[0]
@ -1518,7 +1518,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
label='Subscriptions',
desc=('Select subscriptions to remove.'),
required=True)
subscriptions = await sqlite.get_feeds(db_file)
subscriptions = sqlite.get_feeds(db_file)
subscriptions = sorted(subscriptions, key=lambda x: x[0])
for subscription in subscriptions:
title = subscription[0]
@ -1632,7 +1632,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
# label='Interval period')
jid_file = jid_bare
db_file = config.get_pathname_to_database(jid_file)
subscriptions = await sqlite.get_feeds(db_file)
subscriptions = sqlite.get_feeds(db_file)
# subscriptions = set(subscriptions)
categorized_subscriptions = {}
for subscription in subscriptions:
@ -1692,7 +1692,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
# elif isinstance(urls, str):
else:
url = urls
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
if feed_id:
feed_id = feed_id[0]
title = sqlite.get_feed_title(db_file, feed_id)
@ -1772,7 +1772,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
jid_file = jid_bare
db_file = config.get_pathname_to_database(jid_file)
# url = values['url']
# feed_id = await sqlite.get_feed_id(db_file, url)
# feed_id = sqlite.get_feed_id(db_file, url)
# feed_id = feed_id[0]
# if feed_id: feed_id = feed_id[0]
feed_id = values['id']
@ -1848,7 +1848,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
required=True)
jid_file = jid_bare
db_file = config.get_pathname_to_database(jid_file)
subscriptions = await sqlite.get_feeds(db_file)
subscriptions = sqlite.get_feeds(db_file)
subscriptions = sorted(subscriptions, key=lambda x: x[0])
for subscription in subscriptions:
title = subscription[0]
@ -2321,7 +2321,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
jid_bare = session['from'].bare
jid_file = jid_bare
db_file = config.get_pathname_to_database(jid_file)
subscriptions = await sqlite.get_feeds(db_file)
subscriptions = sqlite.get_feeds(db_file)
subscriptions = sorted(subscriptions, key=lambda x: x[0])
form = self['xep_0004'].make_form('form', 'Subscriptions')
match payload['values']['action']:
@ -2712,7 +2712,6 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
i += 1
value = self.settings[jid_bare]['quantum'] or self.settings['default']['quantum']
value = str(value)
value = str(value)
options = form.add_field(var='quantum',
ftype='list-single',
label='Amount',
@ -2727,7 +2726,6 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
i += 1
value = self.settings[jid_bare]['archive'] or self.settings['default']['archive']
value = str(value)
value = str(value)
options = form.add_field(var='archive',
ftype='list-single',
label='Archive',
@ -2755,7 +2753,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
.format(function_name, jid_full))
jid_bare = session['from'].bare
form = payload
jid_file = jid_bare
@ -2768,14 +2766,23 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
key = value
val = values[value]
if key == 'interval':
if key in ('enabled', 'media', 'old'):
if val == True:
val = 1
elif val == False:
val = 0
if key in ('archive', 'interval', 'quantum'):
val = int(val)
if key == 'interval':
if val < 1: val = 1
val = val * 60
is_enabled = self.settings[jid_bare]['enabled'] or self.settings['default']['enabled']
if (key == 'enabled' and val == 1 and
if (key == 'enabled' and
val == 1 and
str(is_enabled) == 0):
logger.info('Slixfeed has been enabled for {}'.format(jid_bare))
status_type = 'available'
@ -2786,7 +2793,8 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
key_list = ['check', 'status', 'interval']
await task.start_tasks_xmpp(self, jid_bare, key_list)
if (key == 'enabled' and val == 0 and
if (key == 'enabled' and
val == 0 and
str(is_enabled) == 1):
logger.info('Slixfeed has been disabled for {}'.format(jid_bare))
key_list = ['interval', 'status']
@ -2796,10 +2804,8 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
XmppPresence.send(self, jid_bare, status_message,
status_type=status_type)
# These three ilnes (getting value after setting it) might be removed
await config.set_setting_value(db_file, key, val)
val = sqlite.get_setting_value(db_file, key)
val = val[0]
await Config.set_setting_value(self.settings, jid_bare, db_file, key, val)
val = self.settings[jid_bare][key]
# if key == 'enabled':
# if str(setting.enabled) == 0:

View file

@ -302,7 +302,7 @@ async def message(self, message):
title = uri.get_hostname(url)
if url.startswith('http'):
db_file = config.get_pathname_to_database(jid_file)
exist = await sqlite.get_feed_id_and_name(db_file, url)
exist = sqlite.get_feed_id_and_name(db_file, url)
if not exist:
await sqlite.insert_feed(db_file, url, title)
await action.scan(self, jid_bare, db_file, url)
@ -315,7 +315,7 @@ async def message(self, message):
key_list = ['status']
await task.start_tasks_xmpp(self, jid_bare, key_list)
else:
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]
await sqlite.mark_feed_as_read(db_file, feed_id)
response = ('> {}\n'
@ -687,7 +687,7 @@ async def message(self, message):
response = 'Enter at least 4 characters to search'
else:
db_file = config.get_pathname_to_database(jid_file)
result = await sqlite.get_feeds(db_file)
result = sqlite.get_feeds(db_file)
response = action.list_feeds(result)
XmppMessage.send_reply(self, message, response)
case 'goodbye':
@ -707,8 +707,8 @@ async def message(self, message):
await Config.set_setting_value(self.settings, jid_bare, db_file, key, val)
# NOTE Perhaps this should be replaced by functions
# clean and start
await task.refresh_task(self, jid_bare, task.task_send,
key, val)
task.refresh_task(self, jid_bare, task.task_send, key,
val)
response = ('Updates will be sent every {} minutes.'
.format(val))
except:
@ -892,7 +892,7 @@ async def message(self, message):
response = 'Value must be ranged from 1 to 50.'
else:
db_file = config.get_pathname_to_database(jid_file)
result = await sqlite.last_entries(db_file, num)
result = sqlite.get_last_entries(db_file, num)
response = action.list_last_entries(result, num)
except:
response = ('No action has been taken.'
@ -924,7 +924,7 @@ async def message(self, message):
.format(ix))
except:
url = ix_url
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
if feed_id:
feed_id = feed_id[0]
await sqlite.remove_feed_by_url(db_file, url)
@ -937,13 +937,7 @@ async def message(self, message):
# 'No action has been made.'
'News source does not exist. '
.format(url))
# await refresh_task(
# self,
# jid_bare,
# send_status,
# 'status',
# 20
# )
# refresh_task(self, jid_bare, send_status, 'status', 20)
# task.clean_tasks_xmpp(self, jid_bare, ['status'])
key_list = ['status']
await task.start_tasks_xmpp(self, jid_bare, key_list)
@ -982,7 +976,7 @@ async def message(self, message):
.format(ix))
except:
url = ix_url
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = sqlite.get_feed_id(db_file, url)
if feed_id:
feed_id = feed_id[0]
name = sqlite.get_feed_title(db_file, feed_id)