diff --git a/nostr_dvm/tasks/content_discovery_update_db_only.py b/nostr_dvm/tasks/content_discovery_update_db_only.py index 7a13233..654db75 100644 --- a/nostr_dvm/tasks/content_discovery_update_db_only.py +++ b/nostr_dvm/tasks/content_discovery_update_db_only.py @@ -1,7 +1,11 @@ import asyncio import json import os +import time from datetime import timedelta +from itertools import islice + +import networkx as nx from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \ ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Event, EventId, Kind, \ RelayLimits @@ -14,7 +18,7 @@ from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config from nostr_dvm.utils.nip88_utils import NIP88Config, check_and_set_d_tag_nip88, check_and_set_tiereventid_nip88 from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag, create_amount_tag from nostr_dvm.utils.output_utils import post_process_list_to_events - +from nostr_dvm.utils.wot_utils import build_network_from, save_network, print_results """ This File contains a Module to update the database for content discovery dvms @@ -138,18 +142,46 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface): for relay in self.dvm_config.RECONCILE_DB_RELAY_LIST: await cli.add_relay(relay) + await cli.connect() + if self.dvm_config.WOT_FILTERING: + user = self.dvm_config.WOT_BASED_ON_NPUB + depth = self.dvm_config.WOT_DEPTH + print("Calculating WOT for " + user) + + filtering = cli.filtering() + index_map, G = await build_network_from(user, depth=depth, max_batch=500, max_time_request=10) + + # Do we actually need pagerank here? + #print('computing global pagerank...') + #tic = time.time() + #p_G = nx.pagerank(G, tol=1e-12) + # print("network after pagerank: " + str(len(p_G))) + + wot_keys = [] + for item in islice(G, len(G)): + key = next((PublicKey.parse(pubkey) for pubkey, id in index_map.items() if id == item), + None) + wot_keys.append(key) + + #toc = time.time() + #print(f'finished in {toc - tic} seconds') + await filtering.add_public_keys(wot_keys) + + + + # Mute public key - await cli.mute_public_keys(self.dvm_config.MUTE) + #await cli. (self.dvm_config.MUTE) timestamp_since = Timestamp.now().as_secs() - self.db_since since = Timestamp.from_secs(timestamp_since) filter1 = Filter().kinds([definitions.EventDefinitions.KIND_NOTE, definitions.EventDefinitions.KIND_REACTION, - definitions.EventDefinitions.KIND_ZAP]).since(since) # Notes, reactions, zaps + definitions.EventDefinitions.KIND_ZAP]).since(since) # Notes, reactions, zaps # filter = Filter().author(keys.public_key()) if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value: diff --git a/nostr_dvm/utils/dvmconfig.py b/nostr_dvm/utils/dvmconfig.py index 0c7076a..5cff10e 100644 --- a/nostr_dvm/utils/dvmconfig.py +++ b/nostr_dvm/utils/dvmconfig.py @@ -24,25 +24,9 @@ class DVMConfig: "wss://relay.nostr.net" , "wss://relay.primal.net"] # Straight Censorship (reply guy spam) - MUTE = [PublicKey.parse("npub1x5vhtx7j2prvueeenwf7tmesrzmuzc50zs0aakgd75v5c30ekj3s5zjckj"), - PublicKey.parse("npub1l03urys27uet2u6wq6u90rnzf7kv5c3wfu3cyndqz9lq75g46c5q0wkpsj"), - PublicKey.parse("npub17g7qhlu4caefd88vateedm9wau9ys6xt6jhjcfu2kqyw9xmnucxs5d6crj"), - PublicKey.parse("npub1epwccahqndqhseh6q02seu40cqa2ghk3u9tvu92yh4hd6lmxg33spwzujc"), - PublicKey.parse("npub1v0kgu3hymtd4fw9zrlem6l74c3cwl8jdqentt4qsxrrzan6paxaqkkf6dr"), - PublicKey.parse("npub1y8teqt2jay2ulww87wlmpe97gxhjqvhva60jv3ghp8emgk2da3psc2x7lt"), - PublicKey.parse("npub1drz9ts6esv22vplg9vunajwhts4ecaxvusmpxwy8yy683ejnzfnqvfvtk9"), - PublicKey.parse("npub1af5hgjkjpdqavpu3xqz092xjrvrpr3nzfftp4pgh4nez635hznas7m0vvn"), - PublicKey.parse("npub1rwxfxn33mmt9fe66qwg25lm9pm3nwtj5za5qm5cpqjsxlhk3dtsqkmunfe"), - PublicKey.parse("npub1l6y4l424ggvstc8a40n5c4rf8wwt5hlt5vuhn4dzvx9xf0eff9uqnc2fuw"), - PublicKey.parse("npub1q57y985vcazhx87naj5qhdyxxmtrrqakfq7lmvhxppvduqpfkesq3n46e8"), - PublicKey.parse("npub1dryv50m3rl6cx6ajeakmh3ygz83vjcdf6cga99yllmfx9ugqa04st0nk3w"), - PublicKey.parse("npub1xh3n3q2cp2wf9r66mmzmkyunyj8cf5r8aszsvwtdld6upqjmkxcsxgejsd"), - PublicKey.parse("npub1cek65lcyks0jjwx4y47c0zxmx8y22zn7zmhxktfjr32h2z5wtgeqn70vjc"), - PublicKey.parse("npub1y2v5mqw32m7n8mz4wpypcy7wt0t4hg93g67qw0fuyspjdspk0etqm0xx9y"), - PublicKey.parse("npub1cfgr520quxl8p74f5r3u5snt05dxyshfk88tcm5tuj78ypkdhgyqcpxkx2"), - PublicKey.parse("npub1620alhm0dyn063wlrlp6r8xzxlzdk9pp94xfag99gghj92wentlq23t6rz"), - - ] + WOT_FILTERING = False + WOT_BASED_ON_NPUB = "99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64" + WOT_DEPTH = 2 AVOID_PAID_OUTBOX_RELAY_LIST = AVOID_OUTBOX_RELAY_LIST diff --git a/nostr_dvm/utils/nip65_utils.py b/nostr_dvm/utils/nip65_utils.py index 85639cc..3ed0785 100644 --- a/nostr_dvm/utils/nip65_utils.py +++ b/nostr_dvm/utils/nip65_utils.py @@ -16,7 +16,7 @@ async def nip65_announce_relays(dvm_config, client): content = "" event = EventBuilder(EventDefinitions.KIND_RELAY_ANNOUNCEMENT, content, tags).to_event(keys) - eventid = await send_event(event, client=client, dvm_config=dvm_config, blastr=True) + eventid = await send_event(event, client=client, dvm_config=dvm_config) if (eventid is not None): print( bcolors.BLUE + "[" + dvm_config.NIP89.NAME + "] Announced NIP 65 for " + dvm_config.NIP89.NAME + " (EventID: " + str( diff --git a/tests/discovery.py b/tests/discovery.py index 4f736cb..8147d25 100644 --- a/tests/discovery.py +++ b/tests/discovery.py @@ -63,6 +63,7 @@ def build_db_scheduler(name, identifier, admin_config, options, image, descripti dvm_config.RECONCILE_DB_RELAY_LIST = RECONCILE_DB_RELAY_LIST dvm_config.RELAY_LIST = RELAY_LIST dvm_config.DATABASE = database + dvm_config.WOT_FILTERING = True # Activate these to use a subscription based model instead # dvm_config.SUBSCRIPTION_REQUIRED = True @@ -1127,7 +1128,7 @@ def playground(): subscription_config = DVMConfig() subscription_config.PRIVATE_KEY = check_and_set_private_key("dvm_subscription") npub = Keys.parse(subscription_config.PRIVATE_KEY).public_key().to_bech32() - invoice_key, admin_key, wallet_id, user_id, lnaddress = check_and_set_ln_bits_keys("dvm_subscription", npub) + invoice_key, admin_key, wallet_id, lnaddress = check_and_set_ln_bits_keys("dvm_subscription", npub) subscription_config.RECONCILE_DB_RELAY_LIST = RECONCILE_DB_RELAY_LIST subscription_config.RELAY_LIST = RELAY_LIST subscription_config.LNBITS_INVOICE_KEY = invoice_key