Last active
May 15, 2023 15:25
-
-
Save Jxck-S/b6ffe6cc30e4139c3205f2e0b7575cad to your computer and use it in GitHub Desktop.
Post to nostr from Python, with helpful info on how to post a photo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import ssl | |
import time | |
from nostr.event import Event | |
from nostr.relay_manager import RelayManager | |
from nostr.message_type import ClientMessageType | |
from nostr.key import PrivateKey | |
def nostr_post(note, private_key, image_url=None): | |
if image_url: | |
note = f"{note} {image_url}" | |
private_key = PrivateKey.from_nsec(private_key) | |
relay_manager = RelayManager() | |
relay_manager.add_relay("wss://nostr.mutinywallet.com") | |
relay_manager.add_relay("wss://relay.damus.io") | |
relay_manager.open_connections() | |
time.sleep(1.25) | |
event = Event(private_key.public_key.hex(), note) | |
private_key.sign_event(event) | |
relay_manager.publish_event(event) | |
time.sleep(1) # allow the messages to send | |
relay_manager.close_connections() | |
#Test | |
private_key = "put ur pv here" | |
file_name = "" # works with images idk what else | |
#Upload the file using AWS S3 Bucket or nostr.build or void.cat, using this code | |
# AWS S3 Upload code https://gist.github.com/Jxck-S/e7bd0ea70acc0755c410dc05afa698f1 | |
# Nostr.build code and void.cat https://gist.github.com/Jxck-S/2a95655bf42cc344885709d647c717ab | |
# url = ..... | |
note = "This is a test from Python and an image/file" | |
nostr_post(note, private_key, url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did in production, Just didn't update the gist, I also in my production code, put my relays in a CSV and loaded them in.