diff --git a/README.md b/README.md index db5cac3..fad9ca6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 70e3bae..64bb25b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/slixfeed/__main__.py b/slixfeed/__main__.py index 64f0930..822f000 100644 --- a/slixfeed/__main__.py +++ b/slixfeed/__main__.py @@ -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. - xmpp.connect() + + 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__) diff --git a/slixfeed/action.py b/slixfeed/action.py index 4ee206f..5236dc0 100644 --- a/slixfeed/action.py +++ b/slixfeed/action.py @@ -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): diff --git a/slixfeed/config.py b/slixfeed/config.py index 37bc8f3..f3ec3cc 100644 --- a/slixfeed/config.py +++ b/slixfeed/config.py @@ -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) diff --git a/slixfeed/task.py b/slixfeed/task.py index 4cb6e31..2943096 100644 --- a/slixfeed/task.py +++ b/slixfeed/task.py @@ -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 diff --git a/slixfeed/xmpp/client.py b/slixfeed/xmpp/client.py index 3a110d7..fa7a528 100644 --- a/slixfeed/xmpp/client.py +++ b/slixfeed/xmpp/client.py @@ -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): diff --git a/slixfeed/xmpp/process.py b/slixfeed/xmpp/process.py index c5ba512..2fe538c 100644 --- a/slixfeed/xmpp/process.py +++ b/slixfeed/xmpp/process.py @@ -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"]) diff --git a/slixfeed/xmpp/profile.py b/slixfeed/xmpp/profile.py index 82e4045..b2b7035 100644 --- a/slixfeed/xmpp/profile.py +++ b/slixfeed/xmpp/profile.py @@ -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()