Skip to content

Commit

Permalink
fixed #18
Browse files Browse the repository at this point in the history
  • Loading branch information
jheidecker committed Jul 18, 2023
1 parent 467317c commit 6aa534b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
47 changes: 36 additions & 11 deletions lemmony/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = lemmony
version = 0.0.5
version = 0.0.6

[options]
packages = lemmony
Expand Down

0 comments on commit 6aa534b

Please sign in to comment.