Containerized configurations (step towards a portable software. SeeTPFC portablefreeware.com)

This commit is contained in:
Schimon Jehudah 2024-01-22 12:48:00 +00:00
parent 0512e14738
commit c4ccdd1f9d
9 changed files with 74 additions and 18 deletions

View file

@ -46,6 +46,18 @@ Slixfeed is designed to handle multiple contacts, including groupchats, Simultan
### Install
Choose one of the following installation methods.
#### Using pip inside venv
```
$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install git+https://gitgud.io/sjehuda/slixfeed
```
#### Using pipx
```
$ pipx install git+https://gitgud.io/sjehuda/slixfeed
```
@ -58,7 +70,7 @@ $ slixfeed
### Usage
- Start a chat with the bot and follow it instructions.
- Add the bot to contact list and follow it instructions.
- Send command `help` or `commands` for a list of commands.
## Roadmap

View file

@ -44,6 +44,13 @@ dependencies = [
"feedparser",
"lxml",
"slixmpp",
# Optional dependencies
# listed here (testing)
"html2text",
"pdfkit",
"pysocks",
"readability-lxml",
]
[project.urls]
@ -53,8 +60,8 @@ Issues = "https://gitgud.io/sjehuda/slixfeed/issues"
[project.optional-dependencies]
# socks = ["PySocks"]
file-export = ["html2text", "pdfkit"]
proxy = ["pysocks"]
readability = ["readability-lxml"]
# This section returns pep508-identifier error

View file

@ -70,6 +70,8 @@ TODO
activities every X minutes.
When a suspicious activity is detected, it will be reported immediately.
19) Communicate to messages of new contacts (not subscribed and not in roster)
"""
# vars and their meanings:
@ -99,6 +101,9 @@ from slixfeed.config import get_value
from slixfeed.xmpp.client import Slixfeed
#import slixfeed.matrixhandler
import socks
import socket
class Jabber:
def __init__(self, jid, password, nick):
@ -116,6 +121,7 @@ class Jabber:
xmpp.register_plugin('xep_0066') # Out of Band Data
xmpp.register_plugin('xep_0071') # XHTML-IM
xmpp.register_plugin('xep_0084') # User Avatar
# xmpp.register_plugin('xep_0085') # Chat State Notifications
xmpp.register_plugin('xep_0153') # vCard-Based Avatars
xmpp.register_plugin('xep_0199', {'keepalive': True}) # XMPP Ping
xmpp.register_plugin('xep_0249') # Multi-User Chat
@ -142,10 +148,28 @@ class Jabber:
# xmpp.proxy = {'socks5': ('localhost', 9050)}
# Connect to the XMPP server and start processing XMPP stanzas.
address = get_value(
"accounts", "XMPP", ["address", "port"])
if address[0] and address[1]:
xmpp.connect(tuple(address))
else:
xmpp.connect()
xmpp.process()
def main():
values = get_value(
"accounts", "XMPP Proxy", ["socks5_host", "socks5_port"])
if values[0] and values[1]:
host = values[0]
port = values[1]
s = socks.socksocket()
s.set_proxy(socks.SOCKS5, host, port)
# socks.set_default_proxy(socks.SOCKS5, host, port)
# socket.socket = socks.socksocket
# Setup the command line arguments.
parser = ArgumentParser(description=Slixfeed.__doc__)

View file

@ -267,7 +267,7 @@ def list_feeds_by_query(query, results):
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)
config.get_value("settings", "Settings", key)
)
return value
@ -1084,6 +1084,8 @@ async def extract_image_from_html(url):
'contains(@src, "emoji") or '
'contains(@src, "icon") or '
'contains(@src, "logo") or '
'contains(@src, "search") or '
'contains(@src, "share") or '
'contains(@src, "smiley")'
')]/@src')
if len(images):

View file

@ -49,10 +49,10 @@ def get_value(filename, section, keys):
result = None
config_res = configparser.RawConfigParser()
config_dir = get_default_config_directory()
# if not os.path.isdir(config_dir):
# config_dir = '/usr/share/slixfeed/'
if not os.path.isdir(config_dir):
os.mkdir(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 + ".ini")
config_res.read(config_file)
if config_res.has_section(section):
@ -137,6 +137,8 @@ def get_list(filename, key):
config_dir = 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) as defaults:
# default = yaml.safe_load(defaults)

View file

@ -48,7 +48,7 @@ import slixfeed.action as action
from slixfeed.config import (
get_pathname_to_database,
get_default_data_directory,
get_value_default)
get_value)
# from slixfeed.dt import current_time
from slixfeed.sqlite import (
get_feed_title,
@ -155,7 +155,7 @@ async def task_jid(self, jid):
await get_settings_value(
db_file, "enabled")
) or (
get_value_default(
get_value(
"settings", "Settings", "enabled")
)
if enabled:
@ -211,7 +211,7 @@ async def send_update(self, jid, num=None):
await get_settings_value(
db_file, "enabled")
) or (
get_value_default(
get_value(
"settings", "Settings", "enabled")
)
if enabled:
@ -220,7 +220,7 @@ async def send_update(self, jid, num=None):
await get_settings_value(
db_file, "quantum")
) or (
get_value_default(
get_value(
"settings", "Settings", "quantum")
)
else:
@ -329,7 +329,7 @@ async def send_status(self, jid):
await get_settings_value(
db_file, "enabled")
) or (
get_value_default(
get_value(
"settings", "Settings", "enabled")
)
if not enabled:
@ -403,7 +403,7 @@ async def refresh_task(self, jid, callback, key, val=None):
await get_settings_value(
db_file, key)
) or (
get_value_default(
get_value(
"settings", "Settings", key)
)
# if task_manager[jid][key]:
@ -460,7 +460,7 @@ async def check_updates(jid):
urls = await get_feeds_url(db_file)
for url in urls:
await action.scan(db_file, url)
val = get_value_default(
val = get_value(
"settings", "Settings", "check")
await asyncio.sleep(60 * float(val))
# Schedule to call this function again in 90 minutes

View file

@ -208,9 +208,8 @@ class Slixfeed(slixmpp.ClientXMPP):
async def on_presence_available(self, presence):
# TODO Add function to check whether task is already running or not
await task.start_tasks(self, presence)
print("on_presence_available")
print(presence)
async def on_presence_unsubscribed(self, presence):

View file

@ -519,7 +519,7 @@ async def message(self, message):
await send_oob_message(self, jid, url)
else:
response = (
"Failed to fetch {}. Reason: {}"
"Failed to fetch {} Reason: {}"
).format(url, code)
await task.start_tasks_xmpp(
self, jid, ["status"])

View file

@ -44,7 +44,17 @@ async def set_avatar(self):
config_dir = get_default_config_directory()
if not os.path.isdir(config_dir):
config_dir = '/usr/share/slixfeed/'
filename = glob.glob(config_dir + "/image.*")[0]
filename = glob.glob(config_dir + "/image.*")
if not filename and os.path.isdir('/usr/share/slixfeed/'):
# filename = '/usr/share/slixfeed/image.svg'
filename = glob.glob("/usr/share/slixfeed/image.*")
else:
config_dir = os.path.dirname(__file__)
config_dir = config_dir.split("/")
config_dir.pop()
config_dir = "/".join(config_dir)
filename = glob.glob(config_dir + "/assets/image.*")
filename = filename[0]
image_file = os.path.join(config_dir, filename)
with open(image_file, "rb") as avatar_file:
avatar = avatar_file.read()