Fedihosting-Foundation / plemmy

A Python package for accessing the LemmyHttp API
Apache License 2.0
45 stars 15 forks source link

what is the community_id? #9

Closed binhex closed 1 year ago

binhex commented 1 year ago

Hi, just going through your example and I'm a little confused by the community_id where do I find this value in Lemmy, and wouldn't it be simpler to just allow a developer to specify the string value for the community instead?.

ajstamps commented 1 year ago

You can call get_community() to get the id without previously knowing it. The flow should look something like:

srv = LemmyHttp("<instance>")
srv.login("<username>", "<password>")
output = srv.get_community(name="<community name>")
data = output.json()

The 'community_id' would then be in data['community_view']['community']['id'].

I agree that it would be simpler, but this is a limitation with the Lemmy API itself, not @tjkessler's implementation from what I can tell: Here is the API documentation for 'getCommunity' from Lemmy

tjkessler commented 1 year ago

Right now Plemmy is aiming for parity with the LemmyHttp API. In the future I would like to implement some higher-level functions to help users avoid JSON dictionary indexing/keying, e.g., a "get_community" function that will return a community ID directly. Stay tuned!

Edit: keeping this issue open as motivation for me to get this done

tjkessler commented 1 year ago

Closing this issue now that Plemmy 0.3.0 is released! See source code and examples for how to easily access this information without having to parse JSON yourself.