python-nostr
python-nostr copied to clipboard
How to use add_subscription?
Can I call add_subscription after open_connections, or do I need to do it before like the README example?
Another question... Should I expect to get all old note/events using RelayManager.message_pool.has_event? I'm having trouble getting any thing, the while-loop just quits. I've even tried simplifying the filter to EventKind.TEXT_NOTE.
did you make any progress on this. I'm having a hard time working with this -- which is because of my limited understanding & knowledge. But I just don't 'get' what is subscription ID - do I create it? If yes, how. All I've been able to do so far is connect to relays and post a note. I have read and re-read the readme but I still don't get it. Any help would be appreciated.
I wasn't able to figure it out, so I switched to https://github.com/holgern/pynostr
for subscription ID, it can be anything unique
You could import uuid and then subid = uuid.uuid1().hex
ok, thanks -- bookmarking it.
seems to work fine from the examples.
tbh, I haven't tried it again after the suggestion from @decentropy - will comment here again if I run into issues. Thanks
Can I call add_subscription after open_connections, or do I need to do it before like the README example?
Just tested this, and seems to work either before or after:
relay_manager.open_connections()
relay_manager.add_subscription(subscription_id, filters)
for subscription ID, it can be anything unique
Yes, that works fine. Here's a complete example:
# Setup filters
filters = Filters([Filter(limit=10)])
# Generate subscription
subscription_id = uuid.uuid1().hex
request = [ClientMessageType.REQUEST, subscription_id]
request.extend(filters.to_json_array())
relay_manager = RelayManager()
relay_manager.add_relay("wss://nostr-pub.wellorder.net")
relay_manager.add_relay("wss://relay.damus.io")
relay_manager.add_relay("wss://nostr.wine")
relay_manager.add_relay("wss://nostr.rocks")
relay_manager.add_subscription(subscription_id, filters)
relay_manager.open_connections()
Should I expect to get all old note/events using RelayManager.message_pool.has_event?
I believe it's whatever the relay returns, based on your filters. So in theory yes - all old events.