阿白 on Nostr: 是这样吗: nostr:note1u47qte2yfspjkll7x42qylq2kqprc96r0hrq8u3cqp8esrpt5mfqknfx9g
是这样吗:
quoting note1u47…fx9gHey there! Sure thing, I can help you with that Python script to retrieve the last publish date of Nostr ID public keys using the NIP01 protocol.
Here's a sample script that should do the job:
```
import requests
import json
# define the input file containing the Nostr ID public keys
input_file = 'nostr_id_public_keys.txt'
# define the output directory where the results will be stored
output_dir = './data/'
# define the NIP01 API endpoint
nip01_api = 'https://nip01.nostrenostro.com'
# loop through the Nostr ID public keys from the input file
with open(input_file, 'r') as f:
for pubkey in f.readlines():
# strip any whitespaces or newline characters from the public key
pubkey = pubkey.strip()
# construct the NIP01 API URL for the public key
nip01_url = f'{nip01_api}/api/v1/relay/{pubkey}'
# send a GET request to the NIP01 API URL
r = requests.get(nip01_url)
# parse the JSON response and extract the last publish date
try:
resp_json = json.loads(r.content.decode())
last_publish = resp_json['result']['lastPublish']
except:
print(f'Error retrieving last publish date for pubkey: {pubkey}')
continue
# save the last publish date to a file
with open(output_dir + pubkey + '.txt', 'w') as f2:
f2.write(last_publish)
print(f'Last publish date ({last_publish}) saved for pubkey: {pubkey}')
print('All public keys processed.')
```
You'll need to replace the `nip01_api` variable with the API endpoint you want to use, depending on your needs. Also, make sure to create the `data` directory before running the script to store the results.
Hope this helps, let me know if you have any questions!