this post was submitted on 17 Jun 2023
6 points (100.0% liked)

Lemmy

12542 readers
85 users here now

Everything about Lemmy; bugs, gripes, praises, and advocacy.

For discussion about the lemmy.ml instance, go to !meta@lemmy.ml.

founded 4 years ago
MODERATORS
 

I'm currently setting up a Python wrapper for Lemmy's API, my aim being to develop a moderation bot (more info here), so I'm building the wrapper as the bot requests it.

It's my first time doing this, so don't hesitate to contribute if you find it useful: https://codeberg.org/retiolus/Lemmy.py

Usage example:

from lemmy import Lemmy

# Login to your account
lemmy = Lemmy("https://lemmy.ml")
lemmy.log_in("username_or_email", "password")

# Get a community ID
community_id = lemmy.discover_community("community_name")

# Get all posts from a community by ID
community_posts = lemmy.post.list(community_id=community_id)

# Get the modlog of your server
modlog = lemmy.modlog.get()

# Post a new publication on a community
lemmy.post.create(community_id=community_id, name="First Post!", body="This is the first community post.")
top 4 comments
sorted by: hot top controversial new old
[–] chris@l.roofo.cc 1 points 1 year ago

Did you write the wrapper by hand or did you use a tool?

[–] nmtake@lemm.ee 0 points 1 year ago (1 children)

Awesome! I couldn't find how do I get the auth token when I read the official API docs.

[–] retiolus@lemmy.cat 1 points 1 year ago (1 children)

There is no "app" auth token yet, as I know, so you get your token from a normal log in.

[–] nmtake@lemm.ee 2 points 1 year ago

Ah, I see. I'm reading your code and it's very helpfull. Thanks!