Measure function elapsed time period and display a warning for a period of over a second.

This commit is contained in:
Schimon Jehudah 2024-03-04 10:16:49 +00:00
parent f25cb70181
commit 6dd1089c37
6 changed files with 2454 additions and 262 deletions

View file

@ -87,8 +87,7 @@ except ImportError:
async def export_feeds(self, jid, jid_file, ext):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid))
logger.debug('{}: jid: {}: jid_file: {}: ext: {}'.format(function_name, jid, jid_file, ext))
cache_dir = config.get_default_cache_directory()
if not os.path.isdir(cache_dir):
os.mkdir(cache_dir)
@ -119,8 +118,7 @@ async def xmpp_send_status(self, jid):
Jabber ID.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid))
logger.debug('{}: jid: {}'.format(function_name, jid))
status_text = '📜️ Slixfeed RSS News Bot'
jid_file = jid.replace('/', '_')
db_file = config.get_pathname_to_database(jid_file)
@ -173,8 +171,7 @@ async def xmpp_send_update(self, jid, num=None):
Number. The default is None.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid))
logger.debug('{}: jid: {} num: {}'.format(function_name, jid, num))
jid_file = jid.replace('/', '_')
db_file = config.get_pathname_to_database(jid_file)
enabled = config.get_setting_value(db_file, 'enabled')
@ -274,8 +271,7 @@ async def xmpp_send_update(self, jid, num=None):
def manual(filename, section=None, command=None):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
.format(function_name, filename))
logger.debug('{}: filename: {}'.format(function_name, filename))
config_dir = config.get_default_config_directory()
with open(config_dir + '/' + filename, mode="rb") as commands:
cmds = tomllib.load(commands)
@ -326,8 +322,7 @@ def log_to_markdown(timestamp, filename, jid, message):
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
.format(function_name, filename))
logger.debug('{}: timestamp: {} filename: {} jid: {} message: {}'.format(function_name, timestamp, filename, jid, message))
with open(filename + '.md', 'a') as file:
# entry = "{} {}:\n{}\n\n".format(timestamp, jid, message)
entry = (
@ -355,7 +350,7 @@ def is_feed_json(document):
True or False.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated'.format(function_name))
logger.debug('{}'.format(function_name))
value = False
try:
feed = json.loads(document)
@ -391,7 +386,7 @@ def is_feed(feed):
True or False.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated'.format(function_name))
logger.debug('{}'.format(function_name))
value = False
# message = None
if not feed.entries:
@ -427,7 +422,8 @@ def is_feed(feed):
def list_unread_entries(result, feed_title, jid_file):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated'.format(function_name))
logger.debug('{}: feed_title: {} jid_file: {}'
.format(function_name, feed_title, jid_file))
# TODO Add filtering
# TODO Do this when entry is added to list and mark it as read
# DONE!
@ -488,7 +484,7 @@ def list_unread_entries(result, feed_title, jid_file):
def list_search_results(query, results):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for query {}.'
logger.debug('{}: query: {}'
.format(function_name, query))
message = ("Search results for '{}':\n\n```"
.format(query))
@ -504,8 +500,8 @@ def list_search_results(query, results):
def list_feeds_by_query(db_file, query):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for query {}.'
.format(function_name, query))
logger.debug('{}: db_file: {} query: {}'
.format(function_name, db_file, query))
results = sqlite.search_feeds(db_file, query)
message = ('Feeds containing "{}":\n\n```'
.format(query))
@ -536,7 +532,7 @@ async def list_statistics(db_file):
Statistics as message.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
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')
@ -582,8 +578,8 @@ async def list_statistics(db_file):
# FIXME Replace counter by len
def list_last_entries(results, num):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated.'
.format(function_name))
logger.debug('{}: num: {}'
.format(function_name, num))
message = "Recent {} titles:\n\n```".format(num)
for result in results:
message += ("\n{}\n{}\n"
@ -597,8 +593,8 @@ def list_last_entries(results, num):
def pick_a_feed(lang=None):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated.'
.format(function_name))
logger.debug('{}: lang: {}'
.format(function_name, lang))
config_dir = config.get_default_config_directory()
with open(config_dir + '/' + 'feeds.toml', mode="rb") as feeds:
urls = tomllib.load(feeds)
@ -609,8 +605,7 @@ def pick_a_feed(lang=None):
def list_feeds(results):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated.'
.format(function_name))
logger.debug('{}'.format(function_name))
message = "\nList of subscriptions:\n\n```\n"
for result in results:
message += ("Name : {}\n"
@ -634,8 +629,7 @@ def list_feeds(results):
async def list_bookmarks(self):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated.'
.format(function_name))
logger.debug('{}'.format(function_name))
conferences = await XmppBookmark.get(self)
message = '\nList of groupchats:\n\n```\n'
for conference in conferences:
@ -650,8 +644,8 @@ async def list_bookmarks(self):
def export_to_markdown(jid, filename, results):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid))
logger.debug('{}: jid: {} filename: {}'
.format(function_name, jid, filename))
with open(filename, 'w') as file:
file.write('# Subscriptions for {}\n'.format(jid))
file.write('## Set of feeds exported with Slixfeed\n')
@ -665,8 +659,8 @@ def export_to_markdown(jid, filename, results):
# TODO Consider adding element jid as a pointer of import
def export_to_opml(jid, filename, results):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid))
logger.debug('{} jid: {} filename: {}'
.format(function_name, jid, filename))
root = ET.Element("opml")
root.set("version", "1.0")
head = ET.SubElement(root, "head")
@ -691,8 +685,8 @@ def export_to_opml(jid, filename, results):
async def import_opml(db_file, url):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
.format(function_name, db_file))
logger.debug('{}: db_file: {} url: {}'
.format(function_name, db_file, url))
result = await fetch.http(url)
if not result['error']:
document = result['content']
@ -716,8 +710,8 @@ async def import_opml(db_file, url):
async def add_feed(db_file, url):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
.format(function_name, db_file))
logger.debug('{}: db_file: {} url: {}'
.format(function_name, db_file, url))
while True:
exist = await sqlite.get_feed_id_and_name(db_file, url)
if not exist:
@ -884,8 +878,8 @@ async def scan_json(db_file, url):
URL. The default is None.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
.format(function_name, db_file))
logger.debug('{}: db_file: {} url: {}'
.format(function_name, db_file, url))
if isinstance(url, tuple): url = url[0]
result = await fetch.http(url)
if not result['error']:
@ -924,6 +918,8 @@ async def scan_json(db_file, url):
return
# new_entry = 0
for entry in entries:
logger.debug('{}: entry: {}'
.format(function_name, entry["title"]))
if "date_published" in entry.keys():
date = entry["date_published"]
date = dt.rfc2822_to_iso8601(date)
@ -993,10 +989,10 @@ async def scan_json(db_file, url):
media_link = trim_url(media_link)
break
except:
logger.info('KeyError: "url"\n'
logger.error('KeyError: "url"\n'
'Missing "url" attribute for {}'
.format(url))
logger.info('Continue scanning for next '
logger.error('Continue scanning for next '
'potential enclosure of {}'
.format(link))
entry = {
@ -1021,7 +1017,7 @@ async def scan_json(db_file, url):
async def view_feed(url):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for URL {}.'
logger.debug('{}: url: {}'
.format(function_name, url))
while True:
result = await fetch.http(url)
@ -1086,8 +1082,8 @@ async def view_feed(url):
async def view_entry(url, num):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for URL {}.'
.format(function_name, url))
logger.debug('{}: url: {} num: {}'
.format(function_name, url, num))
while True:
result = await fetch.http(url)
if not result['error']:
@ -1166,10 +1162,14 @@ async def scan(db_file, url):
URL. The default is None.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and URL {}.'
logger.debug('{}: 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 = feed_id[0]
status_code = result['status_code']
await sqlite.update_feed_status(db_file, feed_id, status_code)
if not result['error']:
document = result['content']
status = result['status_code']
@ -1212,6 +1212,7 @@ async def scan(db_file, url):
return
# new_entry = 0
for entry in entries:
logger.debug('{}: entry: {}'.format(function_name, entry.title))
if entry.has_key("published"):
date = entry.published
date = dt.rfc2822_to_iso8601(date)
@ -1276,10 +1277,10 @@ async def scan(db_file, url):
media_link = trim_url(media_link)
break
except:
logger.info('KeyError: "href"\n'
logger.error('KeyError: "href"\n'
'Missing "href" attribute for {}'
.format(url))
logger.info('Continue scanning for next '
logger.error('Continue scanning for next '
'potential enclosure of {}'
.format(link))
entry = {
@ -1305,8 +1306,7 @@ async def scan(db_file, url):
def get_document_title(data):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated.'
.format(function_name))
logger.debug('{}'.format(function_name))
try:
document = Document(data)
title = document.short_title()
@ -1318,8 +1318,7 @@ def get_document_title(data):
def get_document_content(data):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated.'
.format(function_name))
logger.debug('{}'.format(function_name))
try:
document = Document(data)
content = document.summary()
@ -1331,8 +1330,7 @@ def get_document_content(data):
def get_document_content_as_text(data):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated.'
.format(function_name))
logger.debug('{}'.format(function_name))
try:
document = Document(data)
content = document.summary()
@ -1345,8 +1343,8 @@ def get_document_content_as_text(data):
def generate_document(data, url, ext, filename, readability=False):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and URL {}.'
.format(function_name, filename, url))
logger.debug('{}: url: {} ext: {} filename: {}'
.format(function_name, url, ext, filename))
error = None
if readability:
try:
@ -1398,8 +1396,8 @@ def generate_document(data, url, ext, filename, readability=False):
async def extract_image_from_feed(db_file, feed_id, url):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and URL {}.'
.format(function_name, db_file, url))
logger.debug('{}: db_file: {} feed_id: {} url: {}'
.format(function_name, db_file, feed_id, url))
feed_url = sqlite.get_feed_url(db_file, feed_id)
feed_url = feed_url[0]
result = await fetch.http(feed_url)
@ -1421,8 +1419,7 @@ async def extract_image_from_feed(db_file, feed_id, url):
async def extract_image_from_html(url):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for URL {}.'
.format(function_name, url))
logger.debug('{}: url: {}'.format(function_name, url))
result = await fetch.http(url)
if not result['error']:
data = result['content']
@ -1453,8 +1450,7 @@ async def extract_image_from_html(url):
def generate_epub(text, pathname):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
.format(function_name, pathname))
logger.debug('{}: text: {} pathname: {}'.format(function_name, text, pathname))
## create an empty eBook
pathname_list = pathname.split("/")
filename = pathname_list.pop()
@ -1483,16 +1479,14 @@ def generate_epub(text, pathname):
def generate_html(text, filename):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
.format(function_name, filename))
logger.debug('{}: text: {} filename: {}'.format(function_name, text, filename))
with open(filename, 'w') as file:
file.write(text)
def generate_markdown(text, filename):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
.format(function_name, filename))
logger.debug('{}: text: {} filename: {}'.format(function_name, text, filename))
h2m = html2text.HTML2Text()
# Convert HTML to Markdown
markdown = h2m.handle(text)
@ -1502,8 +1496,7 @@ def generate_markdown(text, filename):
def generate_pdf(text, filename):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
.format(function_name, filename))
logger.debug('{}: text: {} filename: {}'.format(function_name, text, filename))
try:
pdfkit.from_string(text, filename)
except IOError as error:
@ -1514,16 +1507,14 @@ def generate_pdf(text, filename):
def generate_txt(text, filename):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
.format(function_name, filename))
logger.debug('{}: text: {} filename: {}'.format(function_name, text, filename))
text = remove_html_tags(text)
with open(filename, 'w') as file:
file.write(text)
def remove_html_tags(data):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated.'
.format(function_name))
logger.debug('{}'.format(function_name))
data = BeautifulSoup(data, "lxml").text
data = data.replace("\n\n", "\n")
return data
@ -1531,8 +1522,7 @@ def remove_html_tags(data):
# TODO Add support for eDonkey, Gnutella, Soulseek
async def get_magnet(link):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for URL {}.'
.format(function_name, link))
logger.debug('{}: {}'.format(function_name, link))
parted_link = urlsplit(link)
queries = parse_qs(parted_link.query)
query_xt = queries["xt"][0]
@ -1574,7 +1564,7 @@ async def remove_nonexistent_entries(db_file, url, feed):
Parsed feed document.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and URL {}.'
logger.debug('{}: db_file: {} url: {}'
.format(function_name, db_file, url))
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]
@ -1683,7 +1673,7 @@ async def remove_nonexistent_entries_json(db_file, url, feed):
Parsed feed document.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and URL {}.'
logger.debug('{}: db_file: {}: url: {}'
.format(function_name, db_file, url))
feed_id = await sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]

