2024-06-04 22:21:21 +02:00
|
|
|
from threading import Thread
|
|
|
|
from nostr_sdk import Keys, Filter, ClientBuilder, NostrDatabase, NegentropyOptions, init_logger, LogLevel
|
|
|
|
init_logger(LogLevel.INFO)
|
|
|
|
keys = Keys.parse("nsec1ufnus6pju578ste3v90xd5m2decpuzpql2295m3sknqcjzyys9ls0qlc85")
|
|
|
|
print(keys.public_key().to_bech32())
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-06-09 12:59:41 +02:00
|
|
|
async def reconcile_db():
|
2024-06-04 22:21:21 +02:00
|
|
|
# Create/open SQLite database
|
2024-09-10 09:20:22 +02:00
|
|
|
database = NostrDatabase.lmdb("nostr.db")
|
2024-06-04 22:21:21 +02:00
|
|
|
|
|
|
|
# NOT AVAILABLE ON WINDOWS AT THE MOMENT!
|
|
|
|
# Create/open nostrdb database
|
|
|
|
# database = NostrDatabase.ndb("ndb")
|
|
|
|
|
|
|
|
client = ClientBuilder().database(database).build()
|
|
|
|
|
2024-06-09 12:59:41 +02:00
|
|
|
await client.add_relay("wss://relay.damus.io")
|
|
|
|
await client.add_relay("wss://atl.purplerelay.com")
|
|
|
|
await client.connect()
|
2024-06-04 22:21:21 +02:00
|
|
|
|
|
|
|
# Negentropy reconciliation
|
|
|
|
f = Filter().author(keys.public_key())
|
|
|
|
opts = NegentropyOptions()
|
2024-06-09 12:59:41 +02:00
|
|
|
await client.reconcile(f, opts)
|
2024-06-04 22:21:21 +02:00
|
|
|
|
2024-06-09 12:59:41 +02:00
|
|
|
await do_some_work()
|
2024-06-04 22:21:21 +02:00
|
|
|
|
2024-06-09 12:59:41 +02:00
|
|
|
async def do_some_work():
|
2024-09-10 09:20:22 +02:00
|
|
|
database = NostrDatabase.lmdb("nostr.db")
|
2024-06-04 22:21:21 +02:00
|
|
|
f = Filter().author(keys.public_key()).limit(10)
|
2024-06-09 12:59:41 +02:00
|
|
|
events = await database.query([f])
|
2024-06-04 22:21:21 +02:00
|
|
|
|
|
|
|
for event in events:
|
|
|
|
print(event.as_json())
|
|
|
|
|
|
|
|
nostr_dvm_thread = Thread(target=reconcile_db)
|
|
|
|
nostr_dvm_thread.start()
|