forked from sch/Slixfeed
Fix default alias upon joining to an MUC groupchat;
Scan subscriptions by last scanned time; Update file README.
This commit is contained in:
parent
fd07ae865a
commit
37444c9d4e
6 changed files with 142 additions and 8 deletions
|
@ -56,7 +56,7 @@ It is possible to install Slixfeed using pip and pipx.
|
|||
```
|
||||
$ python3 -m venv .venv
|
||||
$ source .venv/bin/activate
|
||||
$ pip install git+https://gitgud.io/sjehuda/slixfeed
|
||||
$ pip install git+https://git.xmpp-it.net/sch/Slixfeed
|
||||
```
|
||||
|
||||
#### pipx
|
||||
|
@ -64,14 +64,14 @@ $ pip install git+https://gitgud.io/sjehuda/slixfeed
|
|||
##### Install
|
||||
|
||||
```
|
||||
$ pipx install git+https://gitgud.io/sjehuda/slixfeed
|
||||
$ pipx install git+https://git.xmpp-it.net/sch/Slixfeed
|
||||
```
|
||||
|
||||
##### Update
|
||||
|
||||
```
|
||||
$ pipx uninstall slixfeed
|
||||
$ pipx install git+https://gitgud.io/sjehuda/slixfeed
|
||||
$ pipx install git+https://git.xmpp-it.net/sch/Slixfeed
|
||||
```
|
||||
|
||||
### Start
|
||||
|
|
|
@ -2762,6 +2762,39 @@ def get_active_feeds_url(db_file):
|
|||
return result
|
||||
|
||||
|
||||
def get_active_feeds_url_sorted_by_last_scanned(db_file):
|
||||
"""
|
||||
Query table feeds for active URLs and sort them by last scanned time.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
db_file : str
|
||||
Path to database file.
|
||||
|
||||
Returns
|
||||
-------
|
||||
result : tuple
|
||||
URLs of active feeds.
|
||||
"""
|
||||
function_name = sys._getframe().f_code.co_name
|
||||
logger.debug('{}: db_file: {}'
|
||||
.format(function_name, db_file))
|
||||
with create_connection(db_file) as conn:
|
||||
cur = conn.cursor()
|
||||
sql = (
|
||||
"""
|
||||
SELECT feeds_properties.url
|
||||
FROM feeds_properties
|
||||
INNER JOIN feeds_preferences ON feeds_properties.id = feeds_preferences.feed_id
|
||||
INNER JOIN feeds_state ON feeds_properties.id = feeds_state.feed_id
|
||||
WHERE feeds_preferences.enabled = 1
|
||||
ORDER BY feeds_state.scanned
|
||||
"""
|
||||
)
|
||||
result = cur.execute(sql).fetchall()
|
||||
return result
|
||||
|
||||
|
||||
def get_tags(db_file):
|
||||
"""
|
||||
Query table tags and list items.
|
||||
|
|
|
@ -1276,7 +1276,7 @@ class FeedTask:
|
|||
logger.info('Scanning for updates for JID {}'.format(jid_bare))
|
||||
while True:
|
||||
db_file = config.get_pathname_to_database(jid_bare)
|
||||
urls = sqlite.get_active_feeds_url(db_file)
|
||||
urls = sqlite.get_active_feeds_url_sorted_by_last_scanned(db_file)
|
||||
for url in urls:
|
||||
Message.printer('Scanning updates for URL {} ...'.format(url))
|
||||
url = url[0]
|
||||
|
@ -1360,7 +1360,7 @@ class FeedTask:
|
|||
# TODO return number of archived entries and add if statement to run archive maintainence function
|
||||
await sqlite.maintain_archive(db_file, limit)
|
||||
# await sqlite.process_invalid_entries(db_file, ixs)
|
||||
await asyncio.sleep(50)
|
||||
await asyncio.sleep(60 * 2)
|
||||
val = Config.get_setting_value(self.settings, jid_bare, 'check')
|
||||
await asyncio.sleep(60 * float(val))
|
||||
# Schedule to call this function again in 90 minutes
|
||||
|
|
|
@ -67,6 +67,107 @@ except:
|
|||
logger = Logger(__name__)
|
||||
|
||||
|
||||
class Config:
|
||||
|
||||
|
||||
def get_default_data_directory():
|
||||
if os.environ.get('HOME'):
|
||||
data_home = os.path.join(os.environ.get('HOME'), '.local', 'share')
|
||||
return os.path.join(data_home, 'kaikout')
|
||||
elif sys.platform == 'win32':
|
||||
data_home = os.environ.get('APPDATA')
|
||||
if data_home is None:
|
||||
return os.path.join(
|
||||
os.path.dirname(__file__) + '/kaikout_data')
|
||||
else:
|
||||
return os.path.join(os.path.dirname(__file__) + '/kaikout_data')
|
||||
|
||||
|
||||
def get_default_config_directory():
|
||||
"""
|
||||
Determine the directory path where configuration will be stored.
|
||||
|
||||
* If $XDG_CONFIG_HOME is defined, use it;
|
||||
* else if $HOME exists, use it;
|
||||
* else if the platform is Windows, use %APPDATA%;
|
||||
* else use the current directory.
|
||||
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
Path to configuration directory.
|
||||
"""
|
||||
# config_home = xdg.BaseDirectory.xdg_config_home
|
||||
config_home = os.environ.get('XDG_CONFIG_HOME')
|
||||
if config_home is None:
|
||||
if os.environ.get('HOME') is None:
|
||||
if sys.platform == 'win32':
|
||||
config_home = os.environ.get('APPDATA')
|
||||
if config_home is None:
|
||||
return os.path.abspath('.')
|
||||
else:
|
||||
return os.path.abspath('.')
|
||||
else:
|
||||
config_home = os.path.join(
|
||||
os.environ.get('HOME'), '.config'
|
||||
)
|
||||
return os.path.join(config_home, 'kaikout')
|
||||
|
||||
|
||||
def get_setting_value(db_file, key):
|
||||
value = sqlite.get_setting_value(db_file, key)
|
||||
if value:
|
||||
value = value[0]
|
||||
else:
|
||||
value = Config.get_value('settings', 'Settings', key)
|
||||
return value
|
||||
|
||||
|
||||
def get_values(filename, key=None):
|
||||
config_dir = Config.get_default_config_directory()
|
||||
if not os.path.isdir(config_dir):
|
||||
config_dir = '/usr/share/slixfeed/'
|
||||
if not os.path.isdir(config_dir):
|
||||
config_dir = os.path.dirname(__file__) + "/assets"
|
||||
config_file = os.path.join(config_dir, filename)
|
||||
with open(config_file, mode="rb") as defaults:
|
||||
result = tomllib.load(defaults)
|
||||
values = result[key] if key else result
|
||||
return values
|
||||
|
||||
|
||||
class Database:
|
||||
|
||||
|
||||
def instantiate(jid_bare):
|
||||
"""
|
||||
Callback function to instantiate action on database.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
jid_file : str
|
||||
Filename.
|
||||
callback : ?
|
||||
Function name.
|
||||
message : str, optional
|
||||
Optional kwarg when a message is a part or
|
||||
required argument. The default is None.
|
||||
|
||||
Returns
|
||||
-------
|
||||
object
|
||||
Coroutine object.
|
||||
"""
|
||||
db_dir = Config.get_default_data_directory()
|
||||
if not os.path.isdir(db_dir):
|
||||
os.mkdir(db_dir)
|
||||
if not os.path.isdir(db_dir + "/sqlite"):
|
||||
os.mkdir(db_dir + "/sqlite")
|
||||
db_file = os.path.join(db_dir, "sqlite", r"{}.db".format(jid_bare))
|
||||
sqlite.create_tables(db_file)
|
||||
return db_file
|
||||
|
||||
|
||||
class DateAndTime:
|
||||
|
||||
#https://feedparser.readthedocs.io/en/latest/date-parsing.html
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
__version__ = '0.1.85'
|
||||
__version_info__ = (0, 1, 85)
|
||||
__version__ = '0.1.86'
|
||||
__version_info__ = (0, 1, 86)
|
||||
|
|
|
@ -46,7 +46,7 @@ class XmppMuc:
|
|||
# )
|
||||
logger.info('Joining groupchat\nJID : {}\n'.format(jid))
|
||||
jid_from = str(self.boundjid) if self.is_component else None
|
||||
if alias == None: self.alias
|
||||
if not alias: alias = self.alias
|
||||
try:
|
||||
await self.plugin['xep_0045'].join_muc_wait(jid,
|
||||
alias,
|
||||
|
|
Loading…
Reference in a new issue