• 3 Posts
  • 11 Comments
Joined 1 year ago
cake
Cake day: June 5th, 2023

help-circle


  • Here’s a kind of guess on how to create a post using python’s requests library:

    import requests
    import json
    
    # Define the URL for the API endpoint
    url = "https://lemmy.ml/api/v1/post"
    
    # Define the headers for the request
    headers = {'Content-Type': 'application/json'}
    
    # Define the data for the new post
    data = {
     "name": "Your Post Title",
     "community_id": 123,  # Replace with your community ID
     "url": "https://your-url.com",  # Optional
     "body": "Your post content",  # Optional
     "nsfw": False,  # Optional
     "language_id": 1,  # Optional, replace with your language ID
     "auth": "your_auth_token_here"
    }
    
    # Send the POST request
    response = requests.post(url, headers=headers, data=json.dumps(data))
    
    # Print the response
    print(response.json())
    

    Does this look right? I understand that I’ll have to authenticate to the server to do this, but I’m really not sure how to do that.









  • Well, I do get a lot of alerts from Google as new topics come in, and I could post those links. That’s mostly the way things are handled in the Futurology and Science subs. Posting those to Lemmy communities should work, I think. I guess I worry about swamping a community with traffic, but if so, I guess whoever manages that community can let me know to dial it back.