forked from sch/Slixfeed
Print version at startup
This commit is contained in:
parent
acce4fafdc
commit
e36816756c
5 changed files with 52 additions and 81 deletions
|
@ -1 +1,3 @@
|
||||||
__version__ = "1.0.0"
|
from slixfeed.version import __version__, __version_info__
|
||||||
|
|
||||||
|
print('Slixfeed', __version__)
|
|
@ -302,15 +302,6 @@ def list_feeds_by_query(query, results):
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
async def get_setting_value(db_file, key):
|
|
||||||
value = (
|
|
||||||
await sqlite.get_settings_value(db_file, key) or
|
|
||||||
config.get_value("settings", "Settings", key)
|
|
||||||
)
|
|
||||||
value = int(value)
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
|
||||||
async def list_statistics(db_file):
|
async def list_statistics(db_file):
|
||||||
"""
|
"""
|
||||||
Return table statistics.
|
Return table statistics.
|
||||||
|
@ -331,10 +322,10 @@ async def list_statistics(db_file):
|
||||||
entries_all = entries + archive
|
entries_all = entries + archive
|
||||||
feeds_active = await sqlite.get_number_of_feeds_active(db_file)
|
feeds_active = await sqlite.get_number_of_feeds_active(db_file)
|
||||||
feeds_all = await sqlite.get_number_of_items(db_file, 'feeds')
|
feeds_all = await sqlite.get_number_of_items(db_file, 'feeds')
|
||||||
key_archive = await get_setting_value(db_file, "archive")
|
key_archive = await config.get_setting_value(db_file, 'archive')
|
||||||
key_interval = await get_setting_value(db_file, "interval")
|
key_interval = await config.get_setting_value(db_file, 'interval')
|
||||||
key_quantum = await get_setting_value(db_file, "quantum")
|
key_quantum = await config.get_setting_value(db_file, 'quantum')
|
||||||
key_enabled = await get_setting_value(db_file, "enabled")
|
key_enabled = await config.get_setting_value(db_file, 'enabled')
|
||||||
|
|
||||||
# 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)
|
||||||
|
@ -533,7 +524,7 @@ async def add_feed(db_file, url):
|
||||||
updated=updated
|
updated=updated
|
||||||
)
|
)
|
||||||
await scan(db_file, url)
|
await scan(db_file, url)
|
||||||
old = await get_setting_value(db_file, "old")
|
old = await config.get_setting_value(db_file, "old")
|
||||||
if not old:
|
if not old:
|
||||||
feed_id = await sqlite.get_feed_id(db_file, url)
|
feed_id = await sqlite.get_feed_id(db_file, url)
|
||||||
feed_id = feed_id[0]
|
feed_id = feed_id[0]
|
||||||
|
@ -580,7 +571,7 @@ async def add_feed(db_file, url):
|
||||||
)
|
)
|
||||||
await scan_json(
|
await scan_json(
|
||||||
db_file, url)
|
db_file, url)
|
||||||
old = await get_setting_value(db_file, "old")
|
old = await config.get_setting_value(db_file, "old")
|
||||||
if not old:
|
if not old:
|
||||||
feed_id = await sqlite.get_feed_id(db_file, url)
|
feed_id = await sqlite.get_feed_id(db_file, url)
|
||||||
feed_id = feed_id[0]
|
feed_id = feed_id[0]
|
||||||
|
@ -1334,7 +1325,7 @@ async def remove_nonexistent_entries(db_file, url, feed):
|
||||||
else:
|
else:
|
||||||
# print(">>> ARCHIVING:", entry_title)
|
# print(">>> ARCHIVING:", entry_title)
|
||||||
await sqlite.archive_entry(db_file, ix)
|
await sqlite.archive_entry(db_file, ix)
|
||||||
limit = await get_setting_value(db_file, "archive")
|
limit = await config.get_setting_value(db_file, "archive")
|
||||||
await sqlite.maintain_archive(db_file, limit)
|
await sqlite.maintain_archive(db_file, limit)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1407,5 +1398,5 @@ async def remove_nonexistent_entries_json(db_file, url, feed):
|
||||||
await sqlite.delete_entry_by_id(db_file, ix)
|
await sqlite.delete_entry_by_id(db_file, ix)
|
||||||
else:
|
else:
|
||||||
await sqlite.archive_entry(db_file, ix)
|
await sqlite.archive_entry(db_file, ix)
|
||||||
limit = await get_setting_value(db_file, "archive")
|
limit = await config.get_setting_value(db_file, "archive")
|
||||||
await sqlite.maintain_archive(db_file, limit)
|
await sqlite.maintain_archive(db_file, limit)
|
|
@ -30,6 +30,15 @@ import sys
|
||||||
import tomli_w
|
import tomli_w
|
||||||
import tomllib
|
import tomllib
|
||||||
|
|
||||||
|
async def get_setting_value(db_file, key):
|
||||||
|
value = (
|
||||||
|
await sqlite.get_settings_value(db_file, key) or
|
||||||
|
get_value("settings", "Settings", key)
|
||||||
|
)
|
||||||
|
value = int(value)
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
# TODO Merge with backup_obsolete
|
# TODO Merge with backup_obsolete
|
||||||
def update_proxies(file, proxy_name, proxy_type, proxy_url, action='remove'):
|
def update_proxies(file, proxy_name, proxy_type, proxy_url, action='remove'):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -43,25 +43,9 @@ import asyncio
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import slixfeed.action as action
|
import slixfeed.action as action
|
||||||
from slixfeed.config import (
|
import slixfeed.config as config
|
||||||
get_pathname_to_database,
|
|
||||||
get_default_data_directory,
|
|
||||||
get_value)
|
|
||||||
# from slixfeed.dt import current_time
|
# from slixfeed.dt import current_time
|
||||||
from slixfeed.sqlite import (
|
import slixfeed.sqlite as sqlite
|
||||||
delete_archived_entry,
|
|
||||||
get_feed_title,
|
|
||||||
get_feeds_url,
|
|
||||||
get_last_update_time,
|
|
||||||
get_number_of_entries_unread,
|
|
||||||
get_number_of_items,
|
|
||||||
get_settings_value,
|
|
||||||
get_unread_entries,
|
|
||||||
mark_as_read,
|
|
||||||
mark_entry_as_read,
|
|
||||||
set_last_update_time,
|
|
||||||
update_last_update_time
|
|
||||||
)
|
|
||||||
# from xmpp import Slixfeed
|
# from xmpp import Slixfeed
|
||||||
import slixfeed.xmpp.client as xmpp
|
import slixfeed.xmpp.client as xmpp
|
||||||
import slixfeed.xmpp.connect as connect
|
import slixfeed.xmpp.connect as connect
|
||||||
|
@ -137,18 +121,16 @@ async def start_tasks_xmpp(self, jid, tasks=None):
|
||||||
case 'check':
|
case 'check':
|
||||||
task_manager[jid]['check'] = asyncio.create_task(
|
task_manager[jid]['check'] = asyncio.create_task(
|
||||||
check_updates(jid))
|
check_updates(jid))
|
||||||
case "status":
|
case 'status':
|
||||||
task_manager[jid]['status'] = asyncio.create_task(
|
task_manager[jid]['status'] = asyncio.create_task(
|
||||||
send_status(self, jid))
|
send_status(self, jid))
|
||||||
case 'interval':
|
case 'interval':
|
||||||
jid_file = jid.replace('/', '_')
|
jid_file = jid.replace('/', '_')
|
||||||
db_file = get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
update_interval = (
|
update_interval = await config.get_setting_value(db_file,
|
||||||
await get_settings_value(db_file, "interval") or
|
'interval')
|
||||||
get_value("settings", "Settings", "interval")
|
|
||||||
)
|
|
||||||
update_interval = 60 * int(update_interval)
|
update_interval = 60 * int(update_interval)
|
||||||
last_update_time = await get_last_update_time(db_file)
|
last_update_time = await 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
|
||||||
|
@ -166,10 +148,10 @@ async def start_tasks_xmpp(self, jid, tasks=None):
|
||||||
|
|
||||||
# elif diff > val:
|
# elif diff > val:
|
||||||
# next_update_time = val
|
# next_update_time = val
|
||||||
await update_last_update_time(db_file)
|
await sqlite.update_last_update_time(db_file)
|
||||||
else:
|
else:
|
||||||
await set_last_update_time(db_file)
|
await sqlite.set_last_update_time(db_file)
|
||||||
task_manager[jid]["interval"] = asyncio.create_task(
|
task_manager[jid]['interval'] = asyncio.create_task(
|
||||||
send_update(self, jid))
|
send_update(self, jid))
|
||||||
# for task in task_manager[jid].values():
|
# for task in task_manager[jid].values():
|
||||||
# print("task_manager[jid].values()")
|
# print("task_manager[jid].values()")
|
||||||
|
@ -208,21 +190,15 @@ async def send_update(self, jid, num=None):
|
||||||
"""
|
"""
|
||||||
logging.info('Sending a news update to JID {}'.format(jid))
|
logging.info('Sending a news update to JID {}'.format(jid))
|
||||||
jid_file = jid.replace('/', '_')
|
jid_file = jid.replace('/', '_')
|
||||||
db_file = get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
enabled = (
|
enabled = await config.get_setting_value(db_file, 'enabled')
|
||||||
await get_settings_value(db_file, "enabled") or
|
|
||||||
get_value("settings", "Settings", "enabled")
|
|
||||||
)
|
|
||||||
if enabled:
|
if enabled:
|
||||||
if not num:
|
if not num:
|
||||||
num = (
|
num = await config.get_setting_value(db_file, 'quantum')
|
||||||
await get_settings_value(db_file, "quantum") or
|
|
||||||
get_value("settings", "Settings", "quantum")
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
num = int(num)
|
num = int(num)
|
||||||
news_digest = []
|
news_digest = []
|
||||||
results = await get_unread_entries(db_file, num)
|
results = await sqlite.get_unread_entries(db_file, num)
|
||||||
news_digest = ''
|
news_digest = ''
|
||||||
media = None
|
media = None
|
||||||
chat_type = await utility.get_chat_type(self, jid)
|
chat_type = await utility.get_chat_type(self, jid)
|
||||||
|
@ -233,13 +209,13 @@ async def send_update(self, jid, num=None):
|
||||||
enclosure = result[3]
|
enclosure = result[3]
|
||||||
feed_id = result[4]
|
feed_id = result[4]
|
||||||
date = result[5]
|
date = result[5]
|
||||||
title_f = get_feed_title(db_file, feed_id)
|
title_f = sqlite.get_feed_title(db_file, feed_id)
|
||||||
title_f = title_f[0]
|
title_f = title_f[0]
|
||||||
news_digest += action.list_unread_entries(result, title_f)
|
news_digest += action.list_unread_entries(result, title_f)
|
||||||
# print(db_file)
|
# print(db_file)
|
||||||
# print(result[0])
|
# print(result[0])
|
||||||
# breakpoint()
|
# breakpoint()
|
||||||
await mark_as_read(db_file, ix)
|
await sqlite.mark_as_read(db_file, ix)
|
||||||
|
|
||||||
# Find media
|
# Find media
|
||||||
# if url.startswith("magnet:"):
|
# if url.startswith("magnet:"):
|
||||||
|
@ -278,7 +254,7 @@ async def send_update(self, jid, num=None):
|
||||||
# TODO Add while loop to assure delivery.
|
# TODO Add while loop to assure delivery.
|
||||||
# print(await current_time(), ">>> ACT send_message",jid)
|
# print(await current_time(), ">>> ACT send_message",jid)
|
||||||
# NOTE Do we need "if statement"? See NOTE at is_muc.
|
# NOTE Do we need "if statement"? See NOTE at is_muc.
|
||||||
if chat_type in ("chat", "groupchat"):
|
if chat_type in ('chat', 'groupchat'):
|
||||||
# TODO Provide a choice (with or without images)
|
# TODO Provide a choice (with or without images)
|
||||||
xmpp.Slixfeed.send_message(
|
xmpp.Slixfeed.send_message(
|
||||||
self,
|
self,
|
||||||
|
@ -298,10 +274,10 @@ async def send_update(self, jid, num=None):
|
||||||
# TODO Do not refresh task before
|
# TODO Do not refresh task before
|
||||||
# verifying that it was completed.
|
# verifying that it was completed.
|
||||||
await refresh_task(
|
await refresh_task(
|
||||||
self, jid, send_update, "interval")
|
self, jid, send_update, 'interval')
|
||||||
# interval = await initdb(
|
# interval = await initdb(
|
||||||
# jid,
|
# jid,
|
||||||
# get_settings_value,
|
# sqlite.get_settings_value,
|
||||||
# "interval"
|
# "interval"
|
||||||
# )
|
# )
|
||||||
# task_manager[jid]["interval"] = loop.call_at(
|
# task_manager[jid]["interval"] = loop.call_at(
|
||||||
|
@ -336,22 +312,19 @@ async def send_status(self, jid):
|
||||||
logging.info('Sending a status message to JID {}'.format(jid))
|
logging.info('Sending a status message to JID {}'.format(jid))
|
||||||
status_text = '📜️ Slixfeed RSS News Bot'
|
status_text = '📜️ Slixfeed RSS News Bot'
|
||||||
jid_file = jid.replace('/', '_')
|
jid_file = jid.replace('/', '_')
|
||||||
db_file = get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
enabled = (
|
enabled = await config.get_setting_value(db_file, 'enabled')
|
||||||
await get_settings_value(db_file, "enabled") or
|
|
||||||
get_value("settings", "Settings", "enabled")
|
|
||||||
)
|
|
||||||
if not enabled:
|
if not enabled:
|
||||||
status_mode = 'xa'
|
status_mode = 'xa'
|
||||||
status_text = '📫️ Send "Start" to receive updates'
|
status_text = '📫️ Send "Start" to receive updates'
|
||||||
else:
|
else:
|
||||||
feeds = await get_number_of_items(db_file, 'feeds')
|
feeds = await 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 get_number_of_entries_unread(db_file)
|
unread = await 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))
|
||||||
|
@ -399,11 +372,8 @@ async def refresh_task(self, jid, callback, key, val=None):
|
||||||
logging.info('Refreshing task {} for JID {}'.format(callback, jid))
|
logging.info('Refreshing task {} for JID {}'.format(callback, jid))
|
||||||
if not val:
|
if not val:
|
||||||
jid_file = jid.replace('/', '_')
|
jid_file = jid.replace('/', '_')
|
||||||
db_file = get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
val = (
|
val = await config.get_setting_value(db_file, key)
|
||||||
await get_settings_value(db_file, key) or
|
|
||||||
get_value("settings", "Settings", key)
|
|
||||||
)
|
|
||||||
# if task_manager[jid][key]:
|
# if task_manager[jid][key]:
|
||||||
if jid in task_manager:
|
if jid in task_manager:
|
||||||
try:
|
try:
|
||||||
|
@ -452,12 +422,11 @@ async def check_updates(jid):
|
||||||
logging.info('Scanning for updates for JID {}'.format(jid))
|
logging.info('Scanning for updates for JID {}'.format(jid))
|
||||||
while True:
|
while True:
|
||||||
jid_file = jid.replace('/', '_')
|
jid_file = jid.replace('/', '_')
|
||||||
db_file = get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
urls = await get_feeds_url(db_file)
|
urls = await sqlite.get_feeds_url(db_file)
|
||||||
for url in urls:
|
for url in urls:
|
||||||
await action.scan(db_file, url)
|
await action.scan(db_file, url)
|
||||||
val = get_value(
|
val = config.get_value('settings', 'Settings', 'check')
|
||||||
"settings", "Settings", "check")
|
|
||||||
await asyncio.sleep(60 * float(val))
|
await asyncio.sleep(60 * float(val))
|
||||||
# Schedule to call this function again in 90 minutes
|
# Schedule to call this function again in 90 minutes
|
||||||
# loop.call_at(
|
# loop.call_at(
|
||||||
|
@ -478,7 +447,7 @@ async def select_file(self):
|
||||||
Initiate actions by JID (Jabber ID).
|
Initiate actions by JID (Jabber ID).
|
||||||
"""
|
"""
|
||||||
while True:
|
while True:
|
||||||
db_dir = get_default_data_directory()
|
db_dir = config.get_default_data_directory()
|
||||||
if not os.path.isdir(db_dir):
|
if not os.path.isdir(db_dir):
|
||||||
msg = ('Slixfeed does not work without a database.\n'
|
msg = ('Slixfeed does not work without a database.\n'
|
||||||
'To create a database, follow these steps:\n'
|
'To create a database, follow these steps:\n'
|
||||||
|
@ -498,8 +467,8 @@ async def select_file(self):
|
||||||
# await jid_tasker[jid]
|
# await jid_tasker[jid]
|
||||||
async with asyncio.TaskGroup() as tg:
|
async with asyncio.TaskGroup() as tg:
|
||||||
for file in files:
|
for file in files:
|
||||||
if (file.endswith(".db") and
|
if (file.endswith('.db') and
|
||||||
not file.endswith(".db-jour.db")):
|
not file.endswith('.db-jour.db')):
|
||||||
jid = file[:-3]
|
jid = file[:-3]
|
||||||
main_task.extend(
|
main_task.extend(
|
||||||
[tg.create_task(self.task_jid(jid))]
|
[tg.create_task(self.task_jid(jid))]
|
||||||
|
|
|
@ -306,7 +306,7 @@ async def message(self, message):
|
||||||
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(db_file, url)
|
await action.scan(db_file, url)
|
||||||
old = await action.get_setting_value(db_file, "old")
|
old = await config.get_setting_value(db_file, "old")
|
||||||
if old:
|
if old:
|
||||||
# await task.clean_tasks_xmpp(jid, ['status'])
|
# await task.clean_tasks_xmpp(jid, ['status'])
|
||||||
# await send_status(jid)
|
# await send_status(jid)
|
||||||
|
|
Loading…
Reference in a new issue