Why Nostr? What is Njump?
2025-02-13 17:46:41

ever4st on Nostr: This code below works with nostr_sdk 0.32.2 ``` python import asyncio, argparse, json ...

This code below works with nostr_sdk 0.32.2

import asyncio, argparse, json
from nostr_sdk import Metadata, Client, NostrSigner, Keys, Filter, PublicKey, Kind
from datetime import timedelta
 
async def main(npub):
    client = Client()
    await client.add_relay("wss://relay.damus.io")
    await client.connect()
    pk = PublicKey.from_bech32(npub)
    print(f"Getting profile metadata for {npub}:")
    f = Filter().kind(Kind(0)).author(pk).limit(1)
    events = await client.get_events_of([f], timedelta(seconds=15))
    if events:
        event = events[0]
        metadata_dict = json.loads(event.content())
        for key, value in metadata_dict.items():
            print(f"{key}: {value}")
    else:
        print("Could not retrieve metadata for the given public key.")
         
if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Fetch all metadata for a given npub')
    parser.add_argument('npub', type=str, help='The npub of the user')
    args = parser.parse_args()
    asyncio.run(main(args.npub))

but with nostr_sdk 0.39 the program no longer worked and crash with error:

AttributeError: type object 'PublicKey' has no attribute 
'from_bech32'. Did you mean: 'to_bech32'?

why?

source:

Author Public Key
npub1mwce4c8qa2zn9zw9f372syrc9dsnqmyy3jkcmpqkzaze0slj94dqu6nmwy