From 6aa534b95b0da2987eb011069edfdb9db4388ac1 Mon Sep 17 00:00:00 2001 From: Jay Heidecker Date: Mon, 17 Jul 2023 21:10:51 -0600 Subject: [PATCH] fixed #18 --- Containerfile | 2 +- README.md | 2 +- lemmony/cli.py | 47 ++++++++++++++++++++++++++++++++++++----------- setup.cfg | 2 +- 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Containerfile b/Containerfile index 2bf8b69..a25b210 100644 --- a/Containerfile +++ b/Containerfile @@ -10,6 +10,6 @@ WORKDIR /app RUN pip3 install build COPY . . RUN python3 -m build -RUN pip3 install dist/lemmony-0.0.5-py3-none-any.whl +RUN pip3 install dist/lemmony-0.0.6-py3-none-any.whl CMD ["lemmony-cli"] \ No newline at end of file diff --git a/README.md b/README.md index 4d8ddf6..0e5ccfb 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ lemmony-cli: error: the following arguments are required: -l/--local, -u/--usern ### Include and exclude instances -By default lemmony tries to subscribe to as many communities as it can based on the global lists provided by [lemmyverse.net](lemmyverse.net) You can include and exclude instances using the optional `-i` and `-e` flags respectively. This way you can only subscribe to favorite instances, or exclude instances you do not want. The flags cannot be used at the same time. For example: +By default lemmony will only subscribe to communities based on your local instances allowed / blocked federation list. You can override this and include or exclude instances using the optional `-i` and `-e` flags respectively. This way you can only subscribe to favorite instances, or exclude instances you do not want. The flags cannot be used at the same time. For example: To add communities from all instances except `lemmy.world`: diff --git a/lemmony/cli.py b/lemmony/cli.py index d8bb892..b0e8150 100644 --- a/lemmony/cli.py +++ b/lemmony/cli.py @@ -29,22 +29,15 @@ def main(): discover_only = args.discover_only unsubscribe_all = args.unsubscribe_all skip_kbin = args.skip_kbin + + #enable testing + debug = False if args.top_only is not None: top_only = args.top_only else: top_only = 0 - if args.include is not None: - include_instances = args.include - else: - include_instances = [] - - if args.exclude is not None: - exclude_instances = args.exclude - else: - exclude_instances = [] - # create new session object for local instance curSession = requests.Session() @@ -176,7 +169,7 @@ def subscribe(): continue else: local_community_id_list.append(community['community']['id']) - #print("f:non-subscribed:added " + community['community']['actor_id']) + print("f:added " + community['community']['actor_id']) print(page * 50, end="\r") page += 1 else: @@ -234,12 +227,44 @@ def unsubscribe(): print('\r\033[K', end='\r') print('done.') + def getlocalfederation(): + print('fetching local federation allow/block lists...') + local_federation_list = [] + local_federation_list = curSession.get('https://'+local_instance+'/api/v3/federated_instances') + included_instances = [] + excluded_instances = [] + for instance in local_federation_list.json()['federated_instances']['allowed']: + included_instances.append(instance['domain']) + for instance in local_federation_list.json()['federated_instances']['blocked']: + excluded_instances.append(instance['domain']) + return included_instances, excluded_instances + + # get allowed and disallowed instances from local instance and use these if -i and -e are not specified + included_instances, excluded_instances = getlocalfederation() + + if args.include is not None: + include_instances = args.include + exclude_instances = [] + print('including: ' + str(include_instances)) + elif args.exclude is not None: + exclude_instances = args.exclude + include_instances = [] + print('excluding: ' + str(exclude_instances)) + else: + include_instances = included_instances + print('including: ' + str(include_instances)) + exclude_instances = excluded_instances + print('excluding: ' + str(exclude_instances)) + + #main logic if discover_only == True: discover() elif subscribe_only == True: subscribe() elif unsubscribe_all == True: unsubscribe() + elif debug == True: + getlocalfederation() else: discover() subscribe() diff --git a/setup.cfg b/setup.cfg index 1c61bec..2437cf7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = lemmony -version = 0.0.5 +version = 0.0.6 [options] packages = lemmony