Git Product home page Git Product logo

lemmony's Introduction

lemmony

Lemmy, by default, will only collect new content from federated servers when a user searches for it specifically and/or subscribes to that remote content.

This script uses the Lemmy API, Python and Docker to help Lemmy self-hosters with a few (or just one) user who want to browse an "All," with the most complete picture of the federated Lemmyverse!

The script gets all of the publicly federated communities and "makes them known" to your local instance and then subscribes to them. "All" should be populated with activity from around the Lemmyverse.

Per: https://join-lemmy.org/docs/users/01-getting-started.html

These previous ways will only show communities that are already known to the instance. Especially if you joined a small or inactive Lemmy instance, there will be few communities to discover. You can find more communities by browsing different Lemmy instances, or using the Lemmy Community Browser. When you found a community that you want to follow, enter its URL (e.g. https://feddit.de/c/main) or the identifier (e.g. ![email protected]) into the search field of your own Lemmy instance. Lemmy will then fetch the community from its original instance, and allow you to interact with it. The same method also works to fetch users, posts or comments from other instances.

Use is not limited to small instances, that's just what I wrote it for.

Here are some other similar projects:

BIG DISCLAIMER

IF YOU DON'T UNDERSTAND WHAT THIS TOOL DOES, PLEASE CONSIDER CAREFULLY THE IMPLICATIONS OF RUNNING IT.

If you get errors (specifically KeyError,) the server is responding with rate-limit errors as a payload, instead of expected data. Try lowering the rate-limit. (-r)

This will cause load and subsequent incoming network activity on your instance and the network overall! A raspberry-pi or your internet may not be able to accommodate updates from all of the lemmyverse's communities!

What lemmony does

  1. Get a list of communities/magazines in the Lemmyverse from lemmyverse.net that have > 0 posts, are not listed as suspicious, and meet the top and include/exclude conditions
  2. Login to local instance as a specified user
  3. "Makes known" (see above) any communities or magazines fetched above that have never been known on your local instance
  4. Subscribes a user (follows) to all known communities on your local instance that are shown as "Unsubscribed" or, re-subscribes if the status is "Pending."

Compatibility

Lemmy's API versioning is... not ideally stable. Check the release notes for the version of Lemmy the release was tested against. It SHOULD work with newer versions, but no guarantees it will work with older versions.

Usage

The script requires an account to login to the instance. It is recommended you create a "bot" user, mark it as a bot, and use an obvious avatar. One is provided in the repository here for your convenience.

This will probably fail if the instance does not have a valid SSL certificate.

docker / podman

# sudo docker pull ghcr.io/jheidecker/lemmony/lemmony
# sudo docker run ghcr.io/jheidecker/lemmony/lemmony lemmony-cli -l [your-instance] -u [username] -p [password]

or

# podman pull ghcr.io/jheidecker/lemmony/lemmony
# podman run ghcr.io/jheidecker/lemmony/lemmony lemmony-cli -l [your-instance] -u [username] -p [password] 
  • [your instance] - the domain of the local instance i.e. lemmyrules.com. This is the same address (minus the https://) you use to access your lemmy instance. Depending on your setup, it might host.domain.name or just domain.name.
  • [user] - the user account (login.)
  • [password] - password for [user]

Other Options

Pass these flags to the command for more control:

  • -n : skip subscribing to communities in the "Pending" state
  • -s : subscribe only. skips the discovery and adding of new communities
  • -d : discover only. skips subscribing to any communities
  • -r [number] : will rate limit requests to LOCAL to X per second (default: 15)
  • -t [number] : only discover top X communities PER INSTANCE based on active users per day (default: 10) (Lemmy only, does not apply to kbin!)
  • -k : do not include kbin communities in discovery (will still subscribe if they meet conditions to subscribe)
  • -x : forgo all other functions and unsubscribe the USER from all communities

Build and Run Manually

Requires python3, and pip(3)

# git clone https://github.com/jheidecker/lemmony.git
# cd lemmony
# pip install build
# python -m build
# pip install dist/lemmony-[version]-py3-none-any.whl

This should install lemmony-cli as a command in your path:

# lemmony-cli
usage: lemmony-cli [-h] [-i INCLUDE [INCLUDE ...]] [-e EXCLUDE [EXCLUDE ...]] -l LOCAL -u USERNAME -p PASSWORD [-n] [-s] [-d] [-r RATE_LIMIT] [-t TOP_ONLY] [-k] [-x]

lemmony-cli: error: the following arguments are required: -l/--local, -u/--username, -p/--password

Include and exclude instances

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:

# lemmony-cli -l my.lemmy -u my_bot -p my_password -e lemmy.world

To add communities from ONLY lemmy.world:

# lemmony-cli -l my.lemmy -u my_bot -p my_password -i lemmy.world

You can specify multiple instances separated by spaces. For example: -i lemmy.world lemmy.ml beehaw.org

Development Notes (build/test/release)

# git clone https://github.com/jheidecker/lemmony.git
# cd lemmony
  • develop
  • update Containerfile and setup.cfg
# export CR_PAT=secret_pat
# echo $CR_PAT | podman login ghcr.io -u secret_username --password-stdin
# podman build . -t ghcr.io/jheidecker/lemmony/lemmony:version --platform linux/amd64,linux/arm64
  • push (requires access to ghcr package:)
# podman push ghcr.io/jheidecker/lemmony/lemmony:version
  • test (pull, run, etc.)
# podman build . -t ghcr.io/jheidecker/lemmony/lemmony:latest --platform linux/amd64,linux/arm64
# podman push ghcr.io/jheidecker/lemmony/lemmony:latest
  • bump release with release notes

lemmony's People

Contributors

jheidecker avatar

Stargazers

Michael Chrisco avatar Boky avatar Shane avatar  avatar  avatar  avatar Ryota Sakai avatar Erlend Sogge Heggen avatar  avatar  avatar Travis Kessler, PhD avatar Brandon Summers avatar Matt avatar  avatar Christopher Conley avatar  avatar Jasdemi avatar Ravioli avatar Ken Van Dalsum avatar  avatar Owen Kuemerle avatar  avatar Spencer Hughes avatar Jake Shirley avatar Jivan RamjiSingh avatar Lennard Michael Strohmeyer avatar  avatar Cas Bitton avatar razmag avatar Sean P. McAdam avatar Daniel Seifert avatar  avatar Can Evgin avatar pyunramura avatar Tim Stratton avatar badblocks avatar Sami Taaissat avatar xaeg avatar Tom Pomeroy avatar Citizen1 avatar Daniel Phan avatar  avatar  avatar Richard Potter avatar Russell avatar

Watchers

 avatar Jasdemi avatar

lemmony's Issues

--no-pending flag

program switch to change default behaviour from subscribing to all Unsubscribed and Pending to JUST Unsubscribed

toLower

appending to the local list. have to normalize to lowercase to match lemmyverse list

Check lemmy version

Validate minimum lemmy version on login to ensure no breaking API changes

Issue when running docker:

Command run:

sudo docker run ghcr.io/jheidecker/lemmony/lemmony lemmony-cli -l lemmy.myserv.one -u -p -i lemmy.world -s

Output:

logging in to lemmy.myserv.one as BlackCat...
re-fetching communities ready for subscription (this might take a while)...
Traceback (most recent call last):
  File "/usr/local/bin/lemmony-cli", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.11/site-packages/lemmony/cli.py", line 144, in main
    subscribe()
  File "/usr/local/lib/python3.11/site-packages/lemmony/cli.py", line 116, in subscribe
    if actor_resp.json()['communities'] != []:
       ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 'communities'

Unfollow feature

Add unfollow routine that is the only function and simply unsubscribes a user from everything.

Refactor All the Things

Did not start this thinking anyone would ask for it. I want to code good, like few words do. I am not the most ambitious, nor dedicated developer. I solve problems. I realize that poor practices and spaghetti code left unchecked can cause future problems though. This is just a placeholder for that branch that will never happen where everything gets cleaned and refactored!

Exception

Tried 2x and am getting this error:

calvin@SYSTEM:~/lemmony$ lemmony-cli -l $LEMMY.DOMAIN -u lemmysub -p '$PASSWORD' -t 10 -k
logging in to $LEMMY.DOMAIN as lemmysub...
fetching lemmy communities (and kbin magazines) from lemmyverse.net...
got 2353 non-empty Lemmy communities.
enumerating all locally (known) communities (this might take a while)...
done.
adding new global communities > local instance (this will take a while)...
done.
re-fetching communities ready for subscription (this might take a while)...
done.
found 1912 communities to subscribe to.
subscribing lemmysub to communities (this will take a while)...
Traceback (most recent call last):
File "/home/calvin/.local/lib/python3.10/site-packages/requests/models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.10/json/init.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/calvin/.local/bin/lemmony-cli", line 8, in
sys.exit(main())
File "/home/calvin/.local/lib/python3.10/site-packages/lemmony/cli.py", line 204, in main
subscribe()
File "/home/calvin/.local/lib/python3.10/site-packages/lemmony/cli.py", line 194, in subscribe
print(str(idx) + "/" + local_community_count + " " + str(community_id) + ": " + str(sub_resp.json()['community_view']['subscribed']), end="\r")
File "/home/calvin/.local/lib/python3.10/site-packages/requests/models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Issue when subscribing

Issue happened after all 8000 communities were added, before subscribing, and now also happens when rerunning the script. (after enumerating all local communities (this might take a while)...)

8875/8875 https://testlemmy.lealternative.net/c/main: 200
re-fetching communities ready for subscription (this might take a while)...
Traceback (most recent call last):
File "/root/lemmony.py", line 64, in
if actor_resp.json()['communities'] != []:
File "/usr/lib/python3/dist-packages/requests/models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.10/json/init.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.