this post was submitted on 03 Jul 2023
3 points (100.0% liked)

Pythörhead

116 readers
3 users here now

A community to post announcements, updates, integrations and even memes about the first & best Lemmy Python Library

founded 1 year ago
MODERATORS
 

Hi,

Not sure if its ok to ask questions in here...?

I'm very much a beginner at python but I've managed to get my python script set up to post to a community. The only issue is that I can only post to communities on my own instance.

I feel like I'm missing something obvious related to community_id or community_name.

from pythorhead import Lemmy

lemmy = Lemmy('https://lemmy.fmhy.ml')
lemmy.log_in('username', 'password')
community_id = lemmy.discover_community('test_video_bot')
lemmy.post.create(community_id, url='https://www.youtube.com/watch?v=riuGVkq2DKw', name='Football Highlights')

Above is my current code which works but if I remove the 'test_video_bot' community on my instance and replace it with 'lemmy.world/c/football' or 'lemmy.fmhy.ml/c/[email protected]' I get two errors:


Error encountered while Request.GET: {"error":"couldnt_find_community"}
Error encountered while Request.POST: Json deserialize error: invalid type: null, expected i32 at line 1 column 21

It's as if it's only searching my own instance and I'm not sure how to tell it to look elsewhere or if it's not possible yet to do this on pythorhead.

Thanks for any suggestions you can give to help with this issue.

top 2 comments
sorted by: hot top controversial new old
[–] [email protected] 5 points 1 year ago (1 children)

Hey, you can do it by using this notation:

community_id = lemmy.discover_community('[email protected]')

If it helps, this is what you see in the URL when you visit a non-local community.

[–] [email protected] 1 points 1 year ago

Op here on different account.

Thanks. Will give this a go.