mirror of
https://github.com/aljazceru/nostrdvm.git
synced 2025-12-23 17:04:27 +01:00
introduce loglevels to reduce logging on demand, improve wot
This commit is contained in:
@@ -38,7 +38,6 @@ class DVM:
|
||||
|
||||
def __init__(self, dvm_config, admin_config=None):
|
||||
|
||||
|
||||
asyncio.run(self.run_dvm(dvm_config, admin_config))
|
||||
|
||||
async def run_dvm(self, dvm_config, admin_config):
|
||||
@@ -57,7 +56,7 @@ class DVM:
|
||||
self.job_list = []
|
||||
self.jobs_on_hold_list = []
|
||||
pk = self.keys.public_key()
|
||||
print(bcolors.GREEN + "[" + self.dvm_config.NIP89.NAME + "] " + "Nostr DVM public key: " + str(
|
||||
print(bcolors.BLUE + "[" + self.dvm_config.NIP89.NAME + "] " + "Nostr DVM public key: " + str(
|
||||
pk.to_bech32()) + " Hex: " +
|
||||
str(pk.to_hex()) + " Supported DVM tasks: " +
|
||||
', '.join(p.NAME + ":" + p.TASK for p in self.dvm_config.SUPPORTED_DVMS) + bcolors.ENDC)
|
||||
@@ -82,6 +81,7 @@ class DVM:
|
||||
keys = self.keys
|
||||
|
||||
async def handle(self, relay_url, subscription_id, nostr_event: Event):
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print(nostr_event.as_json())
|
||||
if EventDefinitions.KIND_NIP90_EXTRACT_TEXT.as_u64() <= nostr_event.kind().as_u64() <= EventDefinitions.KIND_NIP90_GENERIC.as_u64():
|
||||
await handle_nip90_job_event(nostr_event)
|
||||
@@ -110,6 +110,7 @@ class DVM:
|
||||
p_tag_str = tag.as_vec()[1]
|
||||
|
||||
if p_tag_str != "" and p_tag_str != self.dvm_config.PUBLIC_KEY:
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] No public request, also not addressed to me.")
|
||||
return
|
||||
|
||||
@@ -126,7 +127,7 @@ class DVM:
|
||||
await send_job_status_reaction(nip90_event, "error", client=self.client, dvm_config=self.dvm_config)
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Request by blacklisted user, skipped")
|
||||
return
|
||||
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.INFO.value:
|
||||
print(
|
||||
bcolors.MAGENTA + "[" + self.dvm_config.NIP89.NAME + "] Received new Request: " + task + " from " + user.name + bcolors.ENDC)
|
||||
duration = input_data_file_duration(nip90_event, dvm_config=self.dvm_config, client=self.client)
|
||||
@@ -158,7 +159,8 @@ class DVM:
|
||||
self.dvm_config)
|
||||
|
||||
subscription_status = await nip88_has_active_subscription(PublicKey.parse(user.npub),
|
||||
self.dvm_config.NIP88.DTAG, self.client,
|
||||
self.dvm_config.NIP88.DTAG,
|
||||
self.client,
|
||||
self.dvm_config.PUBLIC_KEY)
|
||||
|
||||
if subscription_status["isActive"]:
|
||||
@@ -201,6 +203,7 @@ class DVM:
|
||||
if (user.iswhitelisted or task_is_free or cashu_redeemed) and (
|
||||
p_tag_str == "" or p_tag_str ==
|
||||
self.dvm_config.PUBLIC_KEY):
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print(
|
||||
"[" + self.dvm_config.NIP89.NAME + "] Free task or Whitelisted for task " + task +
|
||||
". Starting processing..")
|
||||
@@ -278,6 +281,7 @@ class DVM:
|
||||
|
||||
|
||||
else:
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Job addressed to someone else, skipping..")
|
||||
# else:
|
||||
# print("[" + self.dvm_config.NIP89.NAME + "] Task " + task + " not supported on this DVM, skipping..")
|
||||
@@ -500,9 +504,12 @@ class DVM:
|
||||
|
||||
# send_event(reply_event, client=self.client, dvm_config=self.dvm_config)
|
||||
await send_event_outbox(reply_event, client=self.client, dvm_config=self.dvm_config)
|
||||
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print(bcolors.GREEN + "[" + self.dvm_config.NIP89.NAME + "] " + str(
|
||||
original_event.kind().as_u64() + 1000) + " Job Response event sent: " + reply_event.as_json() + bcolors.ENDC)
|
||||
elif self.dvm_config.LOGLEVEL.value >= LogLevel.INFO.value:
|
||||
print(bcolors.GREEN + "[" + self.dvm_config.NIP89.NAME + "] " + str(
|
||||
original_event.kind().as_u64() + 1000) + " Job Response event sent: " + reply_event.id().to_hex() + bcolors.ENDC)
|
||||
|
||||
async def send_job_status_reaction(original_event, status, is_paid=True, amount=0, client=None,
|
||||
content=None,
|
||||
@@ -612,8 +619,13 @@ class DVM:
|
||||
# send_event(reaction_event, client=self.client, dvm_config=self.dvm_config)
|
||||
await send_event_outbox(reaction_event, client=self.client, dvm_config=self.dvm_config)
|
||||
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print(bcolors.YELLOW + "[" + self.dvm_config.NIP89.NAME + "]" + " Sent Kind " + str(
|
||||
EventDefinitions.KIND_FEEDBACK.as_u64()) + " Reaction: " + status + " " + reaction_event.as_json() + bcolors.ENDC)
|
||||
elif self.dvm_config.LOGLEVEL.value >= LogLevel.INFO.value:
|
||||
print(bcolors.YELLOW + "[" + self.dvm_config.NIP89.NAME + "]" + " Sent Kind " + str(
|
||||
EventDefinitions.KIND_FEEDBACK.as_u64()) + " Reaction: " + status + " " + reaction_event.id().to_hex() + bcolors.ENDC)
|
||||
|
||||
return reaction_event.as_json()
|
||||
|
||||
async def do_work(job_event, amount):
|
||||
@@ -696,7 +708,7 @@ class DVM:
|
||||
|
||||
for job in self.job_list:
|
||||
if job.bolt11 != "" and job.payment_hash != "" and not job.payment_hash is None and not job.is_paid:
|
||||
ispaid = check_bolt11_ln_bits_is_paid(job.payment_hash, se.dvm_config)
|
||||
ispaid = check_bolt11_ln_bits_is_paid(job.payment_hash, self.dvm_config)
|
||||
if ispaid and job.is_paid is False:
|
||||
print("is paid")
|
||||
job.is_paid = True
|
||||
@@ -716,7 +728,7 @@ class DVM:
|
||||
self.job_list.remove(job)
|
||||
|
||||
for job in self.jobs_on_hold_list:
|
||||
if await check_event_has_not_unfinished_job_input(job.event, False, client=se.client,
|
||||
if await check_event_has_not_unfinished_job_input(job.event, False, client=self.client,
|
||||
dvmconfig=self.dvm_config):
|
||||
await handle_nip90_job_event(nip90_event=job.event)
|
||||
try:
|
||||
|
||||
@@ -8,7 +8,7 @@ import sys
|
||||
from sys import platform
|
||||
from threading import Thread
|
||||
from venv import create
|
||||
from nostr_sdk import Keys, Kind
|
||||
from nostr_sdk import Keys, Kind, LogLevel
|
||||
from nostr_dvm.dvm import DVM
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||
@@ -17,6 +17,7 @@ from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||
from nostr_dvm.utils.output_utils import post_process_result
|
||||
|
||||
|
||||
|
||||
class DVMTaskInterface:
|
||||
NAME: str
|
||||
KIND: Kind
|
||||
@@ -136,11 +137,12 @@ class DVMTaskInterface:
|
||||
return post_process_result(result, event)
|
||||
|
||||
def set_options(self, request_form):
|
||||
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] " + "Setting options...")
|
||||
opts = []
|
||||
if request_form.get("options"):
|
||||
opts = json.loads(request_form["options"])
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] " + str(opts))
|
||||
return dict(opts)
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ from nostr_dvm.utils.nip88_utils import NIP88Config, check_and_set_d_tag_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
|
||||
|
||||
|
||||
"""
|
||||
This File contains a Module to discover popular notes
|
||||
Accepted Inputs: none
|
||||
@@ -112,7 +113,7 @@ class DicoverContentLatestLongForm(DVMTaskInterface):
|
||||
signer = NostrSigner.keys(keys)
|
||||
|
||||
database = await NostrDatabase.sqlite(self.db_name)
|
||||
print(self.db_name)
|
||||
#print(self.db_name)
|
||||
cli = ClientBuilder().database(database).signer(signer).opts(opts).build()
|
||||
await cli.connect()
|
||||
|
||||
@@ -123,7 +124,7 @@ class DicoverContentLatestLongForm(DVMTaskInterface):
|
||||
|
||||
filter1 = Filter().kind(definitions.EventDefinitions.KIND_LONGFORM).since(since)
|
||||
events = await cli.database().query([filter1])
|
||||
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Considering " + str(len(events)) + " Events")
|
||||
ns.finallist = {}
|
||||
index = options["max_results"]
|
||||
@@ -142,6 +143,7 @@ class DicoverContentLatestLongForm(DVMTaskInterface):
|
||||
e_tag = Tag.parse(["e", entry[0]])
|
||||
result_list.append(e_tag.as_vec())
|
||||
await cli.shutdown()
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Filtered " + str(
|
||||
len(result_list)) + " fitting events.")
|
||||
return json.dumps(result_list)
|
||||
@@ -189,6 +191,7 @@ class DicoverContentLatestLongForm(DVMTaskInterface):
|
||||
filter1 = Filter().kinds([definitions.EventDefinitions.KIND_LONGFORM]).since(since) # Notes, reactions, zaps
|
||||
|
||||
# filter = Filter().author(keys.public_key())
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Syncing notes of the last " + str(
|
||||
self.db_since) + " seconds.. this might take a while..")
|
||||
dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN)
|
||||
@@ -196,6 +199,7 @@ class DicoverContentLatestLongForm(DVMTaskInterface):
|
||||
await cli.database().delete(Filter().until(Timestamp.from_secs(
|
||||
Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesn't get too full.
|
||||
await cli.shutdown()
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print(
|
||||
"[" + self.dvm_config.NIP89.NAME + "] Done Syncing Notes of the last " + str(self.db_since) + " seconds..")
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ from nostr_dvm.utils.nip88_utils import NIP88Config, check_and_set_d_tag_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
|
||||
|
||||
|
||||
"""
|
||||
This File contains a Module to discover popular notes
|
||||
Accepted Inputs: none
|
||||
@@ -125,6 +126,7 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
||||
|
||||
filter1 = Filter().kind(definitions.EventDefinitions.KIND_NOTE).since(since)
|
||||
events = await database.query([filter1])
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Considering " + str(len(events)) + " Events")
|
||||
ns.finallist = {}
|
||||
for event in events:
|
||||
@@ -146,6 +148,7 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
||||
e_tag = Tag.parse(["e", entry[0]])
|
||||
result_list.append(e_tag.as_vec())
|
||||
#await cli.shutdown()
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Filtered " + str(
|
||||
len(result_list)) + " fitting events.")
|
||||
return json.dumps(result_list)
|
||||
@@ -192,6 +195,7 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
||||
definitions.EventDefinitions.KIND_ZAP]).since(since) # Notes, reactions, zaps
|
||||
|
||||
# filter = Filter().author(keys.public_key())
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Syncing notes of the last " + str(
|
||||
self.db_since) + " seconds.. this might take a while..")
|
||||
dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN)
|
||||
@@ -199,6 +203,7 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
||||
await cli.database().delete(Filter().until(Timestamp.from_secs(
|
||||
Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesn't get too full.
|
||||
await cli.shutdown()
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print(
|
||||
"[" + self.dvm_config.NIP89.NAME + "] Done Syncing Notes of the last " + str(self.db_since) + " seconds..")
|
||||
|
||||
|
||||
@@ -127,6 +127,7 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface):
|
||||
|
||||
filter1 = Filter().kind(definitions.EventDefinitions.KIND_NOTE).since(since)
|
||||
events = await database.query([filter1])
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Considering " + str(len(events)) + " Events")
|
||||
|
||||
ns.finallist = {}
|
||||
@@ -189,7 +190,7 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface):
|
||||
# print(EventId.parse(entry[0]).to_bech32() + "/" + EventId.parse(entry[0]).to_hex() + ": " + str(entry[1]))
|
||||
e_tag = Tag.parse(["e", entry[0]])
|
||||
result_list.append(e_tag.as_vec())
|
||||
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Filtered " + str(
|
||||
len(result_list)) + " fitting events.")
|
||||
|
||||
@@ -243,6 +244,7 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface):
|
||||
definitions.EventDefinitions.KIND_ZAP]).since(since) # Notes, reactions, zaps
|
||||
|
||||
# filter = Filter().author(keys.public_key())
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Syncing notes of the last " + str(
|
||||
self.db_since) + " seconds.. this might take a while..")
|
||||
dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN)
|
||||
@@ -250,6 +252,7 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface):
|
||||
await cli.database().delete(Filter().until(Timestamp.from_secs(
|
||||
Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesn't get too full.
|
||||
await cli.shutdown()
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print(
|
||||
"[" + self.dvm_config.NIP89.NAME + "] Done Syncing Notes of the last " + str(self.db_since) + " seconds..")
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ from nostr_dvm.utils.nip88_utils import NIP88Config, check_and_set_d_tag_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
|
||||
|
||||
|
||||
"""
|
||||
This File contains a Module to discover popular notes
|
||||
Accepted Inputs: none
|
||||
@@ -141,6 +142,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
|
||||
filter1 = Filter().kind(definitions.EventDefinitions.KIND_NOTE).authors(followings).since(since)
|
||||
events = await cli.database().query([filter1])
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Considering " + str(len(events)) + " Events")
|
||||
|
||||
ns.finallist = {}
|
||||
@@ -162,6 +164,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
result_list.append(e_tag.as_vec())
|
||||
#await cli.connect()
|
||||
await cli.shutdown()
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Filtered " + str(
|
||||
len(result_list)) + " fitting events.")
|
||||
|
||||
@@ -212,6 +215,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
definitions.EventDefinitions.KIND_ZAP]).since(since) # Notes, reactions, zaps
|
||||
|
||||
# filter = Filter().author(keys.public_key())
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Syncing notes of the last " + str(
|
||||
self.db_since) + " seconds.. this might take a while..")
|
||||
dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN)
|
||||
@@ -219,6 +223,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
await cli.database().delete(Filter().until(Timestamp.from_secs(
|
||||
Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesn't get too full.
|
||||
await cli.shutdown()
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Done Syncing Notes of the last " + str(
|
||||
self.db_since) + " seconds..")
|
||||
|
||||
|
||||
@@ -149,6 +149,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
||||
filter1 = Filter().kind(definitions.EventDefinitions.KIND_NOTE).since(since)
|
||||
|
||||
events = await database.query([filter1])
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Considering " + str(len(events)) + " Events")
|
||||
ns.finallist = {}
|
||||
|
||||
@@ -171,7 +172,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
||||
# print(EventId.parse(entry[0]).to_bech32() + "/" + EventId.parse(entry[0]).to_hex() + ": " + str(entry[1]))
|
||||
e_tag = Tag.parse(["e", entry[0]])
|
||||
result_list.append(e_tag.as_vec())
|
||||
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Filtered " + str(
|
||||
len(result_list)) + " fitting events.")
|
||||
#await cli.shutdown()
|
||||
@@ -209,6 +210,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
||||
definitions.EventDefinitions.KIND_ZAP]).since(since) # Notes, reactions, zaps
|
||||
|
||||
# filter = Filter().author(keys.public_key())
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Syncing notes of the last " + str(
|
||||
self.db_since) + " seconds.. this might take a while..")
|
||||
dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN)
|
||||
@@ -216,6 +218,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
||||
await cli.database().delete(Filter().until(Timestamp.from_secs(
|
||||
Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesn't get too full.
|
||||
await cli.shutdown()
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print(
|
||||
"[" + self.dvm_config.NIP89.NAME + "] Done Syncing Notes of the last " + str(self.db_since) + " seconds..")
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ from nostr_dvm.utils.nip88_utils import NIP88Config, check_and_set_d_tag_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
|
||||
|
||||
|
||||
"""
|
||||
This File contains a Module to update the database for content discovery dvms
|
||||
Accepted Inputs: none
|
||||
@@ -141,6 +142,7 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface):
|
||||
definitions.EventDefinitions.KIND_ZAP]).since(since) # Notes, reactions, zaps
|
||||
|
||||
# filter = Filter().author(keys.public_key())
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.IDENTIFIER + "] Syncing notes of the last " + str(
|
||||
self.db_since) + " seconds.. this might take a while..")
|
||||
dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN)
|
||||
@@ -148,6 +150,7 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface):
|
||||
await cli.database().delete(Filter().until(Timestamp.from_secs(
|
||||
Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesn't get too full.
|
||||
await cli.shutdown()
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print(
|
||||
"[" + self.dvm_config.IDENTIFIER + "] Done Syncing Notes of the last " + str(self.db_since) + " seconds..")
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
|
||||
from nostr_sdk import Keys
|
||||
from nostr_sdk import Keys, LogLevel
|
||||
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config
|
||||
@@ -8,7 +8,6 @@ from nostr_dvm.utils.nostr_utils import check_and_set_private_key
|
||||
from nostr_dvm.utils.output_utils import PostProcessFunctionType
|
||||
from nostr_dvm.utils.zap_utils import check_and_set_ln_bits_keys
|
||||
|
||||
|
||||
class DVMConfig:
|
||||
SUPPORTED_DVMS = []
|
||||
PRIVATE_KEY: str = ""
|
||||
@@ -61,6 +60,7 @@ class DVMConfig:
|
||||
SCHEDULE_UPDATES_SECONDS = 0
|
||||
UPDATE_DATABASE = True # DVMs that use a db manage their db by default. If a dvm should use the same db as another DVM, deactive it for those who do.
|
||||
CUSTOM_PROCESSING_MESSAGE = None
|
||||
LOGLEVEL = LogLevel.DEBUG
|
||||
|
||||
|
||||
def build_default_config(identifier):
|
||||
|
||||
@@ -22,6 +22,7 @@ from nostr_dvm.utils.nip89_utils import create_amount_tag, NIP89Config, check_an
|
||||
from nostr_dvm.utils.nostr_utils import check_and_set_private_key
|
||||
from nostr_dvm.utils.zap_utils import check_and_set_ln_bits_keys
|
||||
|
||||
|
||||
rebroadcast_NIP89 = False # Announce NIP89 on startup
|
||||
rebroadcast_NIP65_Relay_List = False
|
||||
update_profile = False
|
||||
@@ -43,7 +44,7 @@ AVOID_PAID_OUTBOX_RELAY_LIST = ["wss://nostrelay.yeghro.site", "wss://nostr.wine
|
||||
"wss://bitcoiner.social", "wss://relay.stoner.com", "wss://nostr.l00p.org", "wss://relay.nostr.ro", "wss://nostr.kollider.xyz",
|
||||
"wss://relay.valera.co", "wss://relay.austrich.net", "wss://relay.nostrich.de", "wss://nostr.azte.co", "wss://nostr-relay.schnitzel.world",
|
||||
"wss://relay.nostriches.org", "wss://happytavern.co", "wss://onlynotes.lol", "wss://offchain.pub", "wss://purplepag.es", "wss://relay.plebstr.com"
|
||||
"wss://poster.place/relay", "wss://relayable.org", "wss://bbb.santos.lol", "wss://relay.bitheaven.social"
|
||||
"wss://poster.place/relay", "wss://relayable.org", "wss://bbb.santos.lol", "wss://relay.bitheaven.social", "wss://theforest.nostr1.com"
|
||||
|
||||
|
||||
|
||||
@@ -59,6 +60,7 @@ def build_db_scheduler(name, identifier, admin_config, options, image, descripti
|
||||
dvm_config.SHOWLOG = True
|
||||
dvm_config.SCHEDULE_UPDATES_SECONDS = update_rate # Every 10 minutes
|
||||
dvm_config.UPDATE_DATABASE = update_db
|
||||
dvm_config.LOGLEVEL = LogLevel.INFO
|
||||
# Activate these to use a subscription based model instead
|
||||
# dvm_config.SUBSCRIPTION_REQUIRED = True
|
||||
# dvm_config.SUBSCRIPTION_DAILY_COST = 1
|
||||
@@ -99,6 +101,7 @@ def build_example_nostrband(name, identifier, admin_config, image, about, custom
|
||||
dvm_config.USE_OWN_VENV = False
|
||||
dvm_config.CUSTOM_PROCESSING_MESSAGE = custom_processing_msg
|
||||
dvm_config.AVOID_PAID_OUTBOX_RELAY_LIST = AVOID_PAID_OUTBOX_RELAY_LIST
|
||||
dvm_config.LOGLEVEL = LogLevel.INFO
|
||||
#dvm_config.RELAY_LIST = ["wss://dvms.f7z.io",
|
||||
# "wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg"
|
||||
# ]
|
||||
@@ -131,6 +134,7 @@ def build_longform(name, identifier, admin_config, options, cost=0, update_rate=
|
||||
dvm_config.SCHEDULE_UPDATES_SECONDS = update_rate # Every 10 minutes
|
||||
dvm_config.UPDATE_DATABASE = update_db
|
||||
dvm_config.AVOID_PAID_OUTBOX_RELAY_LIST = AVOID_PAID_OUTBOX_RELAY_LIST
|
||||
dvm_config.LOGLEVEL = LogLevel.INFO
|
||||
# Activate these to use a subscription based model instead
|
||||
# dvm_config.SUBSCRIPTION_REQUIRED = True
|
||||
# dvm_config.SUBSCRIPTION_DAILY_COST = 1
|
||||
@@ -180,6 +184,7 @@ def build_example_topic(name, identifier, admin_config, options, image, descript
|
||||
dvm_config.SCHEDULE_UPDATES_SECONDS = update_rate # Every 10 minutes
|
||||
dvm_config.UPDATE_DATABASE = update_db
|
||||
dvm_config.FIX_COST = cost
|
||||
dvm_config.LOGLEVEL = LogLevel.INFO
|
||||
dvm_config.CUSTOM_PROCESSING_MESSAGE = processing_msg
|
||||
dvm_config.AVOID_PAID_OUTBOX_RELAY_LIST = AVOID_PAID_OUTBOX_RELAY_LIST
|
||||
#dvm_config.RELAY_LIST = ["wss://dvms.f7z.io",
|
||||
@@ -219,6 +224,7 @@ def build_example_popular(name, identifier, admin_config, options, image, cost=0
|
||||
update_db=True):
|
||||
dvm_config = build_default_config(identifier)
|
||||
dvm_config.USE_OWN_VENV = False
|
||||
dvm_config.LOGLEVEL = LogLevel.INFO
|
||||
# dvm_config.SHOWLOG = True
|
||||
dvm_config.SCHEDULE_UPDATES_SECONDS = update_rate # Every 10 minutes
|
||||
dvm_config.UPDATE_DATABASE = update_db
|
||||
@@ -264,6 +270,7 @@ def build_example_popular_followers(name, identifier, admin_config, options, ima
|
||||
dvm_config = build_default_config(identifier)
|
||||
dvm_config.USE_OWN_VENV = False
|
||||
dvm_config.SHOWLOG = True
|
||||
dvm_config.LOGLEVEL = LogLevel.INFO
|
||||
dvm_config.SCHEDULE_UPDATES_SECONDS = update_rate # Every x seconds
|
||||
dvm_config.UPDATE_DATABASE = update_db
|
||||
dvm_config.FIX_COST = cost
|
||||
@@ -309,6 +316,7 @@ def build_example_top_zapped(name, identifier, admin_config, options, image, cos
|
||||
dvm_config = build_default_config(identifier)
|
||||
dvm_config.USE_OWN_VENV = False
|
||||
dvm_config.SHOWLOG = True
|
||||
dvm_config.LOGLEVEL = LogLevel.INFO
|
||||
dvm_config.SCHEDULE_UPDATES_SECONDS = update_rate # Every 10 minutes
|
||||
dvm_config.UPDATE_DATABASE = update_db
|
||||
dvm_config.FIX_COST = cost
|
||||
|
||||
72
tests/wot.py
72
tests/wot.py
@@ -78,7 +78,11 @@ async def analyse_users(user_ids=None):
|
||||
try:
|
||||
user_keys = []
|
||||
for npub in user_ids:
|
||||
try:
|
||||
user_keys.append(PublicKey.parse(npub))
|
||||
except Exception as e:
|
||||
print(npub)
|
||||
print(e)
|
||||
|
||||
database = await NostrDatabase.sqlite("db/nostr_followlists.db")
|
||||
followers_filter = Filter().authors(user_keys).kind(Kind(3))
|
||||
@@ -94,8 +98,10 @@ async def analyse_users(user_ids=None):
|
||||
|
||||
return allfriends
|
||||
else:
|
||||
print("no followers")
|
||||
return []
|
||||
except:
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return []
|
||||
|
||||
|
||||
@@ -117,12 +123,16 @@ def write_to_csv(friends, file="friends222.csv"):
|
||||
writer.writerow(row)
|
||||
|
||||
|
||||
def main(user_key):
|
||||
create_csv = True
|
||||
def main(user_key, create_csv, get_profile = False, remove_followings_from_set = False):
|
||||
|
||||
file = "db/friends223.csv"
|
||||
# make sure key is in hex format
|
||||
|
||||
|
||||
if create_csv:
|
||||
# clear previous file
|
||||
try:
|
||||
print("Deleting existing file, creating new one")
|
||||
os.remove(file)
|
||||
except:
|
||||
print("Creating new file")
|
||||
@@ -130,23 +140,32 @@ def main(user_key):
|
||||
asyncio.run(sync_db())
|
||||
|
||||
|
||||
# make sure key is in hex format
|
||||
user_id = PublicKey.parse(user_key).to_hex()
|
||||
user_friends = asyncio.run(analyse_users([user_id]))
|
||||
user_friends_level1 = asyncio.run(analyse_users([user_id]))
|
||||
friendlist = []
|
||||
for npub in user_friends[0].friends:
|
||||
for npub in user_friends_level1[0].friends:
|
||||
friendlist.append(npub)
|
||||
me = Friend(user_id, friendlist)
|
||||
|
||||
write_to_csv([me], file)
|
||||
|
||||
# for every npub we follow, we look at the npubs they follow (this might take a while)
|
||||
friendlist = []
|
||||
for friend in user_friends:
|
||||
for npub in friend.friends:
|
||||
friendlist.append(npub)
|
||||
|
||||
users_friends = asyncio.run(analyse_users(friendlist))
|
||||
write_to_csv(users_friends, file)
|
||||
# for every npub we follow, we look at the npubs they follow (this might take a while)
|
||||
friendlist2 = []
|
||||
for friend in user_friends_level1:
|
||||
for npub in friend.friends:
|
||||
friendlist2.append(npub)
|
||||
|
||||
user_friends_level2 = asyncio.run(analyse_users(friendlist2))
|
||||
write_to_csv(user_friends_level2, file)
|
||||
|
||||
friendlist3 = []
|
||||
for friend in user_friends_level2:
|
||||
for npub in friend.friends:
|
||||
friendlist3.append(npub)
|
||||
print(len(friendlist3))
|
||||
user_friends_level3 = asyncio.run(analyse_users(friendlist3))
|
||||
write_to_csv(user_friends_level3, file)
|
||||
|
||||
|
||||
df = pd.read_csv(file, sep=',')
|
||||
@@ -156,19 +175,40 @@ def main(user_key):
|
||||
G_fb = nx.read_edgelist(file, delimiter=",", create_using=nx.DiGraph(), nodetype=str)
|
||||
print(G_fb)
|
||||
pr = nx.pagerank(G_fb)
|
||||
# Use this to find people your followers follow
|
||||
if remove_followings_from_set:
|
||||
user_id = PublicKey.parse(user_key).to_hex()
|
||||
user_friends_level1 = asyncio.run(analyse_users([user_id]))
|
||||
friendlist = []
|
||||
for npub in user_friends_level1[0].friends:
|
||||
friendlist.append(npub)
|
||||
|
||||
sorted_nodes = sorted([(node, pagerank) for node, pagerank in pr.items() if node not in friendlist], key=lambda x: pr[x[0]],
|
||||
reverse=True)[:50]
|
||||
else:
|
||||
sorted_nodes = sorted([(node, pagerank) for node, pagerank in pr.items()], key=lambda x: pr[x[0]],
|
||||
reverse=True)[:50]
|
||||
|
||||
|
||||
|
||||
for node in sorted_nodes:
|
||||
# print(PublicKey.parse(node[0]).to_bech32() + "," + str(node[1]))
|
||||
name, nip05, lud16 = asyncio.run(getmetadata(node[0]))
|
||||
try:
|
||||
pk = PublicKey.parse(node[0]).to_bech32()
|
||||
except:
|
||||
pk = node[0]
|
||||
|
||||
if get_profile:
|
||||
name, nip05, lud16 = asyncio.run(getmetadata(node[0]))
|
||||
print(name + " (" + pk + ") " + "," + str(node[1]))
|
||||
else:
|
||||
print(pk + "," + str(node[1]))
|
||||
|
||||
|
||||
|
||||
user_id = "99bb5591c9116600f845107d31f9b59e2f7c7e09a1ff802e84f1d43da557ca64"
|
||||
#user_id = "npub1gcxzte5zlkncx26j68ez60fzkvtkm9e0vrwdcvsjakxf9mu9qewqlfnj5z"
|
||||
|
||||
main(user_id)
|
||||
fetch_profiles = True
|
||||
create_csv = False
|
||||
remove_followings_from_set = True
|
||||
main(user_id, create_csv, fetch_profiles, remove_followings_from_set)
|
||||
|
||||
Reference in New Issue
Block a user