View file

@ -17,12 +17,12 @@ class Logger:
def __init__(self, name):
self.logger = logging.getLogger(name)
self.logger.setLevel(logging.DEBUG)
self.logger.setLevel(logging.WARNING)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setLevel(logging.WARNING)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
formatter = logging.Formatter('[%(asctime)s] %(levelname)s: %(name)s: %(message)s')
ch.setFormatter(formatter)
self.logger.addHandler(ch)
@ -41,3 +41,7 @@ class Logger:
def warning(self, message):
self.logger.warning(message)
# def check_difference(function_name, difference):
# if difference > 1:
# Logger.warning(message)

View file

@ -54,16 +54,21 @@ def create_connection(db_file):
conn : object
Connection object or None.
"""
time_begin = time.time()
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
.format(function_name, db_file))
message_log = '{}'
logger.debug(message_log.format(function_name))
conn = None
try:
conn = connect(db_file)
conn.execute("PRAGMA foreign_keys = ON")
return conn
# return conn
except Error as e:
print(e)
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
return conn
@ -77,7 +82,7 @@ def create_tables(db_file):
Path to database file.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
with create_connection(db_file) as conn:
archive_table_sql = (
@ -306,7 +311,7 @@ def get_cursor(db_file):
Cursor.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
if db_file in CURSORS:
return CURSORS[db_file]
@ -329,12 +334,14 @@ async def import_feeds(db_file, feeds):
Set of feeds (Title and URL).
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
async with DBLOCK:
with create_connection(db_file) as conn:
cur = conn.cursor()
for feed in feeds:
logger.debug('{}: feed: {}'
.format(function_name, feed))
url = feed[0]
title = feed[1]
sql = (
@ -366,7 +373,7 @@ async def add_metadata(db_file):
Path to database file.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -395,7 +402,7 @@ def insert_feed_status(cur, feed_id):
Cursor object.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for feed_id {}.'
logger.debug('{}: feed_id: {}'
.format(function_name, feed_id))
sql = (
"""
@ -425,7 +432,7 @@ def insert_feed_properties(cur, feed_id):
Cursor object.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for feed_id {}.'
logger.debug('{}: feed_id: {}'
.format(function_name, feed_id))
sql = (
"""
@ -473,7 +480,7 @@ async def insert_feed(db_file, url, title=None, entries=None, version=None,
Date feed was last updated. The default is None.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and URL {}.'
logger.debug('{}: db_file: {} url: {}'
.format(function_name, db_file, url))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -560,7 +567,7 @@ async def insert_feed_(db_file, url, title=None, entries=None, version=None,
Date feed was last updated. The default is None.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and URL {}.'
logger.debug('{}: db_file: {} url: {}'
.format(function_name, db_file, url))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -606,7 +613,7 @@ async def remove_feed_by_url(db_file, url):
URL of feed.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and URL {}.'
logger.debug('{}: db_file: {} url: {}'
.format(function_name, db_file, url))
with create_connection(db_file) as conn:
async with DBLOCK:
@ -634,7 +641,7 @@ async def remove_feed_by_index(db_file, ix):
Index of feed.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Index {}.'
logger.debug('{}: db_file: {} ix: {}'
.format(function_name, db_file, ix))
with create_connection(db_file) as conn:
async with DBLOCK:
@ -682,7 +689,7 @@ def get_feeds_by_tag_id(db_file, tag_id):
List of tags.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Tag ID {}.'
logger.debug('{}: db_file: {} tag_id: {}'
.format(function_name, db_file, tag_id))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -717,7 +724,7 @@ def get_tags_by_feed_id(db_file, feed_id):
List of tags.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Feed ID {}.'
logger.debug('{}: db_file: {} feed_id: {}'
.format(function_name, db_file, feed_id))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -749,7 +756,7 @@ async def set_feed_id_and_tag_id(db_file, feed_id, tag_id):
Tag ID
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}, Feed ID {} and Tag ID {}.'
logger.debug('{}: db_file: {} feed_id: {} tag_id: {}'
.format(function_name, db_file, feed_id, tag_id))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -787,7 +794,7 @@ def get_tag_id(db_file, tag_name):
Tag ID.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Tag {}.'
logger.debug('{}: db_file: {} tag_name: {}'
.format(function_name, db_file, tag_name))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -820,7 +827,7 @@ def get_tag_name(db_file, ix):
Tag name.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Index {}.'
logger.debug('{}: db_file: {} ix: {}'
.format(function_name, db_file, ix))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -853,7 +860,7 @@ def is_tag_id_associated(db_file, tag_id):
Tag ID.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Tag ID {}.'
logger.debug('{}: db_file: {} tag_id: {}'
.format(function_name, db_file, tag_id))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -873,7 +880,7 @@ def is_tag_id_associated(db_file, tag_id):
async def delete_tag_by_index(db_file, ix):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Index {}.'
logger.debug('{}: db_file: {} ix: {}'
.format(function_name, db_file, ix))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -910,7 +917,7 @@ def is_tag_id_of_feed_id(db_file, tag_id, feed_id):
Tag ID.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}, Feed ID {} and Tag ID {}.'
logger.debug('{}: db_file: {} tag_id: {} feed_id: {}'
.format(function_name, db_file, feed_id, tag_id))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -931,7 +938,7 @@ def is_tag_id_of_feed_id(db_file, tag_id, feed_id):
async def delete_feed_id_tag_id(db_file, feed_id, tag_id):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}, Feed ID {} and Tag ID {}.'
logger.debug('{}: db_file: {} tag_id: {} feed_id: {}'
.format(function_name, db_file, feed_id, tag_id))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -962,7 +969,7 @@ async def set_new_tag(db_file, tag):
Tag
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Tag {}.'
logger.debug('{}: db_file: {} tag: {}'
.format(function_name, db_file, tag))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -1001,7 +1008,7 @@ async def get_feed_id_and_name(db_file, url):
List of ID and Name of feed.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and URL {}.'
logger.debug('{}: db_file: {} url: {}'
.format(function_name, db_file, url))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -1034,7 +1041,7 @@ async def get_number_of_items(db_file, table):
Number of rows.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Table {}.'
logger.debug('{}: db_file: {} table: {}'
.format(function_name, db_file, table))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -1063,7 +1070,7 @@ async def get_number_of_feeds_active(db_file):
Number of rows.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -1093,7 +1100,7 @@ async def get_number_of_entries_unread(db_file):
Number of rows.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -1132,7 +1139,7 @@ async def get_unread_entries(db_file, num):
News items.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Num {}.'
logger.debug('{}: db_file: {} num: {}'
.format(function_name, db_file, num))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -1170,7 +1177,7 @@ def get_feed_id_by_entry_index(db_file, ix):
Feed index.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Index {}.'
logger.debug('{}: db_file: {} ix: {}'
.format(function_name, db_file, ix))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -1203,7 +1210,7 @@ async def get_feed_id(db_file, url):
Feed index.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and URL {}.'
logger.debug('{}: db_file: {} url: {}'
.format(function_name, db_file, url))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -1231,8 +1238,8 @@ async def mark_entry_as_read(cur, ix):
Index of entry.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Index {}.'
.format(function_name, db_file, ix))
logger.debug('{}: ix: {}'
.format(function_name, ix))
sql = (
"""
UPDATE entries
@ -1256,7 +1263,7 @@ def get_number_of_unread_entries_by_feed(db_file, feed_id):
Feed Id.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Feed ID {}.'
logger.debug('{}: db_file: {} feed_id: {}'
.format(function_name, db_file, feed_id))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -1284,7 +1291,7 @@ async def mark_feed_as_read(db_file, feed_id):
Feed Id.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Feed ID {}.'
logger.debug('{}: db_file: {} feed_id: {}'
.format(function_name, db_file, feed_id))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -1312,7 +1319,7 @@ async def delete_entry_by_id(db_file, ix):
Index.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Index {}.'
logger.debug('{}: db_file: {} ix: {}'
.format(function_name, db_file, ix))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -1340,7 +1347,7 @@ async def archive_entry(db_file, ix):
Index.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Index {}.'
logger.debug('{}: db_file: {} ix: {}'
.format(function_name, db_file, ix))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -1379,7 +1386,7 @@ async def archive_entry(db_file, ix):
def get_feed_title(db_file, ix):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Index {}.'
logger.debug('{}: db_file: {} ix: {}'
.format(function_name, db_file, ix))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -1409,7 +1416,7 @@ async def set_feed_title(db_file, feed_id, name):
New name.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}, Feed ID {} and Name {}.'
logger.debug('{}: db_file: {} feed_id: {} name: {}'
.format(function_name, db_file, feed_id, name))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -1430,7 +1437,7 @@ async def set_feed_title(db_file, feed_id, name):
def get_entry_title(db_file, ix):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Index {}.'
logger.debug('{}: db_file: {} ix: {}'
.format(function_name, db_file, ix))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -1448,7 +1455,7 @@ def get_entry_title(db_file, ix):
def get_entry_url(db_file, ix):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Index {}.'
logger.debug('{}: db_file: {} ix: {}'
.format(function_name, db_file, ix))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -1466,7 +1473,7 @@ def get_entry_url(db_file, ix):
def get_feed_url(db_file, ix):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Index {}.'
logger.debug('{}: db_file: {} ix: {}'
.format(function_name, db_file, ix))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -1484,7 +1491,7 @@ def get_feed_url(db_file, ix):
async def mark_as_read(db_file, ix):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Index {}.'
logger.debug('{}: db_file: {} ix: {}'
.format(function_name, db_file, ix))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -1509,7 +1516,7 @@ async def mark_all_as_read(db_file):
Path to database file.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {} ix: {}'
.format(function_name, db_file))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -1542,7 +1549,7 @@ async def delete_archived_entry(cur, ix):
Index of entry.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for Index {}.'
logger.debug('{}: ix: {}'
.format(function_name, ix))
sql = (
"""
@ -1565,8 +1572,7 @@ async def update_statistics(cur):
Cursor object.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated.'
.format(function_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')
@ -1619,7 +1625,7 @@ async def set_enabled_status(db_file, feed_id, status):
0 or 1.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}, Feed ID {} and Status {}.'
logger.debug('{}: db_file: {} feed_id: {} status: {}'
.format(function_name, db_file, feed_id, status))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -1672,8 +1678,8 @@ async def add_entry(db_file, title, link, entry_id, feed_id, date,
0 or 1.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Feed ID {}.'
.format(function_name, db_file, feed_id))
logger.debug('{}: db_file: {} title: {} link: {} entry_id: {} feed_id: {} date: {} read_status: {}'
.format(function_name, db_file, title, link, entry_id, feed_id, date, read_status))
async with DBLOCK:
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -1724,12 +1730,14 @@ async def add_entries_and_update_timestamp(db_file, feed_id, new_entries):
Set of entries as dict.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Feed ID {}.'
logger.debug('{}: db_file: {} feed_id: {}'
.format(function_name, db_file, feed_id))
async with DBLOCK:
with create_connection(db_file) as conn:
cur = conn.cursor()
for entry in new_entries:
logger.debug('{}: db_file: {} feed_id: {} entry: {}'
.format(function_name, db_file, feed_id, entry["title"]))
sql = (
"""
INSERT
@ -1776,7 +1784,7 @@ async def set_date(db_file, feed_id):
Feed Id.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Feed ID {}.'
logger.debug('{}: db_file: {} feed_id: {}'
.format(function_name, db_file, feed_id))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -1810,7 +1818,7 @@ async def update_feed_status(db_file, feed_id, status_code):
Status ID or message.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}, Feed ID {} and Status Code {}.'
print('{}: db_file: {} feed_id: {} status_code: {}'
.format(function_name, db_file, feed_id, status_code))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -1844,7 +1852,7 @@ async def update_feed_validity(db_file, feed_id, valid):
0 or 1.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}, Feed ID {} and Validity {}.'
logger.debug('{}: db_file: {} feed_id: {} valid: {}'
.format(function_name, db_file, feed_id, valid))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -1879,8 +1887,8 @@ async def update_feed_properties(db_file, feed_id, entries, updated):
Date feed was last updated.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Feed ID {}.'
.format(function_name, db_file, feed_id))
logger.debug('{}: db_file: {} feed_id: {} entries: {} updated: {}'
.format(function_name, db_file, feed_id, entries, updated))
async with DBLOCK:
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -1910,7 +1918,7 @@ async def maintain_archive(db_file, limit):
Number of maximum entries to store.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Limit {}.'
logger.debug('{}: db_file: {} limit: {}'
.format(function_name, db_file, limit))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -1955,9 +1963,7 @@ async def maintain_archive(db_file, limit):
# table archive are not marked as read.
async def get_entries_of_feed(db_file, feed_id):
"""
Remove entries that don't exist in a given parsed feed.
Check the entries returned from feed and delete read non
existing entries, otherwise move to table archive, if unread.
Get entries of given feed.
Parameters
----------
@ -1967,7 +1973,7 @@ async def get_entries_of_feed(db_file, feed_id):
Feed Id.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Feed ID {}.'
logger.debug('{} db_file: {} feed_id: {}'
.format(function_name, db_file, feed_id))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -1976,6 +1982,7 @@ async def get_entries_of_feed(db_file, feed_id):
SELECT id, title, link, entry_id, timestamp, read
FROM entries
WHERE feed_id = ?
ORDER BY timestamp DESC
"""
)
par = (feed_id,)
@ -2024,7 +2031,7 @@ async def get_feeds_url(db_file):
URLs of active feeds.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{} db_file: {}'
.format(function_name, db_file))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -2055,7 +2062,7 @@ def get_feeds_by_enabled_state(db_file, enabled_state):
List of URLs.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and State {}.'
logger.debug('{}: db_file: {} enabled_state: {}'
.format(function_name, db_file, enabled_state))
if enabled_state:
enabled_state = 1
@ -2091,7 +2098,7 @@ async def get_active_feeds_url(db_file):
URLs of active feeds.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -2122,7 +2129,7 @@ def get_tags(db_file):
List of tags.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -2151,7 +2158,7 @@ async def get_feeds(db_file):
URLs of feeds.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
# TODO
# 1) Select id from table feeds
@ -2187,7 +2194,7 @@ async def last_entries(db_file, num):
List of recent N entries as message.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Num {}.'
logger.debug('{}: db_file: {} num: {}'
.format(function_name, db_file, num))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -2232,7 +2239,7 @@ def search_feeds(db_file, query):
Feeds of specified keywords as message.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Query {}.'
logger.debug('{}: db_file: {} query: {}'
.format(function_name, db_file, query))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -2267,7 +2274,7 @@ async def search_entries(db_file, query):
Entries of specified keywords as message.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Query {}.'
logger.debug('{}: db_file: {} query: {}'
.format(function_name, db_file, query))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -2339,7 +2346,7 @@ def check_entry_exist(db_file, feed_id, entry_id=None, title=None, link=None,
True or None.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Feed ID {}.'
logger.debug('{}: db_file: {} feed_id: {}'
.format(function_name, db_file, feed_id))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -2416,18 +2423,18 @@ async def set_setting_value(db_file, key_value):
Numeric value.
"""
key = key_value[0]
value = key_value[1]
val = key_value[1]
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}, Key {} and Value {}.'
.format(function_name, db_file, key, value))
logger.debug('{}: db_file: {} key: {} val: {}'
.format(function_name, db_file, key, val))
if not value:
if not val:
match key:
case 'interval':
value = 90
val = 90
case 'quantum':
value = 3
val = 3
async with DBLOCK:
with create_connection(db_file) as conn:
@ -2438,12 +2445,12 @@ async def set_setting_value(db_file, key_value):
INTO settings(
key, value)
VALUES(
:key, :value)
:key, :val)
"""
)
par = {
"key": key,
"value": value
"val": val
}
cur.execute(sql, par)
@ -2472,11 +2479,11 @@ async def update_setting_value(db_file, key_value):
# key = "enabled"
# val = 0
key = key_value[0]
value = key_value[1]
val = key_value[1]
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}, Key {} and Value {}.'
.format(function_name, db_file, key, value))
logger.debug('{}: db_file: {} key: {} val: {}'
.format(function_name, db_file, key, val))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -2484,13 +2491,13 @@ async def update_setting_value(db_file, key_value):
sql = (
"""
UPDATE settings
SET value = :value
SET value = :val
WHERE key = :key
"""
)
par = {
"key": key,
"value": value
"val": val
}
cur.execute(sql, par)
# except:
@ -2501,7 +2508,7 @@ async def update_setting_value(db_file, key_value):
async def delete_filter(db_file, key):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Key {}.'
logger.debug('{}: db_file: {} key: {}'
.format(function_name, db_file, key))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -2519,7 +2526,7 @@ async def delete_filter(db_file, key):
async def delete_setting(db_file, key):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Key {}.'
logger.debug('{}: db_file: {} key: {}'
.format(function_name, db_file, key))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -2537,7 +2544,7 @@ async def delete_setting(db_file, key):
async def delete_settings(db_file):
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
async with DBLOCK:
with create_connection(db_file) as conn:
@ -2569,7 +2576,7 @@ def get_setting_value(db_file, key):
Numeric value.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Key {}.'
logger.debug('{}: db_file: {} key: {}'
.format(function_name, db_file, key))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -2602,7 +2609,7 @@ def is_setting_key(db_file, key):
Key.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Key {}.'
logger.debug('{}: db_file: {} key: {}'
.format(function_name, db_file, key))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -2636,7 +2643,7 @@ async def set_filter_value(db_file, key_value):
val = key_value[1]
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}, Key {} and Value {}.'
logger.debug('{}: db_file: {} key: {} val: {}'
.format(function_name, db_file, key, val))
async with DBLOCK:
@ -2648,12 +2655,12 @@ async def set_filter_value(db_file, key_value):
INTO filters(
key, value)
VALUES(
:key, :value)
:key, :val)
"""
)
par = {
"key": key,
"value": val
"val": val
}
cur.execute(sql, par)
@ -2685,7 +2692,7 @@ async def update_filter_value(db_file, key_value):
val = key_value[1]
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}, Key {} and Value {}.'
logger.debug('{}: db_file: {} key: {} val: {}'
.format(function_name, db_file, key, val))
async with DBLOCK:
@ -2722,7 +2729,7 @@ def is_filter_key(db_file, key):
Key.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}, Key {}.'
logger.debug('{}: db_file: {} key: {}'
.format(function_name, db_file, key))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -2755,7 +2762,7 @@ def get_filter_value(db_file, key):
List of strings.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}, Key {}.'
logger.debug('{}: db_file: {} key: {}'
.format(function_name, db_file, key))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -2785,7 +2792,7 @@ async def set_last_update_time(db_file):
None.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -2820,7 +2827,7 @@ async def get_last_update_time(db_file):
Time.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -2855,7 +2862,7 @@ async def update_last_update_time(db_file):
None.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -2892,7 +2899,7 @@ def get_categories(db_file):
List of categories.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -2922,7 +2929,7 @@ def get_locales(db_file):
List of locales.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -2952,7 +2959,7 @@ def get_nations(db_file):
List of nations.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -3009,7 +3016,7 @@ def get_titles_tags_urls(db_file):
List of titles and urls.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {}.'
logger.debug('{}: db_file: {}'
.format(function_name, db_file))
with create_connection(db_file) as conn:
cur = conn.cursor()
@ -3040,7 +3047,7 @@ def get_titles_tags_urls_by_category(db_file, category):
List of titles and urls.
"""
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for filename {} and Category {}.'
logger.debug('{}: db_file: {} category: {}'
.format(function_name, db_file, category))
with create_connection(db_file) as conn:
cur = conn.cursor()

