diff --git a/slixfeed/__main__.py b/slixfeed/__main__.py index 2fbef5e..88941a4 100644 --- a/slixfeed/__main__.py +++ b/slixfeed/__main__.py @@ -69,6 +69,10 @@ TODO 17) Make the program portable (directly use the directory assets) -- Thorsten +18) The operator account will be given reports from the bot about its + activities every X minutes. + When a suspicious activity is detected, it will be reported immediately. + """ # vars and their meanings: diff --git a/slixfeed/action.py b/slixfeed/action.py index 0292334..7454358 100644 --- a/slixfeed/action.py +++ b/slixfeed/action.py @@ -16,6 +16,12 @@ TODO 2) Call sqlite function from function statistics. Returning a list of values doesn't' seem to be a good practice. +3) Special statistics for operator: + * Size of database(s); + * Amount of JIDs subscribed; + * Amount of feeds of all JIDs; + * Amount of entries of all JIDs. + """ from asyncio.exceptions import IncompleteReadError @@ -225,7 +231,15 @@ def list_feeds_by_query(query, results): return message -def list_statistics(values): +async def get_setting_value(db_file, key): + value = ( + await sqlite.get_settings_value(db_file, key) or + config.get_value_default("settings", "Settings", key) + ) + return value + + +async def list_statistics(db_file): """ Return table statistics. @@ -239,6 +253,27 @@ def list_statistics(values): msg : str Statistics as message. """ + entries_unread = await sqlite.get_number_of_entries_unread(db_file) + entries = await sqlite.get_number_of_items(db_file, 'entries') + archive = await sqlite.get_number_of_items(db_file, 'archive') + entries_all = entries + archive + feeds_active = await sqlite.get_number_of_feeds_active(db_file) + feeds_all = await sqlite.get_number_of_items(db_file, 'feeds') + key_archive = await get_setting_value(db_file, "archive") + key_interval = await get_setting_value(db_file, "interval") + key_quantum = await get_setting_value(db_file, "quantum") + key_enabled = await get_setting_value(db_file, "enabled") + + # msg = """You have {} unread news items out of {} from {} news sources. + # """.format(unread_entries, entries, feeds) + + # try: + # value = cur.execute(sql, par).fetchone()[0] + # except: + # print("Error for key:", key) + # value = "Default" + # values.extend([value]) + message = ( "```" "\nSTATISTICS\n" @@ -250,8 +285,16 @@ def list_statistics(values): "Items per update : {}\n" "Operation status : {}\n" "```" - ).format(values[0], values[1], values[2], values[3], - values[4], values[5], values[6], values[7]) + ).format( + entries_unread, + entries_all, + feeds_active, + feeds_all, + key_archive, + key_interval, + key_quantum, + key_enabled + ) return message diff --git a/slixfeed/fetch.py b/slixfeed/fetch.py index 5fca196..8bc03fa 100644 --- a/slixfeed/fetch.py +++ b/slixfeed/fetch.py @@ -16,9 +16,7 @@ TODO 3) Add "if utility.is_feed(url, feed)" to view_entry and view_feed -4) Refactor view_entry and view_feed - Why "if" twice? - -5) Replace sqlite.remove_nonexistent_entries by sqlite.check_entry_exist +4) Replace sqlite.remove_nonexistent_entries by sqlite.check_entry_exist Same check, just reverse. """ diff --git a/slixfeed/sqlite.py b/slixfeed/sqlite.py index eeaee28..84117be 100644 --- a/slixfeed/sqlite.py +++ b/slixfeed/sqlite.py @@ -961,48 +961,6 @@ async def delete_archived_entry(cur, ix): cur.execute(sql, par) -async def statistics(db_file): - """ - Return table statistics. - - Parameters - ---------- - db_file : str - Path to database file. - - Returns - ------- - values : list - List of values. - """ - values = [] - values.extend([await get_number_of_entries_unread(db_file)]) - entries = await get_number_of_items(db_file, 'entries') - archive = await get_number_of_items(db_file, 'archive') - values.extend([entries + archive]) - values.extend([await get_number_of_feeds_active(db_file)]) - values.extend([await get_number_of_items(db_file, 'feeds')]) - # msg = """You have {} unread news items out of {} from {} news sources. - # """.format(unread_entries, entries, feeds) - with create_connection(db_file) as conn: - cur = conn.cursor() - for key in ["archive", "interval", - "quantum", "enabled"]: - sql = ( - "SELECT value " - "FROM settings " - "WHERE key = ?" - ) - par = (key,) - try: - value = cur.execute(sql, par).fetchone()[0] - except: - print("Error for key:", key) - value = "Default" - values.extend([value]) - return values - - async def update_statistics(cur): """ Update table statistics. diff --git a/slixfeed/xmpp/process.py b/slixfeed/xmpp/process.py index 2d3b7b9..a7794b5 100644 --- a/slixfeed/xmpp/process.py +++ b/slixfeed/xmpp/process.py @@ -756,13 +756,6 @@ async def message(self, message): # "Every update will contain {} news items." # ).format(response) db_file = get_pathname_to_database(jid) - a = await sqlite.get_settings_value(db_file, key) - print(a) - print(key) - print(val) - print(a) - print(a) - print(a) if await sqlite.get_settings_value( db_file, key): await sqlite.update_settings_value( @@ -927,8 +920,7 @@ async def message(self, message): send_reply_message(self, message, response) case "stats": db_file = get_pathname_to_database(jid) - result = await sqlite.statistics(db_file) - response = action.list_statistics(result) + response = await action.list_statistics(db_file) send_reply_message(self, message, response) case _ if message_lowercase.startswith("disable "): ix = message_text[8:]