Settings: Manage several class instance objects.
This commit is contained in:
parent
9969f8ded1
commit
aa5f45cddc
7 changed files with 173 additions and 66 deletions
|
@ -80,12 +80,14 @@ import os
|
||||||
#import slixfeed.matrix
|
#import slixfeed.matrix
|
||||||
|
|
||||||
import slixfeed.config as config
|
import slixfeed.config as config
|
||||||
|
from slixfeed.config import ConfigXMPP
|
||||||
from slixfeed.version import __version__
|
from slixfeed.version import __version__
|
||||||
|
|
||||||
import socks
|
# import socks
|
||||||
import socket
|
# import socket
|
||||||
|
|
||||||
xmpp_type = config.get_value('accounts', 'XMPP', 'type')
|
base = ConfigXMPP()
|
||||||
|
xmpp_type = base.setting['type']
|
||||||
|
|
||||||
if not xmpp_type:
|
if not xmpp_type:
|
||||||
raise Exception('Key type is missing from accounts.ini.')
|
raise Exception('Key type is missing from accounts.ini.')
|
||||||
|
@ -93,9 +95,12 @@ if not xmpp_type:
|
||||||
match xmpp_type:
|
match xmpp_type:
|
||||||
case 'client':
|
case 'client':
|
||||||
from slixfeed.xmpp.client import Slixfeed
|
from slixfeed.xmpp.client import Slixfeed
|
||||||
|
from slixfeed.config import ConfigClient as ConfigAccount
|
||||||
case 'component':
|
case 'component':
|
||||||
from slixfeed.xmpp.component import SlixfeedComponent
|
from slixfeed.xmpp.component import SlixfeedComponent
|
||||||
|
from slixfeed.config import ConfigComponent as ConfigAccount
|
||||||
|
|
||||||
|
account = ConfigAccount()
|
||||||
|
|
||||||
class JabberComponent:
|
class JabberComponent:
|
||||||
def __init__(self, jid, secret, hostname, port, alias=None):
|
def __init__(self, jid, secret, hostname, port, alias=None):
|
||||||
|
@ -172,10 +177,8 @@ class JabberClient:
|
||||||
|
|
||||||
# Connect to the XMPP server and start processing XMPP stanzas.
|
# Connect to the XMPP server and start processing XMPP stanzas.
|
||||||
|
|
||||||
address = config.get_value('accounts', 'XMPP Client',
|
if account.setting['hostname'] and account.setting['port']:
|
||||||
['hostname', 'port'])
|
xmpp.connect((account.setting['hostname'], account.setting['port']))
|
||||||
if address[0] and address[1]:
|
|
||||||
xmpp.connect(tuple(address))
|
|
||||||
else:
|
else:
|
||||||
xmpp.connect()
|
xmpp.connect()
|
||||||
xmpp.process()
|
xmpp.process()
|
||||||
|
@ -240,13 +243,11 @@ def main():
|
||||||
# logwrn = logger.warning
|
# logwrn = logger.warning
|
||||||
|
|
||||||
# Try configuration file
|
# Try configuration file
|
||||||
key_list = ['alias', 'jid', 'password', 'hostname', 'port']
|
alias = account.setting['alias']
|
||||||
values = config.get_value('accounts', 'XMPP Client', key_list)
|
jid = account.setting['jid']
|
||||||
alias = values[0]
|
password = account.setting['password']
|
||||||
jid = values[1]
|
hostname = account.setting['hostname']
|
||||||
password = values[2]
|
port = account.setting['port']
|
||||||
hostname = values[3]
|
|
||||||
port = values[4]
|
|
||||||
|
|
||||||
# Use arguments if were given
|
# Use arguments if were given
|
||||||
if args.jid:
|
if args.jid:
|
||||||
|
|
|
@ -18,7 +18,10 @@ check = 120
|
||||||
# Work status (Value 0 to disable)
|
# Work status (Value 0 to disable)
|
||||||
enabled = 1
|
enabled = 1
|
||||||
|
|
||||||
# Update interval (Minimum value 10)
|
# Enable filters (Value 1 to enable)
|
||||||
|
filter = 0
|
||||||
|
|
||||||
|
# Update interval in minutes (Minimum value 10)
|
||||||
interval = 300
|
interval = 300
|
||||||
|
|
||||||
# Maximum length of summary (Value 0 to disable)
|
# Maximum length of summary (Value 0 to disable)
|
||||||
|
@ -56,7 +59,7 @@ yggdrasil =
|
||||||
http_proxy =
|
http_proxy =
|
||||||
|
|
||||||
# User Agent
|
# User Agent
|
||||||
user-agent = Slixfeed/0.1
|
user_agent = Slixfeed/0.1
|
||||||
|
|
||||||
# Enable policed DNS system (not recommended)
|
# Enable policed DNS system (not recommended)
|
||||||
# clearnet = 1
|
# clearnet = 1
|
||||||
|
|
|
@ -3,6 +3,12 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
FIXME
|
||||||
|
|
||||||
|
1) Use dict for ConfigDefault
|
||||||
|
|
||||||
|
2) Store ConfigJabberID in dicts
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
|
|
||||||
1) Website-specific filter (i.e. audiobookbay).
|
1) Website-specific filter (i.e. audiobookbay).
|
||||||
|
@ -42,15 +48,86 @@ except:
|
||||||
# also initiated at same level or at least at event call, then check whether
|
# also initiated at same level or at least at event call, then check whether
|
||||||
# setting_jid.setting_key has value, otherwise resort to setting_default.setting_key.
|
# setting_jid.setting_key has value, otherwise resort to setting_default.setting_key.
|
||||||
class Config:
|
class Config:
|
||||||
def __init__(self, db_file):
|
def __init__(self):
|
||||||
self.archive = get_setting_value(db_file, 'archive')
|
self.settings = {}
|
||||||
self.enabled = get_setting_value(db_file, 'enabled')
|
# initiate an empty dict and the rest would be:
|
||||||
self.formatting = get_setting_value(db_file, 'formatting')
|
# settings['account'] = {}
|
||||||
self.interval = get_setting_value(db_file, 'interval')
|
# settings['default'] = {}
|
||||||
self.length = get_setting_value(db_file, 'length')
|
# settings['jabber@id'] = {}
|
||||||
self.media = get_setting_value(db_file, 'media')
|
# def __init__(self, db_file):
|
||||||
self.old = get_setting_value(db_file, 'old')
|
# self.archive = get_setting_value(db_file, 'archive')
|
||||||
self.quantum = get_setting_value(db_file, 'quantum')
|
# self.enabled = get_setting_value(db_file, 'enabled')
|
||||||
|
# self.formatting = get_setting_value(db_file, 'formatting')
|
||||||
|
# self.interval = get_setting_value(db_file, 'interval')
|
||||||
|
# self.length = get_setting_value(db_file, 'length')
|
||||||
|
# self.media = get_setting_value(db_file, 'media')
|
||||||
|
# self.old = get_setting_value(db_file, 'old')
|
||||||
|
# self.quantum = get_setting_value(db_file, 'quantum')
|
||||||
|
|
||||||
|
# def default():
|
||||||
|
# archive = get_value('settings', 'Settings', 'archive')
|
||||||
|
# enabled = get_value('settings', 'Settings', 'enabled')
|
||||||
|
# formatting = get_value('settings', 'Settings', 'formatting')
|
||||||
|
# interval = get_value('settings', 'Settings', 'interval')
|
||||||
|
# length = get_value('settings', 'Settings', 'length')
|
||||||
|
# media = get_value('settings', 'Settings', 'media')
|
||||||
|
# old = get_value('settings', 'Settings', 'old')
|
||||||
|
# quantum = get_value('settings', 'Settings', 'quantum')
|
||||||
|
|
||||||
|
# def jid(db_file):
|
||||||
|
# archive = sqlite.get_setting_value(db_file, 'archive')
|
||||||
|
# enabled = sqlite.get_setting_value(db_file, 'enabled')
|
||||||
|
# formatting = sqlite.get_setting_value(db_file, 'formatting')
|
||||||
|
# interval = sqlite.get_setting_value(db_file, 'interval')
|
||||||
|
# length = sqlite.get_setting_value(db_file, 'length')
|
||||||
|
# media = sqlite.get_setting_value(db_file, 'media')
|
||||||
|
# old = sqlite.get_setting_value(db_file, 'old')
|
||||||
|
# quantum = sqlite.get_setting_value(db_file, 'quantum')
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigDefault:
|
||||||
|
def __init__(self):
|
||||||
|
self.setting = {}
|
||||||
|
for key in ('archive', 'check', 'enabled', 'filter', 'formatting',
|
||||||
|
'interval', 'length', 'media', 'old', 'quantum'):
|
||||||
|
value = get_value('settings', 'Settings', key)
|
||||||
|
self.setting[key] = value
|
||||||
|
|
||||||
|
class ConfigNetwork:
|
||||||
|
def __init__(self):
|
||||||
|
self.setting = {}
|
||||||
|
for key in ('http_proxy', 'user_agent'):
|
||||||
|
value = get_value('settings', 'Network', key)
|
||||||
|
self.setting[key] = value
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigXMPP:
|
||||||
|
def __init__(self):
|
||||||
|
self.setting = {}
|
||||||
|
for key in ('operator', 'reconnect_timeout', 'type'):
|
||||||
|
value = get_value('accounts', 'XMPP', key)
|
||||||
|
self.setting[key] = value
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigClient:
|
||||||
|
def __init__(self):
|
||||||
|
self.setting = {}
|
||||||
|
for key in ('alias', 'jid', 'operator', 'password', 'hostname', 'port'):
|
||||||
|
value = get_value('accounts', 'XMPP Client', key)
|
||||||
|
self.setting[key] = value
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigJabberID:
|
||||||
|
def __init__(self, jid_bare=None, db_file=None):
|
||||||
|
self.setting = {}
|
||||||
|
if jid_bare and db_file:
|
||||||
|
self.setting[jid_bare] = {}
|
||||||
|
for key in ('archive', 'enabled', 'filter', 'formatting', 'interval',
|
||||||
|
'length', 'media', 'old', 'quantum'):
|
||||||
|
value = sqlite.get_setting_value(db_file, key)
|
||||||
|
if value: value = value[0]
|
||||||
|
print(value)
|
||||||
|
self.setting[jid_bare][key] = value
|
||||||
|
|
||||||
|
|
||||||
async def set_setting_value(db_file, key, val):
|
async def set_setting_value(db_file, key, val):
|
||||||
|
|
|
@ -92,7 +92,7 @@ def http_response(url):
|
||||||
"""
|
"""
|
||||||
user_agent = (
|
user_agent = (
|
||||||
config.get_value(
|
config.get_value(
|
||||||
"settings", "Network", "user-agent")
|
"settings", "Network", "user_agent")
|
||||||
) or 'Slixfeed/0.1'
|
) or 'Slixfeed/0.1'
|
||||||
headers = {
|
headers = {
|
||||||
"User-Agent": user_agent
|
"User-Agent": user_agent
|
||||||
|
@ -121,7 +121,7 @@ async def http(url):
|
||||||
msg: list or str
|
msg: list or str
|
||||||
Document or error message.
|
Document or error message.
|
||||||
"""
|
"""
|
||||||
user_agent = (config.get_value("settings", "Network", "user-agent")
|
user_agent = (config.get_value("settings", "Network", "user_agent")
|
||||||
or 'Slixfeed/0.1')
|
or 'Slixfeed/0.1')
|
||||||
headers = {'User-Agent': user_agent}
|
headers = {'User-Agent': user_agent}
|
||||||
proxy = (config.get_value("settings", "Network", "http_proxy") or '')
|
proxy = (config.get_value("settings", "Network", "http_proxy") or '')
|
||||||
|
|
|
@ -59,6 +59,7 @@ import logging
|
||||||
import os
|
import os
|
||||||
import slixfeed.action as action
|
import slixfeed.action as action
|
||||||
import slixfeed.config as config
|
import slixfeed.config as config
|
||||||
|
from slixfeed.config import ConfigJabberID
|
||||||
# from slixfeed.dt import current_time
|
# from slixfeed.dt import current_time
|
||||||
import slixfeed.sqlite as sqlite
|
import slixfeed.sqlite as sqlite
|
||||||
# from xmpp import Slixfeed
|
# from xmpp import Slixfeed
|
||||||
|
@ -143,7 +144,7 @@ async def start_tasks_xmpp(self, jid, tasks=None):
|
||||||
match task:
|
match task:
|
||||||
case 'check':
|
case 'check':
|
||||||
self.task_manager[jid]['check'] = asyncio.create_task(
|
self.task_manager[jid]['check'] = asyncio.create_task(
|
||||||
check_updates(jid))
|
check_updates(self, jid))
|
||||||
case 'status':
|
case 'status':
|
||||||
self.task_manager[jid]['status'] = asyncio.create_task(
|
self.task_manager[jid]['status'] = asyncio.create_task(
|
||||||
task_status(self, jid))
|
task_status(self, jid))
|
||||||
|
@ -169,7 +170,8 @@ async def task_status(self, jid):
|
||||||
async def task_send(self, jid):
|
async def task_send(self, jid):
|
||||||
jid_file = jid.replace('/', '_')
|
jid_file = jid.replace('/', '_')
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
update_interval = config.get_setting_value(db_file, 'interval')
|
setting_custom = ConfigJabberID(db_file)
|
||||||
|
update_interval = setting_custom.interval or self.default.settings_p['interval']
|
||||||
update_interval = 60 * int(update_interval)
|
update_interval = 60 * int(update_interval)
|
||||||
last_update_time = await sqlite.get_last_update_time(db_file)
|
last_update_time = await sqlite.get_last_update_time(db_file)
|
||||||
if last_update_time:
|
if last_update_time:
|
||||||
|
@ -227,7 +229,8 @@ async def refresh_task(self, jid, callback, key, val=None):
|
||||||
if not val:
|
if not val:
|
||||||
jid_file = jid.replace('/', '_')
|
jid_file = jid.replace('/', '_')
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
val = config.get_setting_value(db_file, key)
|
setting_custom = ConfigJabberID(db_file)
|
||||||
|
val = setting_custom.interval or self.default.settings_p[key]
|
||||||
# if self.task_manager[jid][key]:
|
# if self.task_manager[jid][key]:
|
||||||
if jid in self.task_manager:
|
if jid in self.task_manager:
|
||||||
try:
|
try:
|
||||||
|
@ -263,7 +266,7 @@ async def wait_and_run(self, callback, jid, val):
|
||||||
|
|
||||||
# TODO Take this function out of
|
# TODO Take this function out of
|
||||||
# <class 'slixmpp.clientxmpp.ClientXMPP'>
|
# <class 'slixmpp.clientxmpp.ClientXMPP'>
|
||||||
async def check_updates(jid):
|
async def check_updates(self, jid):
|
||||||
"""
|
"""
|
||||||
Start calling for update check up.
|
Start calling for update check up.
|
||||||
|
|
||||||
|
@ -279,7 +282,7 @@ async def check_updates(jid):
|
||||||
urls = await sqlite.get_active_feeds_url(db_file)
|
urls = await sqlite.get_active_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 = config.get_value('settings', 'Settings', 'check')
|
val = self.default.setting['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(
|
||||||
|
|
|
@ -43,6 +43,9 @@ import slixfeed.task as task
|
||||||
# from lxml import etree
|
# from lxml import etree
|
||||||
|
|
||||||
import slixfeed.config as config
|
import slixfeed.config as config
|
||||||
|
from slixfeed.config import ConfigDefault
|
||||||
|
from slixfeed.config import ConfigJabberID
|
||||||
|
from slixfeed.config import ConfigXMPP
|
||||||
from slixfeed.log import Logger
|
from slixfeed.log import Logger
|
||||||
from slixfeed.version import __version__
|
from slixfeed.version import __version__
|
||||||
from slixfeed.xmpp.bookmark import XmppBookmark
|
from slixfeed.xmpp.bookmark import XmppBookmark
|
||||||
|
@ -64,7 +67,6 @@ import logging
|
||||||
import os
|
import os
|
||||||
import slixfeed.action as action
|
import slixfeed.action as action
|
||||||
import slixfeed.config as config
|
import slixfeed.config as config
|
||||||
from slixfeed.config import Config
|
|
||||||
import slixfeed.crawl as crawl
|
import slixfeed.crawl as crawl
|
||||||
import slixfeed.dt as dt
|
import slixfeed.dt as dt
|
||||||
import slixfeed.fetch as fetch
|
import slixfeed.fetch as fetch
|
||||||
|
@ -111,12 +113,17 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
# Handler for nickname
|
# Handler for nickname
|
||||||
self.alias = alias
|
self.alias = alias
|
||||||
|
|
||||||
# Handlers for tasks
|
# Handler for tasks
|
||||||
self.task_manager = {}
|
self.task_manager = {}
|
||||||
|
|
||||||
# Handlers for ping
|
# Handler for ping
|
||||||
self.task_ping_instance = {}
|
self.task_ping_instance = {}
|
||||||
|
|
||||||
|
# Handlers for configuration
|
||||||
|
self.base = ConfigXMPP()
|
||||||
|
self.custom = ConfigJabberID() # The value is {} (which is empty)
|
||||||
|
self.default = ConfigDefault()
|
||||||
|
|
||||||
# Handlers for connection events
|
# Handlers for connection events
|
||||||
self.connection_attempts = 0
|
self.connection_attempts = 0
|
||||||
self.max_connection_attempts = 10
|
self.max_connection_attempts = 10
|
||||||
|
@ -261,8 +268,8 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
task.task_ping(self)
|
task.task_ping(self)
|
||||||
bookmarks = await self.plugin['xep_0048'].get_bookmarks()
|
bookmarks = await self.plugin['xep_0048'].get_bookmarks()
|
||||||
XmppGroupchat.autojoin(self, bookmarks)
|
XmppGroupchat.autojoin(self, bookmarks)
|
||||||
if config.get_value('accounts', 'XMPP', 'operator'):
|
if self.base['operator']:
|
||||||
jid_op = config.get_value('accounts', 'XMPP', 'operator')
|
jid_op = self.base['operator']
|
||||||
status_message = 'Slixfeed version {}'.format(__version__)
|
status_message = 'Slixfeed version {}'.format(__version__)
|
||||||
XmppPresence.send(self, jid_op, status_message)
|
XmppPresence.send(self, jid_op, status_message)
|
||||||
time_end = time.time()
|
time_end = time.time()
|
||||||
|
@ -655,7 +662,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
# )
|
# )
|
||||||
|
|
||||||
# NOTE https://codeberg.org/poezio/slixmpp/issues/3515
|
# NOTE https://codeberg.org/poezio/slixmpp/issues/3515
|
||||||
# if jid == config.get_value('accounts', 'XMPP', 'operator'):
|
# if jid == self.base['operator']:
|
||||||
self['xep_0050'].add_command(node='recent',
|
self['xep_0050'].add_command(node='recent',
|
||||||
name='📰️ Browse',
|
name='📰️ Browse',
|
||||||
handler=self._handle_recent)
|
handler=self._handle_recent)
|
||||||
|
@ -704,7 +711,9 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
jid_bare = session['from'].bare
|
jid_bare = session['from'].bare
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
setting = Config(db_file)
|
# if not self.custom.setting and jid_bare not in self.custom.setting:
|
||||||
|
if jid_bare not in self.custom.setting:
|
||||||
|
self.custom = ConfigJabberID(jid_bare, db_file)
|
||||||
form = self['xep_0004'].make_form('form', 'Profile')
|
form = self['xep_0004'].make_form('form', 'Profile')
|
||||||
form['instructions'] = ('Displaying information\nJabber ID {}'
|
form['instructions'] = ('Displaying information\nJabber ID {}'
|
||||||
.format(jid_bare))
|
.format(jid_bare))
|
||||||
|
@ -730,35 +739,43 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
value=unread)
|
value=unread)
|
||||||
form.add_field(ftype='fixed',
|
form.add_field(ftype='fixed',
|
||||||
value='Options')
|
value='Options')
|
||||||
key_archive = str(setting.archive)
|
key_archive = self.custom.setting[jid_bare]['archive'] or self.default.setting['archive']
|
||||||
|
key_archive = str(key_archive)
|
||||||
form.add_field(label='Archive',
|
form.add_field(label='Archive',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=key_archive)
|
value=key_archive)
|
||||||
key_enabled = str(setting.enabled)
|
key_enabled = self.custom.setting[jid_bare]['enabled'] or self.default.setting['enabled']
|
||||||
|
key_enabled = str(key_enabled)
|
||||||
form.add_field(label='Enabled',
|
form.add_field(label='Enabled',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=key_enabled)
|
value=key_enabled)
|
||||||
key_interval = str(setting.interval)
|
key_interval = self.custom.setting[jid_bare]['interval'] or self.default.setting['interval']
|
||||||
|
key_interval = str(key_interval)
|
||||||
form.add_field(label='Interval',
|
form.add_field(label='Interval',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=key_interval)
|
value=key_interval)
|
||||||
key_length = str(setting.length)
|
key_length = self.custom.setting[jid_bare]['length'] or self.default.setting['length']
|
||||||
|
key_length = str(key_length)
|
||||||
form.add_field(label='Length',
|
form.add_field(label='Length',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=key_length)
|
value=key_length)
|
||||||
key_media = str(setting.media)
|
key_media = self.custom.setting[jid_bare]['media'] or self.default.setting['media']
|
||||||
|
key_media = str(key_media)
|
||||||
form.add_field(label='Media',
|
form.add_field(label='Media',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=key_media)
|
value=key_media)
|
||||||
key_old = str(setting.old)
|
key_old = self.custom.setting[jid_bare]['old'] or self.default.setting['old']
|
||||||
|
key_old = str(key_old)
|
||||||
form.add_field(label='Old',
|
form.add_field(label='Old',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=key_old)
|
value=key_old)
|
||||||
key_quantum = str(setting.quantum)
|
key_quantum = self.custom.setting[jid_bare]['quantum'] or self.default.setting['quantum']
|
||||||
|
key_quantum = str(key_quantum)
|
||||||
form.add_field(label='Quantum',
|
form.add_field(label='Quantum',
|
||||||
ftype='text-single',
|
ftype='text-single',
|
||||||
value=key_quantum)
|
value=key_quantum)
|
||||||
update_interval = str(setting.interval)
|
update_interval = self.custom.setting[jid_bare]['interval'] or self.default.setting['interval']
|
||||||
|
update_interval = str(update_interval)
|
||||||
update_interval = 60 * int(update_interval)
|
update_interval = 60 * int(update_interval)
|
||||||
last_update_time = await sqlite.get_last_update_time(db_file)
|
last_update_time = await sqlite.get_last_update_time(db_file)
|
||||||
if last_update_time:
|
if last_update_time:
|
||||||
|
@ -1913,7 +1930,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
options.addOption('Import', 'import')
|
options.addOption('Import', 'import')
|
||||||
options.addOption('Export', 'export')
|
options.addOption('Export', 'export')
|
||||||
jid = session['from'].bare
|
jid = session['from'].bare
|
||||||
if jid == config.get_value('accounts', 'XMPP', 'operator'):
|
if jid == self.base['operator']:
|
||||||
options.addOption('Administration', 'admin')
|
options.addOption('Administration', 'admin')
|
||||||
session['payload'] = form
|
session['payload'] = form
|
||||||
session['next'] = self._handle_advanced_result
|
session['next'] = self._handle_advanced_result
|
||||||
|
@ -1940,7 +1957,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
# NOTE Even though this check is already conducted on previous
|
# NOTE Even though this check is already conducted on previous
|
||||||
# form, this check is being done just in case.
|
# form, this check is being done just in case.
|
||||||
jid_bare = session['from'].bare
|
jid_bare = session['from'].bare
|
||||||
if jid_bare == config.get_value('accounts', 'XMPP', 'operator'):
|
if jid_bare == self.base['operator']:
|
||||||
if self.is_component:
|
if self.is_component:
|
||||||
# NOTE This will be changed with XEP-0222 XEP-0223
|
# NOTE This will be changed with XEP-0222 XEP-0223
|
||||||
text_info = ('Subscriber management options are '
|
text_info = ('Subscriber management options are '
|
||||||
|
@ -2669,10 +2686,12 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
if chat_type == 'chat' or moderator:
|
if chat_type == 'chat' or moderator:
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
setting = Config(db_file)
|
if jid_bare not in self.custom.setting:
|
||||||
|
self.custom = ConfigJabberID(jid_bare, db_file)
|
||||||
form = self['xep_0004'].make_form('form', 'Settings')
|
form = self['xep_0004'].make_form('form', 'Settings')
|
||||||
form['instructions'] = 'Editing settings'
|
form['instructions'] = 'Editing settings'
|
||||||
value = str(setting.enabled)
|
value = self.custom.setting[jid_bare]['enabled'] or self.default.setting['enabled']
|
||||||
|
value = str(value)
|
||||||
value = int(value)
|
value = int(value)
|
||||||
if value:
|
if value:
|
||||||
value = True
|
value = True
|
||||||
|
@ -2683,8 +2702,8 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
label='Enabled',
|
label='Enabled',
|
||||||
desc='Enable news updates.',
|
desc='Enable news updates.',
|
||||||
value=value)
|
value=value)
|
||||||
|
value = self.custom.setting[jid_bare]['media'] or self.default.setting['media']
|
||||||
value = str(setting.media)
|
value = str(value)
|
||||||
value = int(value)
|
value = int(value)
|
||||||
if value:
|
if value:
|
||||||
value = True
|
value = True
|
||||||
|
@ -2695,8 +2714,8 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
desc='Send audio, images or videos if found.',
|
desc='Send audio, images or videos if found.',
|
||||||
label='Display media',
|
label='Display media',
|
||||||
value=value)
|
value=value)
|
||||||
|
value = self.custom.setting[jid_bare]['old'] or self.default.setting['old']
|
||||||
value = str(setting.old)
|
value = str(value)
|
||||||
value = int(value)
|
value = int(value)
|
||||||
if value:
|
if value:
|
||||||
value = True
|
value = True
|
||||||
|
@ -2708,8 +2727,8 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
# label='Send only new items',
|
# label='Send only new items',
|
||||||
label='Include old news',
|
label='Include old news',
|
||||||
value=value)
|
value=value)
|
||||||
|
value = self.custom.setting[jid_bare]['interval'] or self.default.setting['interval']
|
||||||
value = str(setting.interval)
|
value = str(value)
|
||||||
value = int(value)
|
value = int(value)
|
||||||
value = value/60
|
value = value/60
|
||||||
value = int(value)
|
value = int(value)
|
||||||
|
@ -2729,8 +2748,8 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
i += 6
|
i += 6
|
||||||
else:
|
else:
|
||||||
i += 1
|
i += 1
|
||||||
|
value = self.custom.setting[jid_bare]['quantum'] or self.default.setting['quantum']
|
||||||
value = str(setting.quantum)
|
value = str(value)
|
||||||
value = str(value)
|
value = str(value)
|
||||||
options = form.add_field(var='quantum',
|
options = form.add_field(var='quantum',
|
||||||
ftype='list-single',
|
ftype='list-single',
|
||||||
|
@ -2744,8 +2763,8 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
x = str(i)
|
x = str(i)
|
||||||
options.addOption(x, x)
|
options.addOption(x, x)
|
||||||
i += 1
|
i += 1
|
||||||
|
value = self.custom.setting[jid_bare]['archive'] or self.default.setting['archive']
|
||||||
value = str(setting.archive)
|
value = str(value)
|
||||||
value = str(value)
|
value = str(value)
|
||||||
options = form.add_field(var='archive',
|
options = form.add_field(var='archive',
|
||||||
ftype='list-single',
|
ftype='list-single',
|
||||||
|
@ -2779,7 +2798,8 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
form = payload
|
form = payload
|
||||||
jid_file = jid_bare
|
jid_file = jid_bare
|
||||||
db_file = config.get_pathname_to_database(jid_file)
|
db_file = config.get_pathname_to_database(jid_file)
|
||||||
setting = Config(db_file)
|
if jid_bare not in self.custom.setting:
|
||||||
|
self.custom = ConfigJabberID(jid_bare, db_file)
|
||||||
# In this case (as is typical), the payload is a form
|
# In this case (as is typical), the payload is a form
|
||||||
values = payload['values']
|
values = payload['values']
|
||||||
for value in values:
|
for value in values:
|
||||||
|
@ -2791,8 +2811,10 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
if val < 1: val = 1
|
if val < 1: val = 1
|
||||||
val = val * 60
|
val = val * 60
|
||||||
|
|
||||||
|
is_enabled = self.custom.setting[jid_bare]['enabled'] or self.default.setting['enabled']
|
||||||
|
|
||||||
if (key == 'enabled' and val == 1 and
|
if (key == 'enabled' and val == 1 and
|
||||||
str(setting.enabled) == 0):
|
str(is_enabled) == 0):
|
||||||
logger.info('Slixfeed has been enabled for {}'.format(jid_bare))
|
logger.info('Slixfeed has been enabled for {}'.format(jid_bare))
|
||||||
status_type = 'available'
|
status_type = 'available'
|
||||||
status_message = '📫️ Welcome back!'
|
status_message = '📫️ Welcome back!'
|
||||||
|
@ -2803,7 +2825,7 @@ class Slixfeed(slixmpp.ClientXMPP):
|
||||||
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
await task.start_tasks_xmpp(self, jid_bare, key_list)
|
||||||
|
|
||||||
if (key == 'enabled' and val == 0 and
|
if (key == 'enabled' and val == 0 and
|
||||||
str(setting.enabled) == 1):
|
str(is_enabled) == 1):
|
||||||
logger.info('Slixfeed has been disabled for {}'.format(jid_bare))
|
logger.info('Slixfeed has been disabled for {}'.format(jid_bare))
|
||||||
key_list = ['interval', 'status']
|
key_list = ['interval', 'status']
|
||||||
task.clean_tasks_xmpp(self, jid_bare, key_list)
|
task.clean_tasks_xmpp(self, jid_bare, key_list)
|
||||||
|
|
|
@ -28,7 +28,7 @@ import logging
|
||||||
import os
|
import os
|
||||||
import slixfeed.action as action
|
import slixfeed.action as action
|
||||||
import slixfeed.config as config
|
import slixfeed.config as config
|
||||||
# from slixfeed.config import Config
|
from slixfeed.config import ConfigJabberID
|
||||||
import slixfeed.dt as dt
|
import slixfeed.dt as dt
|
||||||
import slixfeed.fetch as fetch
|
import slixfeed.fetch as fetch
|
||||||
import slixfeed.sqlite as sqlite
|
import slixfeed.sqlite as sqlite
|
||||||
|
@ -306,7 +306,8 @@ async def message(self, message):
|
||||||
await action.scan(db_file, url)
|
await action.scan(db_file, url)
|
||||||
# setting = Config(db_file)
|
# setting = Config(db_file)
|
||||||
# old = setting.old
|
# old = setting.old
|
||||||
old = config.get_setting_value(db_file, "old")
|
setting_custom = ConfigJabberID(db_file)
|
||||||
|
old = setting_custom.old or self.default.settings_p['old']
|
||||||
if old:
|
if old:
|
||||||
# task.clean_tasks_xmpp(self, jid, ['status'])
|
# task.clean_tasks_xmpp(self, jid, ['status'])
|
||||||
# await send_status(jid)
|
# await send_status(jid)
|
||||||
|
|
Loading…
Reference in a new issue