this post was submitted on 13 Jul 2023
30 points (100.0% liked)

Python

6288 readers
8 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

๐Ÿ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

๐Ÿ Python project:
๐Ÿ’“ Python Community:
โœจ Python Ecosystem:
๐ŸŒŒ Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
 

I've written a script to repost Github posts to Lemmy but now I'm trying to repost comments too and I don't know how to get the corresponding post_id that I need to do that.

lemmy.comment.create(post_id, comment_body)

Is there a way to associate the Github URL to the post_id when creating it with Pythorhead and then figuring out the Github URL from the comment and getting the post_id that way?

Alternatively, would something like this work? If so how would I limit the search to a specific community?

import requests

# GitHub URL of the post
github_url = "https://github.com/user/repo/issues/123"

# Lemmy API endpoint to search for posts
lemmy_search_url = "https://lemmy.ml/api/v3/search"

# Query parameters for the search endpoint
params = {
    "q": github_url,
    "type": "link",
    "sort": "relevance",
    "limit": 1
}

# Send a GET request to the search endpoint
response = requests.get(lemmy_search_url, params=params)

# Parse the response JSON to get the post_id
post_id = response.json()["posts"][0]["id"]

# Use the post_id to create a comment in Lemmy
lemmy.comment.create(post_id, comment_body)

Are there any other ways?

you are viewing a single comment's thread
view the rest of the comments
[โ€“] jnovinger 1 points 1 year ago

OP, you could even use a local file/sqlite database in the repo and just update and commit it when the script runs.

Simon Willison has a cool approach for this that runs in GitHub Actions and keeps the versioned state in git itself: https://simonwillison.net/2020/Oct/9/git-scraping/