forked from sch/Slixfeed
Reduce amount of Python keywords async and await
This commit is contained in:
parent
8388cf5084
commit
ae89521d9b
7 changed files with 164 additions and 162 deletions
|
@ -97,7 +97,7 @@ async def export_feeds(self, jid, jid_file, ext):
|
||||||
filename = os.path.join(
|
filename = os.path.join(
|
||||||
cache_dir, ext, 'slixfeed_' + dt.timestamp() + '.' + ext)
|
cache_dir, ext, 'slixfeed_' + dt.timestamp() + '.' + ext)
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
results = await sqlite.get_feeds(db_file)
|
results = sqlite.get_feeds(db_file)
|
||||||
match ext:
|
match ext:
|
||||||
# case 'html':
|
# case 'html':
|
||||||
# response = 'Not yet implemented.'
|
# response = 'Not yet implemented.'
|
||||||
|
@ -128,13 +128,13 @@ async def xmpp_send_status(self, jid):
|
||||||
status_mode = 'xa'
|
status_mode = 'xa'
|
||||||
status_text = '📪️ Send "Start" to receive updates'
|
status_text = '📪️ Send "Start" to receive updates'
|
||||||
else:
|
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")
|
# print(await current_time(), jid, "has", feeds, "feeds")
|
||||||
if not feeds:
|
if not feeds:
|
||||||
status_mode = 'available'
|
status_mode = 'available'
|
||||||
status_text = '📪️ Send a URL from a blog or a news website'
|
status_text = '📪️ Send a URL from a blog or a news website'
|
||||||
else:
|
else:
|
||||||
unread = await sqlite.get_number_of_entries_unread(db_file)
|
unread = sqlite.get_number_of_entries_unread(db_file)
|
||||||
if unread:
|
if unread:
|
||||||
status_mode = 'chat'
|
status_mode = 'chat'
|
||||||
status_text = '📬️ There are {} news items'.format(str(unread))
|
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']
|
num = self.settings[jid]['quantum'] or self.settings['default']['quantum']
|
||||||
else:
|
else:
|
||||||
num = int(num)
|
num = int(num)
|
||||||
results = await sqlite.get_unread_entries(db_file, num)
|
results = sqlite.get_unread_entries(db_file, num)
|
||||||
news_digest = ''
|
news_digest = ''
|
||||||
media = None
|
media = None
|
||||||
chat_type = await get_chat_type(self, jid)
|
chat_type = await get_chat_type(self, jid)
|
||||||
|
@ -290,6 +290,7 @@ 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:
|
||||||
|
@ -580,12 +581,12 @@ async def list_statistics(db_file):
|
||||||
function_name = sys._getframe().f_code.co_name
|
function_name = sys._getframe().f_code.co_name
|
||||||
logger.debug('{}: db_file: {}'
|
logger.debug('{}: db_file: {}'
|
||||||
.format(function_name, db_file))
|
.format(function_name, db_file))
|
||||||
entries_unread = await sqlite.get_number_of_entries_unread(db_file)
|
entries_unread = sqlite.get_number_of_entries_unread(db_file)
|
||||||
entries = await sqlite.get_number_of_items(db_file, 'entries')
|
entries = sqlite.get_number_of_items(db_file, 'entries')
|
||||||
archive = await sqlite.get_number_of_items(db_file, 'archive')
|
archive = sqlite.get_number_of_items(db_file, 'archive')
|
||||||
entries_all = entries + archive
|
entries_all = entries + archive
|
||||||
feeds_active = await sqlite.get_number_of_feeds_active(db_file)
|
feeds_active = sqlite.get_number_of_feeds_active(db_file)
|
||||||
feeds_all = await sqlite.get_number_of_items(db_file, 'feeds')
|
feeds_all = sqlite.get_number_of_items(db_file, 'feeds')
|
||||||
|
|
||||||
# msg = """You have {} unread news items out of {} from {} news sources.
|
# msg = """You have {} unread news items out of {} from {} news sources.
|
||||||
# """.format(unread_entries, entries, feeds)
|
# """.format(unread_entries, entries, feeds)
|
||||||
|
@ -726,8 +727,7 @@ async def import_opml(db_file, url):
|
||||||
if not result['error']:
|
if not result['error']:
|
||||||
document = result['content']
|
document = result['content']
|
||||||
root = ET.fromstring(document)
|
root = ET.fromstring(document)
|
||||||
before = await sqlite.get_number_of_items(
|
before = sqlite.get_number_of_items(db_file, 'feeds')
|
||||||
db_file, 'feeds')
|
|
||||||
feeds = []
|
feeds = []
|
||||||
for child in root.findall(".//outline"):
|
for child in root.findall(".//outline"):
|
||||||
url = child.get("xmlUrl")
|
url = child.get("xmlUrl")
|
||||||
|
@ -737,8 +737,7 @@ async def import_opml(db_file, url):
|
||||||
feeds.extend([(url, title)])
|
feeds.extend([(url, title)])
|
||||||
await sqlite.import_feeds(db_file, feeds)
|
await sqlite.import_feeds(db_file, feeds)
|
||||||
await sqlite.add_metadata(db_file)
|
await sqlite.add_metadata(db_file)
|
||||||
after = await sqlite.get_number_of_items(
|
after = sqlite.get_number_of_items(db_file, 'feeds')
|
||||||
db_file, 'feeds')
|
|
||||||
difference = int(after) - int(before)
|
difference = int(after) - int(before)
|
||||||
return difference
|
return difference
|
||||||
|
|
||||||
|
@ -748,7 +747,7 @@ async def add_feed(self, jid_bare, db_file, url):
|
||||||
logger.debug('{}: db_file: {} url: {}'
|
logger.debug('{}: db_file: {} url: {}'
|
||||||
.format(function_name, db_file, url))
|
.format(function_name, db_file, url))
|
||||||
while True:
|
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:
|
if not exist:
|
||||||
status_code = None
|
status_code = None
|
||||||
result = await fetch.http(url)
|
result = await fetch.http(url)
|
||||||
|
@ -790,7 +789,7 @@ async def add_feed(self, jid_bare, db_file, url):
|
||||||
updated=updated)
|
updated=updated)
|
||||||
await scan(self, jid_bare, db_file, url)
|
await scan(self, jid_bare, db_file, url)
|
||||||
old = self.settings[jid_bare]['old'] or self.settings['default']['old']
|
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]
|
feed_id = feed_id[0]
|
||||||
if not old:
|
if not old:
|
||||||
await sqlite.mark_feed_as_read(db_file, feed_id)
|
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)
|
await scan_json(self, jid_bare, db_file, url)
|
||||||
old = self.settings[jid_bare]['old'] or self.settings['default']['old']
|
old = self.settings[jid_bare]['old'] or self.settings['default']['old']
|
||||||
if not 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]
|
feed_id = feed_id[0]
|
||||||
await sqlite.mark_feed_as_read(db_file, feed_id)
|
await sqlite.mark_feed_as_read(db_file, feed_id)
|
||||||
result_final = {'link' : url,
|
result_final = {'link' : url,
|
||||||
|
@ -926,7 +925,7 @@ async def scan_json(self, jid_bare, db_file, url):
|
||||||
entries = feed["items"]
|
entries = feed["items"]
|
||||||
await remove_nonexistent_entries_json(self, jid_bare, db_file, url, feed)
|
await remove_nonexistent_entries_json(self, jid_bare, db_file, url, feed)
|
||||||
try:
|
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]
|
feed_id = feed_id[0]
|
||||||
# await sqlite.update_feed_validity(
|
# await sqlite.update_feed_validity(
|
||||||
# db_file, feed_id, valid)
|
# db_file, feed_id, valid)
|
||||||
|
@ -938,7 +937,7 @@ async def scan_json(self, jid_bare, db_file, url):
|
||||||
updated = ''
|
updated = ''
|
||||||
else:
|
else:
|
||||||
updated = ''
|
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]
|
feed_id = feed_id[0]
|
||||||
await sqlite.update_feed_properties(
|
await sqlite.update_feed_properties(
|
||||||
db_file, feed_id, len(feed["items"]), updated)
|
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 = "{}: *{}*".format(feed["feed"]["title"], entry.title)
|
||||||
title = entry["title"] if "title" in entry.keys() else date
|
title = entry["title"] if "title" in entry.keys() else date
|
||||||
entry_id = entry["id"] if "id" in entry.keys() else link
|
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]
|
feed_id = feed_id[0]
|
||||||
exist = sqlite.check_entry_exist(db_file, feed_id,
|
exist = sqlite.check_entry_exist(db_file, feed_id,
|
||||||
entry_id=entry_id,
|
entry_id=entry_id,
|
||||||
|
@ -1046,7 +1045,7 @@ async def scan_json(self, jid_bare, db_file, url):
|
||||||
# url, date, read_status)
|
# url, date, read_status)
|
||||||
# await sqlite.set_date(db_file, url)
|
# await sqlite.set_date(db_file, url)
|
||||||
if len(new_entries):
|
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]
|
feed_id = feed_id[0]
|
||||||
await sqlite.add_entries_and_update_timestamp(db_file, feed_id,
|
await sqlite.add_entries_and_update_timestamp(db_file, feed_id,
|
||||||
new_entries)
|
new_entries)
|
||||||
|
@ -1203,7 +1202,7 @@ async def scan(self, jid_bare, db_file, url):
|
||||||
.format(function_name, db_file, url))
|
.format(function_name, db_file, url))
|
||||||
if isinstance(url, tuple): url = url[0]
|
if isinstance(url, tuple): url = url[0]
|
||||||
result = await fetch.http(url)
|
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]
|
feed_id = feed_id[0]
|
||||||
status_code = result['status_code']
|
status_code = result['status_code']
|
||||||
await sqlite.update_feed_status(db_file, feed_id, 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
|
valid = 0
|
||||||
else:
|
else:
|
||||||
valid = 1
|
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]
|
feed_id = feed_id[0]
|
||||||
await sqlite.update_feed_validity(
|
await sqlite.update_feed_validity(
|
||||||
db_file, feed_id, valid)
|
db_file, feed_id, valid)
|
||||||
|
@ -1239,7 +1238,7 @@ async def scan(self, jid_bare, db_file, url):
|
||||||
updated = ''
|
updated = ''
|
||||||
else:
|
else:
|
||||||
updated = ''
|
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]
|
feed_id = feed_id[0]
|
||||||
await sqlite.update_feed_properties(db_file, feed_id,
|
await sqlite.update_feed_properties(db_file, feed_id,
|
||||||
len(feed["entries"]), updated)
|
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 = "{}: *{}*".format(feed["feed"]["title"], entry.title)
|
||||||
title = entry.title if entry.has_key("title") else date
|
title = entry.title if entry.has_key("title") else date
|
||||||
entry_id = entry.id if entry.has_key("id") else link
|
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]
|
feed_id = feed_id[0]
|
||||||
exist = sqlite.check_entry_exist(db_file, feed_id,
|
exist = sqlite.check_entry_exist(db_file, feed_id,
|
||||||
entry_id=entry_id,
|
entry_id=entry_id,
|
||||||
|
@ -1337,7 +1336,7 @@ async def scan(self, jid_bare, db_file, url):
|
||||||
# url, date, read_status)
|
# url, date, read_status)
|
||||||
# await sqlite.set_date(db_file, url)
|
# await sqlite.set_date(db_file, url)
|
||||||
if len(new_entries):
|
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]
|
feed_id = feed_id[0]
|
||||||
await sqlite.add_entries_and_update_timestamp(db_file, feed_id,
|
await sqlite.add_entries_and_update_timestamp(db_file, feed_id,
|
||||||
new_entries)
|
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
|
function_name = sys._getframe().f_code.co_name
|
||||||
logger.debug('{}: db_file: {} url: {}'
|
logger.debug('{}: db_file: {} url: {}'
|
||||||
.format(function_name, 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]
|
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
|
entries = feed.entries
|
||||||
limit = self.settings[jid_bare]['archive'] or self.settings['default']['archive']
|
limit = self.settings[jid_bare]['archive'] or self.settings['default']['archive']
|
||||||
for item in items:
|
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
|
function_name = sys._getframe().f_code.co_name
|
||||||
logger.debug('{}: db_file: {}: url: {}'
|
logger.debug('{}: db_file: {}: url: {}'
|
||||||
.format(function_name, 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]
|
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"]
|
entries = feed["items"]
|
||||||
limit = self.settings[jid_bare]['archive'] or self.settings['default']['archive']
|
limit = self.settings[jid_bare]['archive'] or self.settings['default']['archive']
|
||||||
for item in items:
|
for item in items:
|
||||||
|
|
|
@ -989,7 +989,7 @@ async def set_new_tag(db_file, tag):
|
||||||
cur.execute(sql, par)
|
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.
|
Get Id and Name of feed.
|
||||||
Check whether a feed exists.
|
Check whether a feed exists.
|
||||||
|
@ -1024,7 +1024,7 @@ async def get_feed_id_and_name(db_file, url):
|
||||||
return result
|
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.
|
Return number of entries or feeds.
|
||||||
|
|
||||||
|
@ -1055,7 +1055,7 @@ async def get_number_of_items(db_file, table):
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
|
||||||
async def get_number_of_feeds_active(db_file):
|
def get_number_of_feeds_active(db_file):
|
||||||
"""
|
"""
|
||||||
Return number of active feeds.
|
Return number of active feeds.
|
||||||
|
|
||||||
|
@ -1085,7 +1085,7 @@ async def get_number_of_feeds_active(db_file):
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
|
||||||
async def get_number_of_entries_unread(db_file):
|
def get_number_of_entries_unread(db_file):
|
||||||
"""
|
"""
|
||||||
Return number of unread items.
|
Return number of unread items.
|
||||||
|
|
||||||
|
@ -1122,7 +1122,7 @@ async def get_number_of_entries_unread(db_file):
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
|
||||||
async def get_unread_entries(db_file, num):
|
def get_unread_entries(db_file, num):
|
||||||
"""
|
"""
|
||||||
Extract information from unread entries.
|
Extract information from unread entries.
|
||||||
|
|
||||||
|
@ -1193,7 +1193,7 @@ def get_feed_id_by_entry_index(db_file, ix):
|
||||||
return feed_id
|
return feed_id
|
||||||
|
|
||||||
|
|
||||||
async def get_feed_id(db_file, url):
|
def get_feed_id(db_file, url):
|
||||||
"""
|
"""
|
||||||
Get index of given feed.
|
Get index of given feed.
|
||||||
|
|
||||||
|
@ -1572,9 +1572,9 @@ async def update_statistics(cur):
|
||||||
function_name = sys._getframe().f_code.co_name
|
function_name = sys._getframe().f_code.co_name
|
||||||
logger.debug('{}'.format(function_name))
|
logger.debug('{}'.format(function_name))
|
||||||
stat_dict = {}
|
stat_dict = {}
|
||||||
stat_dict["feeds"] = await get_number_of_items(cur, 'feeds')
|
stat_dict["feeds"] = get_number_of_items(cur, 'feeds')
|
||||||
stat_dict["entries"] = await get_number_of_items(cur, 'entries')
|
stat_dict["entries"] = get_number_of_items(cur, 'entries')
|
||||||
stat_dict["unread"] = await get_number_of_entries_unread(cur=cur)
|
stat_dict["unread"] = get_number_of_entries_unread(cur=cur)
|
||||||
for i in stat_dict:
|
for i in stat_dict:
|
||||||
sql = (
|
sql = (
|
||||||
"SELECT id "
|
"SELECT id "
|
||||||
|
@ -1959,7 +1959,7 @@ async def maintain_archive(db_file, limit):
|
||||||
# NOTE Entries that are read from archive are deleted.
|
# NOTE Entries that are read from archive are deleted.
|
||||||
# NOTE Unlike entries from table entries, entries from
|
# NOTE Unlike entries from table entries, entries from
|
||||||
# table archive are not marked as read.
|
# 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.
|
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
|
# 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.
|
# 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
|
# TODO select by "feed_id" (of table "status") from
|
||||||
# "feed" urls that are enabled in table "status"
|
# "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.
|
Query table feeds for URLs.
|
||||||
|
|
||||||
|
@ -2081,7 +2081,7 @@ def get_feeds_by_enabled_state(db_file, enabled_state):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
async def get_active_feeds_url(db_file):
|
def get_active_feeds_url(db_file):
|
||||||
"""
|
"""
|
||||||
Query table feeds for active URLs.
|
Query table feeds for active URLs.
|
||||||
|
|
||||||
|
@ -2141,7 +2141,7 @@ def get_tags(db_file):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
async def get_feeds(db_file):
|
def get_feeds(db_file):
|
||||||
"""
|
"""
|
||||||
Query table feeds and list items.
|
Query table feeds and list items.
|
||||||
|
|
||||||
|
@ -2175,7 +2175,7 @@ async def get_feeds(db_file):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
async def last_entries(db_file, num):
|
def get_last_entries(db_file, num):
|
||||||
"""
|
"""
|
||||||
Query entries.
|
Query entries.
|
||||||
|
|
||||||
|
@ -2789,6 +2789,7 @@ async def set_last_update_time(db_file):
|
||||||
function_name = sys._getframe().f_code.co_name
|
function_name = sys._getframe().f_code.co_name
|
||||||
logger.debug('{}: db_file: {}'
|
logger.debug('{}: db_file: {}'
|
||||||
.format(function_name, db_file))
|
.format(function_name, db_file))
|
||||||
|
async with DBLOCK:
|
||||||
with create_connection(db_file) as conn:
|
with create_connection(db_file) as conn:
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
sql = (
|
sql = (
|
||||||
|
@ -2807,7 +2808,7 @@ async def set_last_update_time(db_file):
|
||||||
cur.execute(sql, par)
|
cur.execute(sql, par)
|
||||||
|
|
||||||
|
|
||||||
async def get_last_update_time(db_file):
|
def get_last_update_time(db_file):
|
||||||
"""
|
"""
|
||||||
Get value of last_update.
|
Get value of last_update.
|
||||||
|
|
||||||
|
@ -2859,6 +2860,7 @@ async def update_last_update_time(db_file):
|
||||||
function_name = sys._getframe().f_code.co_name
|
function_name = sys._getframe().f_code.co_name
|
||||||
logger.debug('{}: db_file: {}'
|
logger.debug('{}: db_file: {}'
|
||||||
.format(function_name, db_file))
|
.format(function_name, db_file))
|
||||||
|
async with DBLOCK:
|
||||||
with create_connection(db_file) as conn:
|
with create_connection(db_file) as conn:
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
sql = (
|
sql = (
|
||||||
|
|
|
@ -164,7 +164,7 @@ async def start_tasks_xmpp(self, jid_bare, tasks=None):
|
||||||
|
|
||||||
async def task_status(self, jid):
|
async def task_status(self, jid):
|
||||||
await action.xmpp_send_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):
|
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)
|
Config.add_settings_jid(self.settings, jid_bare, db_file)
|
||||||
update_interval = self.settings[jid_bare]['interval'] or self.settings['default']['interval']
|
update_interval = self.settings[jid_bare]['interval'] or self.settings['default']['interval']
|
||||||
update_interval = 60 * int(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:
|
if last_update_time:
|
||||||
last_update_time = float(last_update_time)
|
last_update_time = float(last_update_time)
|
||||||
diff = time.time() - last_update_time
|
diff = time.time() - last_update_time
|
||||||
|
@ -196,7 +196,7 @@ async def task_send(self, jid_bare):
|
||||||
else:
|
else:
|
||||||
await sqlite.set_last_update_time(db_file)
|
await sqlite.set_last_update_time(db_file)
|
||||||
await action.xmpp_send_update(self, jid_bare)
|
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'])
|
await start_tasks_xmpp(self, jid_bare, ['status'])
|
||||||
|
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ def clean_tasks_xmpp(self, jid, tasks=None):
|
||||||
.format(task, jid))
|
.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.
|
Apply new setting at runtime.
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ async def check_updates(self, jid):
|
||||||
while True:
|
while True:
|
||||||
jid_file = jid.replace('/', '_')
|
jid_file = jid.replace('/', '_')
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
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:
|
for url in urls:
|
||||||
await action.scan(self, jid, db_file, url)
|
await action.scan(self, jid, db_file, url)
|
||||||
val = self.settings['default']['check']
|
val = self.settings['default']['check']
|
||||||
|
|
|
@ -256,20 +256,21 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
function_name = sys._getframe().f_code.co_name
|
function_name = sys._getframe().f_code.co_name
|
||||||
message_log = '{}'
|
message_log = '{}'
|
||||||
logger.debug(message_log.format(function_name))
|
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')
|
jid_operator = config.get_value('accounts', 'XMPP', 'operator')
|
||||||
if jid_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)
|
XmppPresence.send(self, jid_operator, status_message)
|
||||||
|
await profile.update(self)
|
||||||
profile.set_identity(self, 'client')
|
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)
|
# XmppCommand.adhoc_commands(self)
|
||||||
self.adhoc_commands()
|
self.adhoc_commands()
|
||||||
self.service_reactions()
|
# self.service_reactions()
|
||||||
await self['xep_0115'].update_caps()
|
|
||||||
await self.get_roster()
|
|
||||||
await profile.update(self)
|
|
||||||
task.task_ping(self)
|
task.task_ping(self)
|
||||||
time_end = time.time()
|
time_end = time.time()
|
||||||
difference = time_end - time_begin
|
difference = time_end - time_begin
|
||||||
|
@ -721,21 +722,21 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
.format(jid_bare))
|
.format(jid_bare))
|
||||||
form.add_field(ftype='fixed',
|
form.add_field(ftype='fixed',
|
||||||
value='News')
|
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',
|
form.add_field(label='Subscriptions',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=feeds_all)
|
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',
|
form.add_field(label='Active',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=feeds_act)
|
value=feeds_act)
|
||||||
entries = await sqlite.get_number_of_items(db_file, 'entries')
|
entries = sqlite.get_number_of_items(db_file, 'entries')
|
||||||
archive = await sqlite.get_number_of_items(db_file, 'archive')
|
archive = sqlite.get_number_of_items(db_file, 'archive')
|
||||||
entries_all = str(entries + archive)
|
entries_all = str(entries + archive)
|
||||||
form.add_field(label='Items',
|
form.add_field(label='Items',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=entries_all)
|
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',
|
form.add_field(label='Unread',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=unread)
|
value=unread)
|
||||||
|
@ -779,7 +780,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
update_interval = self.settings[jid_bare]['interval'] or self.settings['default']['interval']
|
update_interval = self.settings[jid_bare]['interval'] or self.settings['default']['interval']
|
||||||
update_interval = str(update_interval)
|
update_interval = str(update_interval)
|
||||||
update_interval = 60 * int(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:
|
if last_update_time:
|
||||||
last_update_time = float(last_update_time)
|
last_update_time = float(last_update_time)
|
||||||
dt_object = datetime.fromtimestamp(last_update_time)
|
dt_object = datetime.fromtimestamp(last_update_time)
|
||||||
|
@ -979,11 +980,11 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
num = 100
|
num = 100
|
||||||
match payload['values']['action']:
|
match payload['values']['action']:
|
||||||
case 'all':
|
case 'all':
|
||||||
results = await sqlite.get_entries(db_file, num) # FIXME
|
results = sqlite.get_entries(db_file, num) # FIXME
|
||||||
case 'rejected':
|
case 'rejected':
|
||||||
results = await sqlite.get_entries_rejected(db_file, num) # FIXME
|
results = sqlite.get_entries_rejected(db_file, num) # FIXME
|
||||||
case 'unread':
|
case 'unread':
|
||||||
results = await sqlite.get_unread_entries(db_file, num)
|
results = sqlite.get_unread_entries(db_file, num)
|
||||||
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'] = 'Recent {} updates'.format(num)
|
||||||
|
@ -1539,7 +1540,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
label='Subscription',
|
label='Subscription',
|
||||||
desc=('Select a subscription to edit.'),
|
desc=('Select a subscription to edit.'),
|
||||||
required=True)
|
required=True)
|
||||||
subscriptions = await sqlite.get_feeds(db_file)
|
subscriptions = sqlite.get_feeds(db_file)
|
||||||
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
title = subscription[0]
|
title = subscription[0]
|
||||||
|
@ -1558,7 +1559,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
label='Subscriptions',
|
label='Subscriptions',
|
||||||
desc=('Select subscriptions to remove.'),
|
desc=('Select subscriptions to remove.'),
|
||||||
required=True)
|
required=True)
|
||||||
subscriptions = await sqlite.get_feeds(db_file)
|
subscriptions = sqlite.get_feeds(db_file)
|
||||||
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
title = subscription[0]
|
title = subscription[0]
|
||||||
|
@ -1672,7 +1673,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
# label='Interval period')
|
# label='Interval period')
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
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)
|
# subscriptions = set(subscriptions)
|
||||||
categorized_subscriptions = {}
|
categorized_subscriptions = {}
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
|
@ -1732,7 +1733,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
# elif isinstance(urls, str):
|
# elif isinstance(urls, str):
|
||||||
else:
|
else:
|
||||||
url = urls
|
url = urls
|
||||||
feed_id = await sqlite.get_feed_id(db_file, url)
|
feed_id = sqlite.get_feed_id(db_file, url)
|
||||||
if feed_id:
|
if feed_id:
|
||||||
feed_id = feed_id[0]
|
feed_id = feed_id[0]
|
||||||
title = sqlite.get_feed_title(db_file, feed_id)
|
title = sqlite.get_feed_title(db_file, feed_id)
|
||||||
|
@ -1812,7 +1813,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
# url = values['url']
|
# 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]
|
# feed_id = feed_id[0]
|
||||||
# if feed_id: feed_id = feed_id[0]
|
# if feed_id: feed_id = feed_id[0]
|
||||||
feed_id = values['id']
|
feed_id = values['id']
|
||||||
|
@ -1888,7 +1889,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
required=True)
|
required=True)
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
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])
|
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
title = subscription[0]
|
title = subscription[0]
|
||||||
|
@ -2361,7 +2362,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
jid_bare = session['from'].bare
|
jid_bare = session['from'].bare
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
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])
|
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
||||||
form = self['xep_0004'].make_form('form', 'Subscriptions')
|
form = self['xep_0004'].make_form('form', 'Subscriptions')
|
||||||
match payload['values']['action']:
|
match payload['values']['action']:
|
||||||
|
|
|
@ -96,21 +96,21 @@ class XmppCommand:
|
||||||
.format(jid_bare))
|
.format(jid_bare))
|
||||||
form.add_field(ftype='fixed',
|
form.add_field(ftype='fixed',
|
||||||
value='News')
|
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',
|
form.add_field(label='Subscriptions',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=feeds_all)
|
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',
|
form.add_field(label='Active',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=feeds_act)
|
value=feeds_act)
|
||||||
entries = await sqlite.get_number_of_items(db_file, 'entries')
|
entries = sqlite.get_number_of_items(db_file, 'entries')
|
||||||
archive = await sqlite.get_number_of_items(db_file, 'archive')
|
archive = sqlite.get_number_of_items(db_file, 'archive')
|
||||||
entries_all = str(entries + archive)
|
entries_all = str(entries + archive)
|
||||||
form.add_field(label='Items',
|
form.add_field(label='Items',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=entries_all)
|
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',
|
form.add_field(label='Unread',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=unread)
|
value=unread)
|
||||||
|
@ -154,7 +154,7 @@ class XmppCommand:
|
||||||
update_interval = self.settings[jid_bare]['interval'] or self.settings['default']['interval']
|
update_interval = self.settings[jid_bare]['interval'] or self.settings['default']['interval']
|
||||||
update_interval = str(update_interval)
|
update_interval = str(update_interval)
|
||||||
update_interval = 60 * int(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:
|
if last_update_time:
|
||||||
last_update_time = float(last_update_time)
|
last_update_time = float(last_update_time)
|
||||||
dt_object = datetime.fromtimestamp(last_update_time)
|
dt_object = datetime.fromtimestamp(last_update_time)
|
||||||
|
@ -354,11 +354,11 @@ class XmppCommand:
|
||||||
num = 100
|
num = 100
|
||||||
match payload['values']['action']:
|
match payload['values']['action']:
|
||||||
case 'all':
|
case 'all':
|
||||||
results = await sqlite.get_entries(db_file, num) # FIXME
|
results = sqlite.get_entries(db_file, num) # FIXME
|
||||||
case 'rejected':
|
case 'rejected':
|
||||||
results = await sqlite.get_entries_rejected(db_file, num) # FIXME
|
results = sqlite.get_entries_rejected(db_file, num) # FIXME
|
||||||
case 'unread':
|
case 'unread':
|
||||||
results = await sqlite.get_unread_entries(db_file, num)
|
results = sqlite.get_unread_entries(db_file, num)
|
||||||
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'] = 'Recent {} updates'.format(num)
|
||||||
|
@ -914,7 +914,7 @@ class XmppCommand:
|
||||||
label='Subscription',
|
label='Subscription',
|
||||||
desc=('Select a subscription to edit.'),
|
desc=('Select a subscription to edit.'),
|
||||||
required=True)
|
required=True)
|
||||||
subscriptions = await sqlite.get_feeds(db_file)
|
subscriptions = sqlite.get_feeds(db_file)
|
||||||
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
title = subscription[0]
|
title = subscription[0]
|
||||||
|
@ -933,7 +933,7 @@ class XmppCommand:
|
||||||
label='Subscriptions',
|
label='Subscriptions',
|
||||||
desc=('Select subscriptions to remove.'),
|
desc=('Select subscriptions to remove.'),
|
||||||
required=True)
|
required=True)
|
||||||
subscriptions = await sqlite.get_feeds(db_file)
|
subscriptions = sqlite.get_feeds(db_file)
|
||||||
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
title = subscription[0]
|
title = subscription[0]
|
||||||
|
@ -1047,7 +1047,7 @@ class XmppCommand:
|
||||||
# label='Interval period')
|
# label='Interval period')
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
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)
|
# subscriptions = set(subscriptions)
|
||||||
categorized_subscriptions = {}
|
categorized_subscriptions = {}
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
|
@ -1107,7 +1107,7 @@ class XmppCommand:
|
||||||
# elif isinstance(urls, str):
|
# elif isinstance(urls, str):
|
||||||
else:
|
else:
|
||||||
url = urls
|
url = urls
|
||||||
feed_id = await sqlite.get_feed_id(db_file, url)
|
feed_id = sqlite.get_feed_id(db_file, url)
|
||||||
if feed_id:
|
if feed_id:
|
||||||
feed_id = feed_id[0]
|
feed_id = feed_id[0]
|
||||||
title = sqlite.get_feed_title(db_file, feed_id)
|
title = sqlite.get_feed_title(db_file, feed_id)
|
||||||
|
@ -1187,7 +1187,7 @@ class XmppCommand:
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
# url = values['url']
|
# 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]
|
# feed_id = feed_id[0]
|
||||||
# if feed_id: feed_id = feed_id[0]
|
# if feed_id: feed_id = feed_id[0]
|
||||||
feed_id = values['id']
|
feed_id = values['id']
|
||||||
|
@ -1263,7 +1263,7 @@ class XmppCommand:
|
||||||
required=True)
|
required=True)
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
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])
|
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
title = subscription[0]
|
title = subscription[0]
|
||||||
|
@ -1736,7 +1736,7 @@ class XmppCommand:
|
||||||
jid_bare = session['from'].bare
|
jid_bare = session['from'].bare
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
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])
|
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
||||||
form = self['xep_0004'].make_form('form', 'Subscriptions')
|
form = self['xep_0004'].make_form('form', 'Subscriptions')
|
||||||
match payload['values']['action']:
|
match payload['values']['action']:
|
||||||
|
|
|
@ -681,21 +681,21 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
.format(jid_bare))
|
.format(jid_bare))
|
||||||
form.add_field(ftype='fixed',
|
form.add_field(ftype='fixed',
|
||||||
value='News')
|
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',
|
form.add_field(label='Subscriptions',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=feeds_all)
|
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',
|
form.add_field(label='Active',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=feeds_act)
|
value=feeds_act)
|
||||||
entries = await sqlite.get_number_of_items(db_file, 'entries')
|
entries = sqlite.get_number_of_items(db_file, 'entries')
|
||||||
archive = await sqlite.get_number_of_items(db_file, 'archive')
|
archive = sqlite.get_number_of_items(db_file, 'archive')
|
||||||
entries_all = str(entries + archive)
|
entries_all = str(entries + archive)
|
||||||
form.add_field(label='Items',
|
form.add_field(label='Items',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=entries_all)
|
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',
|
form.add_field(label='Unread',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=unread)
|
value=unread)
|
||||||
|
@ -739,7 +739,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
update_interval = self.settings[jid_bare]['interval'] or self.settings['default']['interval']
|
update_interval = self.settings[jid_bare]['interval'] or self.settings['default']['interval']
|
||||||
update_interval = str(update_interval)
|
update_interval = str(update_interval)
|
||||||
update_interval = 60 * int(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:
|
if last_update_time:
|
||||||
last_update_time = float(last_update_time)
|
last_update_time = float(last_update_time)
|
||||||
dt_object = datetime.fromtimestamp(last_update_time)
|
dt_object = datetime.fromtimestamp(last_update_time)
|
||||||
|
@ -939,11 +939,11 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
num = 100
|
num = 100
|
||||||
match payload['values']['action']:
|
match payload['values']['action']:
|
||||||
case 'all':
|
case 'all':
|
||||||
results = await sqlite.get_entries(db_file, num) # FIXME
|
results = sqlite.get_entries(db_file, num) # FIXME
|
||||||
case 'rejected':
|
case 'rejected':
|
||||||
results = await sqlite.get_entries_rejected(db_file, num) # FIXME
|
results = sqlite.get_entries_rejected(db_file, num) # FIXME
|
||||||
case 'unread':
|
case 'unread':
|
||||||
results = await sqlite.get_unread_entries(db_file, num)
|
results = sqlite.get_unread_entries(db_file, num)
|
||||||
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'] = 'Recent {} updates'.format(num)
|
||||||
|
@ -1105,7 +1105,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
error_count = 0
|
error_count = 0
|
||||||
exist_count = 0
|
exist_count = 0
|
||||||
for url in urls:
|
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']:
|
if result['error']:
|
||||||
error_count += 1
|
error_count += 1
|
||||||
elif result['exist']:
|
elif result['exist']:
|
||||||
|
@ -1129,7 +1129,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
else:
|
else:
|
||||||
if isinstance(url, list):
|
if isinstance(url, list):
|
||||||
url = url[0]
|
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):
|
if isinstance(result, list):
|
||||||
results = result
|
results = result
|
||||||
form = self['xep_0004'].make_form('form', 'Subscriptions')
|
form = self['xep_0004'].make_form('form', 'Subscriptions')
|
||||||
|
@ -1499,7 +1499,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
label='Subscription',
|
label='Subscription',
|
||||||
desc=('Select a subscription to edit.'),
|
desc=('Select a subscription to edit.'),
|
||||||
required=True)
|
required=True)
|
||||||
subscriptions = await sqlite.get_feeds(db_file)
|
subscriptions = sqlite.get_feeds(db_file)
|
||||||
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
title = subscription[0]
|
title = subscription[0]
|
||||||
|
@ -1518,7 +1518,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
label='Subscriptions',
|
label='Subscriptions',
|
||||||
desc=('Select subscriptions to remove.'),
|
desc=('Select subscriptions to remove.'),
|
||||||
required=True)
|
required=True)
|
||||||
subscriptions = await sqlite.get_feeds(db_file)
|
subscriptions = sqlite.get_feeds(db_file)
|
||||||
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
title = subscription[0]
|
title = subscription[0]
|
||||||
|
@ -1632,7 +1632,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
# label='Interval period')
|
# label='Interval period')
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
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)
|
# subscriptions = set(subscriptions)
|
||||||
categorized_subscriptions = {}
|
categorized_subscriptions = {}
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
|
@ -1692,7 +1692,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
# elif isinstance(urls, str):
|
# elif isinstance(urls, str):
|
||||||
else:
|
else:
|
||||||
url = urls
|
url = urls
|
||||||
feed_id = await sqlite.get_feed_id(db_file, url)
|
feed_id = sqlite.get_feed_id(db_file, url)
|
||||||
if feed_id:
|
if feed_id:
|
||||||
feed_id = feed_id[0]
|
feed_id = feed_id[0]
|
||||||
title = sqlite.get_feed_title(db_file, feed_id)
|
title = sqlite.get_feed_title(db_file, feed_id)
|
||||||
|
@ -1772,7 +1772,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
# url = values['url']
|
# 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]
|
# feed_id = feed_id[0]
|
||||||
# if feed_id: feed_id = feed_id[0]
|
# if feed_id: feed_id = feed_id[0]
|
||||||
feed_id = values['id']
|
feed_id = values['id']
|
||||||
|
@ -1848,7 +1848,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
required=True)
|
required=True)
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
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])
|
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
||||||
for subscription in subscriptions:
|
for subscription in subscriptions:
|
||||||
title = subscription[0]
|
title = subscription[0]
|
||||||
|
@ -2321,7 +2321,7 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
jid_bare = session['from'].bare
|
jid_bare = session['from'].bare
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
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])
|
subscriptions = sorted(subscriptions, key=lambda x: x[0])
|
||||||
form = self['xep_0004'].make_form('form', 'Subscriptions')
|
form = self['xep_0004'].make_form('form', 'Subscriptions')
|
||||||
match payload['values']['action']:
|
match payload['values']['action']:
|
||||||
|
@ -2712,7 +2712,6 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
i += 1
|
i += 1
|
||||||
value = self.settings[jid_bare]['quantum'] or self.settings['default']['quantum']
|
value = self.settings[jid_bare]['quantum'] or self.settings['default']['quantum']
|
||||||
value = str(value)
|
value = str(value)
|
||||||
value = str(value)
|
|
||||||
options = form.add_field(var='quantum',
|
options = form.add_field(var='quantum',
|
||||||
ftype='list-single',
|
ftype='list-single',
|
||||||
label='Amount',
|
label='Amount',
|
||||||
|
@ -2727,7 +2726,6 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
i += 1
|
i += 1
|
||||||
value = self.settings[jid_bare]['archive'] or self.settings['default']['archive']
|
value = self.settings[jid_bare]['archive'] or self.settings['default']['archive']
|
||||||
value = str(value)
|
value = str(value)
|
||||||
value = str(value)
|
|
||||||
options = form.add_field(var='archive',
|
options = form.add_field(var='archive',
|
||||||
ftype='list-single',
|
ftype='list-single',
|
||||||
label='Archive',
|
label='Archive',
|
||||||
|
@ -2768,14 +2766,23 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
key = value
|
key = value
|
||||||
val = values[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)
|
val = int(val)
|
||||||
|
|
||||||
|
if key == 'interval':
|
||||||
if val < 1: val = 1
|
if val < 1: val = 1
|
||||||
val = val * 60
|
val = val * 60
|
||||||
|
|
||||||
is_enabled = self.settings[jid_bare]['enabled'] or self.settings['default']['enabled']
|
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):
|
str(is_enabled) == 0):
|
||||||
logger.info('Slixfeed has been enabled for {}'.format(jid_bare))
|
logger.info('Slixfeed has been enabled for {}'.format(jid_bare))
|
||||||
status_type = 'available'
|
status_type = 'available'
|
||||||
|
@ -2786,7 +2793,8 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
key_list = ['check', 'status', 'interval']
|
key_list = ['check', 'status', 'interval']
|
||||||
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
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):
|
str(is_enabled) == 1):
|
||||||
logger.info('Slixfeed has been disabled for {}'.format(jid_bare))
|
logger.info('Slixfeed has been disabled for {}'.format(jid_bare))
|
||||||
key_list = ['interval', 'status']
|
key_list = ['interval', 'status']
|
||||||
|
@ -2796,10 +2804,8 @@ class SlixfeedComponent(slixmpp.ComponentXMPP):
|
||||||
XmppPresence.send(self, jid_bare, status_message,
|
XmppPresence.send(self, jid_bare, status_message,
|
||||||
status_type=status_type)
|
status_type=status_type)
|
||||||
|
|
||||||
# These three ilnes (getting value after setting it) might be removed
|
await Config.set_setting_value(self.settings, jid_bare, db_file, key, val)
|
||||||
await config.set_setting_value(db_file, key, val)
|
val = self.settings[jid_bare][key]
|
||||||
val = sqlite.get_setting_value(db_file, key)
|
|
||||||
val = val[0]
|
|
||||||
|
|
||||||
# if key == 'enabled':
|
# if key == 'enabled':
|
||||||
# if str(setting.enabled) == 0:
|
# if str(setting.enabled) == 0:
|
||||||
|
|
|
@ -302,7 +302,7 @@ async def message(self, message):
|
||||||
title = uri.get_hostname(url)
|
title = uri.get_hostname(url)
|
||||||
if url.startswith('http'):
|
if url.startswith('http'):
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
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:
|
if not exist:
|
||||||
await sqlite.insert_feed(db_file, url, title)
|
await sqlite.insert_feed(db_file, url, title)
|
||||||
await action.scan(self, jid_bare, db_file, url)
|
await action.scan(self, jid_bare, db_file, url)
|
||||||
|
@ -315,7 +315,7 @@ async def message(self, message):
|
||||||
key_list = ['status']
|
key_list = ['status']
|
||||||
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
||||||
else:
|
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]
|
feed_id = feed_id[0]
|
||||||
await sqlite.mark_feed_as_read(db_file, feed_id)
|
await sqlite.mark_feed_as_read(db_file, feed_id)
|
||||||
response = ('> {}\n'
|
response = ('> {}\n'
|
||||||
|
@ -687,7 +687,7 @@ async def message(self, message):
|
||||||
response = 'Enter at least 4 characters to search'
|
response = 'Enter at least 4 characters to search'
|
||||||
else:
|
else:
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
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)
|
response = action.list_feeds(result)
|
||||||
XmppMessage.send_reply(self, message, response)
|
XmppMessage.send_reply(self, message, response)
|
||||||
case 'goodbye':
|
case 'goodbye':
|
||||||
|
@ -707,8 +707,8 @@ async def message(self, message):
|
||||||
await Config.set_setting_value(self.settings, jid_bare, db_file, key, val)
|
await Config.set_setting_value(self.settings, jid_bare, db_file, key, val)
|
||||||
# NOTE Perhaps this should be replaced by functions
|
# NOTE Perhaps this should be replaced by functions
|
||||||
# clean and start
|
# clean and start
|
||||||
await task.refresh_task(self, jid_bare, task.task_send,
|
task.refresh_task(self, jid_bare, task.task_send, key,
|
||||||
key, val)
|
val)
|
||||||
response = ('Updates will be sent every {} minutes.'
|
response = ('Updates will be sent every {} minutes.'
|
||||||
.format(val))
|
.format(val))
|
||||||
except:
|
except:
|
||||||
|
@ -892,7 +892,7 @@ async def message(self, message):
|
||||||
response = 'Value must be ranged from 1 to 50.'
|
response = 'Value must be ranged from 1 to 50.'
|
||||||
else:
|
else:
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
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)
|
response = action.list_last_entries(result, num)
|
||||||
except:
|
except:
|
||||||
response = ('No action has been taken.'
|
response = ('No action has been taken.'
|
||||||
|
@ -924,7 +924,7 @@ async def message(self, message):
|
||||||
.format(ix))
|
.format(ix))
|
||||||
except:
|
except:
|
||||||
url = ix_url
|
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:
|
if feed_id:
|
||||||
feed_id = feed_id[0]
|
feed_id = feed_id[0]
|
||||||
await sqlite.remove_feed_by_url(db_file, url)
|
await sqlite.remove_feed_by_url(db_file, url)
|
||||||
|
@ -937,13 +937,7 @@ async def message(self, message):
|
||||||
# 'No action has been made.'
|
# 'No action has been made.'
|
||||||
'News source does not exist. '
|
'News source does not exist. '
|
||||||
.format(url))
|
.format(url))
|
||||||
# await refresh_task(
|
# refresh_task(self, jid_bare, send_status, 'status', 20)
|
||||||
# self,
|
|
||||||
# jid_bare,
|
|
||||||
# send_status,
|
|
||||||
# 'status',
|
|
||||||
# 20
|
|
||||||
# )
|
|
||||||
# task.clean_tasks_xmpp(self, jid_bare, ['status'])
|
# task.clean_tasks_xmpp(self, jid_bare, ['status'])
|
||||||
key_list = ['status']
|
key_list = ['status']
|
||||||
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
||||||
|
@ -982,7 +976,7 @@ async def message(self, message):
|
||||||
.format(ix))
|
.format(ix))
|
||||||
except:
|
except:
|
||||||
url = ix_url
|
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:
|
if feed_id:
|
||||||
feed_id = feed_id[0]
|
feed_id = feed_id[0]
|
||||||
name = sqlite.get_feed_title(db_file, feed_id)
|
name = sqlite.get_feed_title(db_file, feed_id)
|
||||||
|
|
Loading…
Reference in a new issue