View file

@ -1,2 +1,2 @@
__version__ = '0.1.26'
__version_info__ = (0, 1, 26)
__version__ = '0.1.27'
__version_info__ = (0, 1, 27)

View file

@ -56,6 +56,7 @@ from slixfeed.xmpp.roster import XmppRoster
from slixfeed.xmpp.presence import XmppPresence
from slixfeed.xmpp.utility import get_chat_type
import sys
import time
import asyncio
from datetime import datetime
@ -181,10 +182,11 @@ class Slixfeed(slixmpp.ClientXMPP):
# TODO Test
async def on_groupchat_invite(self, message):
time_begin = time.time()
jid_full = str(message['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid_full))
message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full))
inviter = message['from'].bare
muc_jid = message['groupchat_invite']['jid']
await XmppBookmark.add(self, muc_jid)
@ -195,14 +197,19 @@ class Slixfeed(slixmpp.ClientXMPP):
'You may always reach me via xmpp:{}?message'
.format(self.alias, self.boundjid.bare))
XmppMessage.send(self, muc_jid, message_body, 'groupchat')
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
# NOTE Tested with Gajim and Psi
async def on_groupchat_direct_invite(self, message):
time_begin = time.time()
jid_full = str(message['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid_full))
message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full))
inviter = message['from'].bare
muc_jid = message['groupchat_invite']['jid']
await XmppBookmark.add(self, muc_jid)
@ -213,6 +220,10 @@ class Slixfeed(slixmpp.ClientXMPP):
'You may always reach me via xmpp:{}?message'
.format(self.alias, self.boundjid.bare))
XmppMessage.send(self, muc_jid, message_body, 'groupchat')
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
async def on_session_end(self, event):
@ -221,14 +232,23 @@ class Slixfeed(slixmpp.ClientXMPP):
async def on_connection_failed(self, event):
logger.info('Event connection_failed has been initiated.')
time_begin = time.time()
function_name = sys._getframe().f_code.co_name
message_log = '{}'
logger.debug(message_log.format(function_name))
message = 'Connection has failed. Reason: {}'.format(event)
XmppConnect.recover(self, message)
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
async def on_session_start(self, event):
time_begin = time.time()
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated.'.format(function_name))
message_log = '{}'
logger.debug(message_log.format(function_name))
# self.send_presence()
profile.set_identity(self, 'client')
# XmppCommand.adhoc_commands(self)
@ -244,32 +264,48 @@ class Slixfeed(slixmpp.ClientXMPP):
jid_op = config.get_value('accounts', 'XMPP', 'operator')
status_message = 'Slixfeed version {}'.format(__version__)
XmppPresence.send(self, jid_op, status_message)
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
def on_session_resumed(self, event):
time_begin = time.time()
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated.'.format(function_name))
message_log = '{}'
logger.debug(message_log.format(function_name))
# self.send_presence()
profile.set_identity(self, 'client')
self['xep_0115'].update_caps()
XmppGroupchat.autojoin(self)
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
async def on_disco_info(self, DiscoInfo):
time_begin = time.time()
jid_full = str(DiscoInfo['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid_full))
message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full))
# self.service_reactions()
# self.send_presence(pto=jid)
await self['xep_0115'].update_caps(jid=jid_full)
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
async def on_message(self, message):
time_begin = time.time()
jid_full = str(message['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid_full))
message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full))
jid_bare = message['from'].bare
if jid_bare == self.boundjid.bare:
status_type = 'dnd'
@ -296,13 +332,18 @@ class Slixfeed(slixmpp.ClientXMPP):
# chat_type = message["type"]
# message_body = message["body"]
# message_reply = message.reply
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
async def on_changed_status(self, presence):
time_begin = time.time()
jid_full = str(presence['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid_full))
message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full))
# await task.check_readiness(self, presence)
jid_bare = presence['from'].bare
if jid_bare in self.boundjid.bare:
@ -312,13 +353,18 @@ class Slixfeed(slixmpp.ClientXMPP):
task.clean_tasks_xmpp(self, jid_bare, key_list)
key_list = ['status', 'check']
await task.start_tasks_xmpp(self, jid_bare, key_list)
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
async def on_presence_subscribe(self, presence):
time_begin = time.time()
jid_full = str(presence['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid_full))
message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full))
jid_bare = presence['from'].bare
if not self.client_roster[jid_bare]['to']:
# XmppPresence.subscription(self, jid, 'subscribe')
@ -330,13 +376,18 @@ class Slixfeed(slixmpp.ClientXMPP):
message_body = 'Share online status to receive updates.'
XmppMessage.send_headline(self, jid_bare, message_subject,
message_body, 'chat')
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
def on_presence_subscribed(self, presence):
time_begin = time.time()
jid_full = str(presence['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid_full))
message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full))
message_subject = 'RSS News Bot'
message_body = ('Greetings! I am {}, the news anchor.\n'
'My job is to bring you the latest '
@ -347,13 +398,18 @@ class Slixfeed(slixmpp.ClientXMPP):
# XmppPresence.subscription(self, jid, 'subscribed')
XmppMessage.send_headline(self, jid_bare, message_subject,
message_body, 'chat')
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
async def on_presence_available(self, presence):
time_begin = time.time()
jid_full = str(presence['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid_full))
message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full))
# TODO Add function to check whether task is already running or not
# await task.start_tasks(self, presence)
# NOTE Already done inside the start-task function
@ -366,13 +422,19 @@ class Slixfeed(slixmpp.ClientXMPP):
await task.start_tasks_xmpp(self, jid_bare)
self.add_event_handler("presence_unavailable",
self.on_presence_unavailable)
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{}: jid_full: {} (time: {})'
.format(function_name, jid_full,
difference))
def on_presence_unsubscribed(self, presence):
time_begin = time.time()
jid_full = str(presence['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid_full))
message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full))
jid_bare = presence['from'].bare
message_body = 'You have been unsubscribed.'
# status_message = '🖋️ Subscribe to receive updates'
@ -382,16 +444,19 @@ class Slixfeed(slixmpp.ClientXMPP):
# XmppPresence.send(self, jid, status_message,
# presence_type='unsubscribed')
XmppRoster.remove(self, jid_bare)
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
def on_presence_unavailable(self, presence):
time_begin = time.time()
jid_full = str(presence['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid_full))
message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full))
jid_bare = presence['from'].bare
logger.info('Event presence_unavailable has been initiated for JID {}.'
.format(jid_bare))
# await task.stop_tasks(self, jid)
task.clean_tasks_xmpp(self, jid_bare)
@ -402,6 +467,10 @@ class Slixfeed(slixmpp.ClientXMPP):
presence_type='unavailable')
self.del_event_handler("presence_unavailable",
self.on_presence_unavailable)
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
# TODO
@ -410,12 +479,17 @@ class Slixfeed(slixmpp.ClientXMPP):
# If roster, remove contact JID into file
# If bookmarks, remove groupchat JID into file
def on_presence_error(self, presence):
time_begin = time.time()
jid_full = str(presence['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid_full))
message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full))
jid_bare = presence["from"].bare
task.clean_tasks_xmpp(self, jid_bare)
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
def on_reactions(self, message):
@ -424,10 +498,11 @@ class Slixfeed(slixmpp.ClientXMPP):
async def on_chatstate_active(self, message):
time_begin = time.time()
jid_full = str(message['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid_full))
message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full))
jid_bare = message['from'].bare
if jid_bare in self.boundjid.bare:
return
@ -439,13 +514,18 @@ class Slixfeed(slixmpp.ClientXMPP):
await asyncio.sleep(5)
key_list = ['status']
await task.start_tasks_xmpp(self, jid_bare, key_list)
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
async def on_chatstate_composing(self, message):
time_begin = time.time()
jid_full = str(message['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid_full))
message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full))
if message['type'] in ('chat', 'normal'):
jid_bare = message['from'].bare
# NOTE: Required for Cheogram
@ -456,13 +536,18 @@ class Slixfeed(slixmpp.ClientXMPP):
status_message = ('💡 Send "help" for manual, or "info" for '
'information.')
XmppPresence.send(self, jid_bare, status_message)
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
async def on_chatstate_gone(self, message):
time_begin = time.time()
jid_full = str(message['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid_full))
message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full))
jid_bare = message['from'].bare
if jid_bare in self.boundjid.bare:
return
@ -470,13 +555,18 @@ class Slixfeed(slixmpp.ClientXMPP):
# task.clean_tasks_xmpp(self, jid, ['status'])
key_list = ['status']
await task.start_tasks_xmpp(self, jid_bare, key_list)
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
async def on_chatstate_inactive(self, message):
time_begin = time.time()
jid_full = str(message['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid_full))
message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full))
jid_bare = message['from'].bare
if jid_bare in self.boundjid.bare:
return
@ -484,13 +574,18 @@ class Slixfeed(slixmpp.ClientXMPP):
# task.clean_tasks_xmpp(self, jid, ['status'])
key_list = ['status']
await task.start_tasks_xmpp(self, jid_bare, key_list)
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
async def on_chatstate_paused(self, message):
time_begin = time.time()
jid_full = str(message['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
.format(function_name, jid_full))
message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full))
jid_bare = message['from'].bare
if jid_bare in self.boundjid.bare:
return
@ -498,6 +593,10 @@ class Slixfeed(slixmpp.ClientXMPP):
# task.clean_tasks_xmpp(self, jid, ['status'])
key_list = ['status']
await task.start_tasks_xmpp(self, jid_bare, key_list)
time_end = time.time()
difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name,
difference))
@ -546,7 +645,8 @@ class Slixfeed(slixmpp.ClientXMPP):
def adhoc_commands(self):
logger.info('Function adhoc_commands has been initiated.')
function_name = sys._getframe().f_code.co_name
logger.debug('{}'.format(function_name))
# self["xep_0050"].add_command(
# node="updates_enable",
# name="Enable/Disable News Updates",
@ -598,7 +698,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_profile(self, iq, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
jid_file = jid_bare
@ -693,7 +793,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_filters(self, iq, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
chat_type = await get_chat_type(self, jid_bare)
@ -746,7 +846,7 @@ class Slixfeed(slixmpp.ClientXMPP):
"""
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
# Text is not displayed; only labels
form = payload
@ -784,7 +884,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_subscription_add(self, iq, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
chat_type = await get_chat_type(self, jid_bare)
@ -825,7 +925,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_recent(self, iq, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
form = self['xep_0004'].make_form('form', 'Updates')
form['instructions'] = 'Browse and read news'
@ -850,7 +950,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_recent_result(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
jid_file = jid_bare
@ -858,9 +958,9 @@ class Slixfeed(slixmpp.ClientXMPP):
num = 100
match payload['values']['action']:
case 'all':
results = await sqlite.get_entries(db_file, num)
results = await sqlite.get_entries(db_file, num) # FIXME
case 'rejected':
results = await sqlite.get_entries_rejected(db_file, num)
results = await sqlite.get_entries_rejected(db_file, num) # FIXME
case 'unread':
results = await sqlite.get_unread_entries(db_file, num)
if results:
@ -889,7 +989,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_recent_select(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
values = payload['values']
ix = values['update']
@ -956,7 +1056,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_recent_action(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
ext = payload['values']['filetype']
url = payload['values']['url'][0]
@ -1010,7 +1110,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_subscription_new(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
jid_file = jid_bare
@ -1137,7 +1237,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_subscription_enable(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
form = payload
jid_bare = session['from'].bare
@ -1171,7 +1271,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_subscription_disable(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
form = payload
jid_bare = session['from'].bare
@ -1205,7 +1305,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_subscription_del_complete(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
form = payload
jid_bare = session['from'].bare
@ -1239,7 +1339,7 @@ class Slixfeed(slixmpp.ClientXMPP):
def _handle_cancel(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
text_note = ('Operation has been cancelled.'
'\n'
@ -1252,7 +1352,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_discover(self, iq, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
chat_type = await get_chat_type(self, jid_bare)
@ -1284,7 +1384,7 @@ class Slixfeed(slixmpp.ClientXMPP):
def _handle_discover_type(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
values = payload['values']
search_type = values['search_type']
@ -1340,7 +1440,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_discover_category(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
values = payload['values']
category = values['category']
@ -1370,7 +1470,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_subscriptions(self, iq, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
chat_type = await get_chat_type(self, jid_bare)
@ -1403,7 +1503,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_subscriptions_result(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
jid_file = jid_bare
@ -1507,7 +1607,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_subscription_tag(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
jid_file = jid_bare
@ -1541,7 +1641,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_subscription(self, iq, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
form = self['xep_0004'].make_form('form', 'Subscription editor')
@ -1588,7 +1688,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_subscription_editor(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
jid_file = jid_bare
@ -1684,7 +1784,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_subscription_complete(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
values = payload['values']
@ -1749,7 +1849,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_subscription_selector(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
form = self['xep_0004'].make_form('form', 'Add Subscription')
@ -1791,7 +1891,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_advanced(self, iq, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
chat_type = await get_chat_type(self, jid_bare)
@ -1826,7 +1926,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_advanced_result(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
match payload['values']['option']:
case 'activity':
@ -1931,7 +2031,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_about(self, iq, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
form = self['xep_0004'].make_form('form', 'About')
form['instructions'] = 'Information about Slixfeed and related projects'
@ -1960,7 +2060,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_about_result(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
match payload['values']['option']:
case 'about':
@ -2043,7 +2143,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_motd(self, iq, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
# TODO add functionality to attach image.
# Here you can add groupchat rules,post schedule, tasks or
@ -2056,7 +2156,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_help(self, iq, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
import tomllib
@ -2098,7 +2198,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_import_complete(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
form = payload
url = payload['values']['url']
@ -2135,7 +2235,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_export_complete(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
form = payload
jid_bare = session['from'].bare
@ -2168,7 +2268,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_promoted(self, iq, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
jid_full = str(session['from'])
@ -2235,7 +2335,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_admin_action(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
jid_file = jid_bare
@ -2319,7 +2419,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_subscribers_complete(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
values = payload['values']
jid_bare = values['jid']
@ -2367,7 +2467,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_contact_action(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = payload['values']['jid']
form = self['xep_0004'].make_form('form', 'Contacts')
@ -2434,7 +2534,7 @@ class Slixfeed(slixmpp.ClientXMPP):
def _handle_contacts_complete(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
values = payload['values']
jid_bare = values['jid']
@ -2458,7 +2558,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_bookmarks_editor(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = payload['values']['jid']
properties = await XmppBookmark.properties(self, jid_bare)
@ -2523,7 +2623,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_bookmarks_complete(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
# form = self['xep_0004'].make_form('result', 'Done')
# form['instructions'] = ('✅️ Bookmark has been saved')
@ -2558,7 +2658,7 @@ class Slixfeed(slixmpp.ClientXMPP):
"""
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
chat_type = await get_chat_type(self, jid_bare)
@ -2671,7 +2771,7 @@ class Slixfeed(slixmpp.ClientXMPP):
async def _handle_settings_complete(self, payload, session):
jid_full = str(session['from'])
function_name = sys._getframe().f_code.co_name
logger.info('Function {} has been initiated for JID {}.'
logger.debug('{}: jid_full: {}'
.format(function_name, jid_full))
jid_bare = session['from'].bare
form = payload

2091
slixfeed/xmpp/command.py Normal file

File diff suppressed because it is too large Load diff