-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get profile information from pubkey #82
Comments
You can do that using the I really don't know if it's the most appropriate way but it worked for me. I'm just starting to explore this library. |
@lndrkzts can you please share your piece of code? |
After some tests, this is the final code to get profile updates using an npub: import time
import uuid
from nostr.event import EventKind
from nostr.relay_manager import RelayManager
from nostr.key import PublicKey
from nostr.filter import Filter, Filters
pub_key = PublicKey.from_npub('npubxxxxxxxxxx')
filters = Filters([Filter(authors=[pub_key.hex()], kinds=[EventKind.SET_METADATA])])
subscription_id = uuid.uuid1().hex
relay_manager = RelayManager()
relay_manager.add_relay("wss://relay.snort.social")
relay_manager.add_relay("wss://relay.damus.io")
relay_manager.add_subscription_on_all_relays(subscription_id, filters)
time.sleep(1)
while relay_manager.message_pool.has_events():
event_msg = relay_manager.message_pool.get_event()
print(event_msg.event.content)
relay_manager.close_all_relay_connections() Keep in mind that you need to add at least one of the relays where the update was done to have some results. |
@daiangan is this code sample using the
Also, I can't get your code to work using the main branch and changing function names of relay_manager.add_subscription_on_all_relays, etc. It runs, but doesn't get any events for the pubkeys I give it. Stumped... |
I FIGURED IT OUT!! import time
import uuid
import ssl
import json
from nostr.event import EventKind
from nostr.relay_manager import RelayManager
from nostr.key import PublicKey
from nostr.filter import Filter, Filters
from nostr.message_type import ClientMessageType
def get_info():
pub_key = PublicKey.from_npub('npub1xegedgkkjf24pl4d76cdwhufacng5hapzjnrtgms3pyhlvmyqj9suym08k')
filters = Filters([Filter(authors=[pub_key.hex()], kinds=[EventKind.SET_METADATA])]) # TEXT_NOTE
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.snort.social")
relay_manager.add_relay("wss://relay.damus.io")
relay_manager.add_subscription(subscription_id, filters)
relay_manager.open_connections({"cert_reqs": ssl.CERT_NONE})
time.sleep(1.25) # allow the connections to open
message = json.dumps(request)
relay_manager.publish_message(message)
time.sleep(1) # allow the messages to send
while relay_manager.message_pool.has_events():
event_msg = relay_manager.message_pool.get_event()
data = json.loads(event_msg.event.content)
pretty_json = json.dumps(data, indent=4)
print(pretty_json)
relay_manager.close_connections()
if __name__ == "__main__":
get_info() |
If I have a pubkey, how can I query to find out about their profile information like bio and lightning address?
Thank you
The text was updated successfully, but these errors were encountered: