mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-03-26 17:41:43 +01:00
and another cleanup
This commit is contained in:
parent
69a369110a
commit
b12d2d1c2c
@ -1,10 +1,9 @@
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
from datetime import timedelta
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Event, EventId, Kind, \
|
||||
RelayOptions, RelayLimits
|
||||
|
||||
from nostr_sdk import Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Event, Kind, \
|
||||
RelayLimits
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils import definitions
|
||||
@ -15,7 +14,6 @@ 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
|
||||
@ -69,7 +67,6 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
user = event.author().to_hex()
|
||||
max_results = 100
|
||||
|
||||
|
||||
for tag in event.tags():
|
||||
if tag.as_vec()[0] == 'i':
|
||||
input_type = tag.as_vec()[2]
|
||||
@ -80,8 +77,6 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
elif param == "user": # check for param type
|
||||
user = tag.as_vec()[2]
|
||||
|
||||
|
||||
|
||||
options = {
|
||||
"max_results": max_results,
|
||||
"user": user,
|
||||
@ -96,32 +91,33 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
|
||||
options = self.set_options(request_form)
|
||||
relaylimits = RelayLimits.disable()
|
||||
opts = (Options().wait_for_send(True).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)).relay_limits(relaylimits))
|
||||
opts = (
|
||||
Options().wait_for_send(True).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)).relay_limits(
|
||||
relaylimits))
|
||||
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
|
||||
keys = Keys.parse(sk.to_hex())
|
||||
signer = NostrSigner.keys(keys)
|
||||
|
||||
database = NostrDatabase.lmdb(self.db_name)
|
||||
database = NostrDatabase.lmdb(self.db_name)
|
||||
cli = ClientBuilder().database(database).signer(signer).opts(opts).build()
|
||||
for relay in self.dvm_config.RECONCILE_DB_RELAY_LIST:
|
||||
await cli.add_relay(relay)
|
||||
|
||||
#ropts = RelayOptions().ping(False)
|
||||
#cli.add_relay_with_opts("wss://nostr.band", ropts)
|
||||
# ropts = RelayOptions().ping(False)
|
||||
# cli.add_relay_with_opts("wss://nostr.band", ropts)
|
||||
|
||||
await cli.connect()
|
||||
|
||||
user = PublicKey.parse(options["user"])
|
||||
followers_filter = Filter().author(user).kinds([Kind(3)])
|
||||
followers = await cli.get_events_of([followers_filter], relay_timeout)
|
||||
#print(followers)
|
||||
# print(followers)
|
||||
|
||||
# Negentropy reconciliation
|
||||
# Query events from database
|
||||
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
||||
since = Timestamp.from_secs(timestamp_since)
|
||||
|
||||
|
||||
result_list = []
|
||||
|
||||
if len(followers) > 0:
|
||||
@ -132,7 +128,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
newest = entry.created_at().as_secs()
|
||||
best_entry = entry
|
||||
|
||||
#print(best_entry.as_json())
|
||||
# print(best_entry.as_json())
|
||||
followings = []
|
||||
for tag in best_entry.tags():
|
||||
if tag.as_vec()[0] == "p":
|
||||
@ -146,22 +142,22 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
|
||||
ns.finallist = {}
|
||||
for event in events:
|
||||
#if event.created_at().as_secs() > timestamp_since:
|
||||
# if event.created_at().as_secs() > timestamp_since:
|
||||
filt = Filter().kinds(
|
||||
[definitions.EventDefinitions.KIND_ZAP, definitions.EventDefinitions.KIND_REACTION, definitions.EventDefinitions.KIND_REPOST,
|
||||
[definitions.EventDefinitions.KIND_ZAP, definitions.EventDefinitions.KIND_REACTION,
|
||||
definitions.EventDefinitions.KIND_REPOST,
|
||||
definitions.EventDefinitions.KIND_NOTE]).event(event.id()).since(since)
|
||||
reactions = await cli.database().query([filt])
|
||||
if len(reactions) >= self.min_reactions:
|
||||
ns.finallist[event.id().to_hex()] = len(reactions)
|
||||
|
||||
|
||||
|
||||
finallist_sorted = sorted(ns.finallist.items(), key=lambda x: x[1], reverse=True)[:int(options["max_results"])]
|
||||
finallist_sorted = sorted(ns.finallist.items(), key=lambda x: x[1], reverse=True)[
|
||||
:int(options["max_results"])]
|
||||
for entry in finallist_sorted:
|
||||
# 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())
|
||||
#await cli.connect()
|
||||
# await cli.connect()
|
||||
await cli.shutdown()
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Filtered " + str(
|
||||
@ -192,7 +188,6 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
self.last_schedule = Timestamp.now().as_secs()
|
||||
return 1
|
||||
|
||||
|
||||
async def sync_db(self):
|
||||
try:
|
||||
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_LONG_TIMEOUT)))
|
||||
@ -233,7 +228,8 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
||||
# We build an example here that we can call by either calling this file directly from the main directory,
|
||||
# or by adding it to our playground. You can call the example and adjust it to your needs or redefine it in the
|
||||
# playground or elsewhere
|
||||
def build_example(name, identifier, admin_config, options, cost=0, update_rate=300, processing_msg=None, update_db=True):
|
||||
def build_example(name, identifier, admin_config, options, cost=0, update_rate=300, processing_msg=None,
|
||||
update_db=True):
|
||||
dvm_config = build_default_config(identifier)
|
||||
dvm_config.USE_OWN_VENV = False
|
||||
dvm_config.SHOWLOG = True
|
||||
@ -274,7 +270,8 @@ def build_example(name, identifier, admin_config, options, cost=0, update_rate=
|
||||
# admin_config.UPDATE_PROFILE = False
|
||||
# admin_config.REBROADCAST_NIP89 = False
|
||||
|
||||
return DicoverContentCurrentlyPopularFollowers(name=name, dvm_config=dvm_config, nip89config=nip89config, options=options,
|
||||
return DicoverContentCurrentlyPopularFollowers(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||
options=options,
|
||||
admin_config=admin_config)
|
||||
|
||||
|
||||
@ -337,4 +334,4 @@ def build_example_subscription(name, identifier, admin_config, options, processi
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
process_venv(DicoverContentCurrentlyPopularFollowers)
|
||||
process_venv(DicoverContentCurrentlyPopularFollowers)
|
||||
|
@ -1,10 +1,11 @@
|
||||
import asyncio
|
||||
import json
|
||||
import json
|
||||
import os
|
||||
from datetime import timedelta
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Event, EventId, Kind, \
|
||||
RelayOptions, RelayLimits
|
||||
|
||||
from nostr_sdk import Timestamp, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, EventId, Kind, \
|
||||
RelayLimits
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils import definitions
|
||||
@ -15,7 +16,6 @@ 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
|
||||
@ -119,7 +119,6 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
||||
|
||||
filter1 = Filter().kind(definitions.EventDefinitions.KIND_NIP93_GALLERYENTRY).since(since)
|
||||
|
||||
|
||||
ge_events = await databasegallery.query([filter1])
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Considering " + str(len(ge_events)) + " Events")
|
||||
@ -129,7 +128,7 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
||||
relays = []
|
||||
|
||||
if len(ge_events) == 0:
|
||||
return[]
|
||||
return []
|
||||
|
||||
for ge_event in ge_events:
|
||||
|
||||
@ -138,15 +137,14 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
||||
if tag.as_vec()[0] == "e":
|
||||
id = EventId.from_hex(tag.as_vec()[1])
|
||||
ids.append(id)
|
||||
#if len(tag.as_vec()) > 2:
|
||||
#if (tag.as_vec()[2]) not in relays:
|
||||
# relays.append(tag.as_vec()[2])
|
||||
# if len(tag.as_vec()) > 2:
|
||||
# if (tag.as_vec()[2]) not in relays:
|
||||
# relays.append(tag.as_vec()[2])
|
||||
|
||||
if id is None:
|
||||
print("No event id found")
|
||||
continue
|
||||
|
||||
|
||||
relaylimits = RelayLimits.disable()
|
||||
opts = (Options().wait_for_send(True).send_timeout(
|
||||
timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)).relay_limits(relaylimits))
|
||||
@ -164,19 +162,18 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
||||
await cli.connect()
|
||||
|
||||
filtreactions = Filter().kinds([definitions.EventDefinitions.KIND_ZAP, definitions.EventDefinitions.KIND_REPOST,
|
||||
definitions.EventDefinitions.KIND_REACTION, definitions.EventDefinitions.KIND_DELETION,
|
||||
definitions.EventDefinitions.KIND_NOTE]).events(ids).since(since)
|
||||
definitions.EventDefinitions.KIND_REACTION,
|
||||
definitions.EventDefinitions.KIND_DELETION,
|
||||
definitions.EventDefinitions.KIND_NOTE]).events(ids).since(since)
|
||||
|
||||
dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN)
|
||||
await cli.reconcile(filtreactions, dbopts)
|
||||
|
||||
|
||||
filter2 = Filter().ids(ids)
|
||||
events = await cli.get_events_of([filter2], relay_timeout)
|
||||
|
||||
print(len(events))
|
||||
|
||||
|
||||
for event in events:
|
||||
if event.created_at().as_secs() > timestamp_since:
|
||||
filt1 = Filter().kinds([definitions.EventDefinitions.KIND_DELETION]).event(event.id()).limit(1)
|
||||
@ -185,8 +182,6 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
||||
print("Deleted event, skipping")
|
||||
continue
|
||||
|
||||
|
||||
|
||||
filt = Filter().kinds([definitions.EventDefinitions.KIND_ZAP, definitions.EventDefinitions.KIND_REPOST,
|
||||
definitions.EventDefinitions.KIND_REACTION,
|
||||
definitions.EventDefinitions.KIND_NOTE]).event(event.id()).since(since)
|
||||
@ -219,7 +214,6 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
||||
# await cli.shutdown()
|
||||
return json.dumps(result_list)
|
||||
|
||||
|
||||
async def post_process(self, result, event):
|
||||
"""Overwrite the interface function to return a social client readable format, if requested"""
|
||||
for tag in event.tags():
|
||||
@ -250,7 +244,7 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
||||
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
|
||||
keys = Keys.parse(sk.to_hex())
|
||||
signer = NostrSigner.keys(keys)
|
||||
database = NostrDatabase.lmdb(self.db_name)
|
||||
database = NostrDatabase.lmdb(self.db_name)
|
||||
cli = ClientBuilder().signer(signer).database(database).opts(opts).build()
|
||||
|
||||
for relay in self.dvm_config.RECONCILE_DB_RELAY_LIST:
|
||||
@ -261,7 +255,8 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
||||
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
||||
since = Timestamp.from_secs(timestamp_since)
|
||||
|
||||
filter1 = Filter().kinds([definitions.EventDefinitions.KIND_NIP93_GALLERYENTRY]).since(since) # Notes, reactions, zaps
|
||||
filter1 = Filter().kinds([definitions.EventDefinitions.KIND_NIP93_GALLERYENTRY]).since(
|
||||
since) # Notes, reactions, zaps
|
||||
|
||||
# filter = Filter().author(keys.public_key())
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
@ -274,7 +269,8 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
||||
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..")
|
||||
"[" + self.dvm_config.NIP89.NAME + "] Done Syncing Notes of the last " + str(
|
||||
self.db_since) + " seconds..")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
@ -326,7 +322,7 @@ def build_example(name, identifier, admin_config, options, cost=0, update_rate=1
|
||||
# admin_config.REBROADCAST_NIP89 = False
|
||||
|
||||
return DicoverContentCurrentlyPopularGallery(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||
admin_config=admin_config, options=options)
|
||||
admin_config=admin_config, options=options)
|
||||
|
||||
|
||||
def build_example_subscription(name, identifier, admin_config, options, update_rate=180, processing_msg=None,
|
||||
@ -389,8 +385,8 @@ def build_example_subscription(name, identifier, admin_config, options, update_r
|
||||
# admin_config.PRIVKEY = dvm_config.PRIVATE_KEY
|
||||
|
||||
return DicoverContentCurrentlyPopularGallery(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||
nip88config=nip88config, options=options,
|
||||
admin_config=admin_config)
|
||||
nip88config=nip88config, options=options,
|
||||
admin_config=admin_config)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -1,10 +1,10 @@
|
||||
import asyncio
|
||||
import json
|
||||
import json
|
||||
import os
|
||||
from datetime import timedelta
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Event, EventId, Kind, \
|
||||
RelayOptions
|
||||
|
||||
from nostr_sdk import Timestamp, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, init_logger, LogLevel, Kind
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils import definitions
|
||||
@ -106,7 +106,6 @@ class DicoverContentCurrentlyPopularMostr(DVMTaskInterface):
|
||||
from nostr_sdk import Filter
|
||||
from types import SimpleNamespace
|
||||
|
||||
|
||||
ns = SimpleNamespace()
|
||||
options = self.set_options(request_form)
|
||||
|
||||
@ -116,7 +115,6 @@ class DicoverContentCurrentlyPopularMostr(DVMTaskInterface):
|
||||
keys = Keys.parse(sk.to_hex())
|
||||
signer = NostrSigner.keys(keys)
|
||||
|
||||
|
||||
database = NostrDatabase.lmdb(self.db_name)
|
||||
try:
|
||||
await database.delete(Filter().until(Timestamp.from_secs(
|
||||
@ -125,7 +123,6 @@ class DicoverContentCurrentlyPopularMostr(DVMTaskInterface):
|
||||
print(e)
|
||||
cli = ClientBuilder().signer(signer).database(database).opts(opts).build()
|
||||
|
||||
|
||||
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
||||
since = Timestamp.from_secs(timestamp_since)
|
||||
|
||||
@ -162,7 +159,6 @@ class DicoverContentCurrentlyPopularMostr(DVMTaskInterface):
|
||||
# await cli.shutdown()
|
||||
return json.dumps(result_list)
|
||||
|
||||
|
||||
async def post_process(self, result, event):
|
||||
"""Overwrite the interface function to return a social client readable format, if requested"""
|
||||
for tag in event.tags():
|
||||
@ -220,10 +216,10 @@ class DicoverContentCurrentlyPopularMostr(DVMTaskInterface):
|
||||
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)
|
||||
#await cli.reconcile(filter1, dbopts)
|
||||
#await cli.reconcile(filter2, dbopts)
|
||||
#await cli.reconcile(filter3, dbopts)
|
||||
# dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN)
|
||||
# await cli.reconcile(filter1, dbopts)
|
||||
# await cli.reconcile(filter2, dbopts)
|
||||
# await cli.reconcile(filter3, dbopts)
|
||||
|
||||
# RECONCOILE NOT POSSIBLE ON THESE RELAYS SO WE FETCH AB BUNCH (will be stored in db)
|
||||
try:
|
||||
|
@ -1,9 +1,10 @@
|
||||
import asyncio
|
||||
import json
|
||||
import json
|
||||
import os
|
||||
from datetime import timedelta
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Event, EventId, Kind, \
|
||||
|
||||
from nostr_sdk import Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Kind, \
|
||||
RelayLimits
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
@ -167,7 +168,7 @@ class DicoverContentCurrentlyPopularNonFollowers(DVMTaskInterface):
|
||||
newest = entry.created_at().as_secs()
|
||||
best_entry = entry
|
||||
|
||||
#print(best_entry.as_json())
|
||||
# print(best_entry.as_json())
|
||||
followings = []
|
||||
for tag in best_entry.tags():
|
||||
if tag.as_vec()[0] == "p":
|
||||
@ -211,7 +212,7 @@ class DicoverContentCurrentlyPopularNonFollowers(DVMTaskInterface):
|
||||
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()
|
||||
# await cli.shutdown()
|
||||
return json.dumps(result_list)
|
||||
|
||||
async def schedule(self, dvm_config):
|
||||
@ -241,8 +242,9 @@ class DicoverContentCurrentlyPopularNonFollowers(DVMTaskInterface):
|
||||
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
|
||||
filter1 = Filter().kinds(
|
||||
[definitions.EventDefinitions.KIND_NOTE, definitions.EventDefinitions.KIND_REACTION,
|
||||
definitions.EventDefinitions.KIND_ZAP]).since(since) # Notes, reactions, zaps
|
||||
|
||||
# filter = Filter().author(keys.public_key())
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
@ -255,7 +257,8 @@ class DicoverContentCurrentlyPopularNonFollowers(DVMTaskInterface):
|
||||
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..")
|
||||
"[" + self.dvm_config.NIP89.NAME + "] Done Syncing Notes of the last " + str(
|
||||
self.db_since) + " seconds..")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
@ -302,7 +305,7 @@ def build_example(name, identifier, admin_config, options, image, description, u
|
||||
nip89config.CONTENT = json.dumps(nip89info)
|
||||
|
||||
return DicoverContentCurrentlyPopularNonFollowers(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||
admin_config=admin_config, options=options)
|
||||
admin_config=admin_config, options=options)
|
||||
|
||||
|
||||
def build_example_subscription(name, identifier, admin_config, options, image, description, processing_msg=None,
|
||||
@ -359,9 +362,9 @@ def build_example_subscription(name, identifier, admin_config, options, image, d
|
||||
# admin_config.PRIVKEY = dvm_config.PRIVATE_KEY
|
||||
|
||||
return DicoverContentCurrentlyPopularNonFollowers(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||
nip88config=nip88config,
|
||||
admin_config=admin_config,
|
||||
options=options)
|
||||
nip88config=nip88config,
|
||||
admin_config=admin_config,
|
||||
options=options)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -1,9 +1,10 @@
|
||||
import asyncio
|
||||
import json
|
||||
import json
|
||||
import os
|
||||
from datetime import timedelta
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Event, EventId, Kind
|
||||
|
||||
from nostr_sdk import Timestamp, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Kind
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils import definitions
|
||||
@ -39,7 +40,6 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
||||
result = ""
|
||||
database = None
|
||||
|
||||
|
||||
async def init_dvm(self, name, dvm_config: DVMConfig, nip89config: NIP89Config, nip88config: NIP88Config = None,
|
||||
admin_config: AdminConfig = None, options=None):
|
||||
|
||||
@ -159,8 +159,6 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
||||
filter = Filter().kind(definitions.EventDefinitions.KIND_NOTE).since(since).search(word)
|
||||
filters.append(filter)
|
||||
|
||||
|
||||
|
||||
events = await self.database.query(filters)
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Considering " + str(len(events)) + " Events")
|
||||
@ -168,7 +166,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
||||
|
||||
for event in events:
|
||||
if all(ele in event.content().lower() for ele in self.must_list):
|
||||
#if any(ele in event.content().lower() for ele in self.search_list):
|
||||
# if any(ele in event.content().lower() for ele in self.search_list):
|
||||
if not any(ele in event.content().lower() for ele in self.avoid_list):
|
||||
filt = Filter().kinds(
|
||||
[definitions.EventDefinitions.KIND_ZAP, definitions.EventDefinitions.KIND_REACTION,
|
||||
@ -187,7 +185,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
||||
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()
|
||||
# await cli.shutdown()
|
||||
return json.dumps(result_list)
|
||||
|
||||
async def schedule(self, dvm_config):
|
||||
@ -219,8 +217,9 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
||||
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
|
||||
filter1 = Filter().kinds(
|
||||
[definitions.EventDefinitions.KIND_NOTE, definitions.EventDefinitions.KIND_REACTION,
|
||||
definitions.EventDefinitions.KIND_ZAP]).since(since) # Notes, reactions, zaps
|
||||
|
||||
# filter = Filter().author(keys.public_key())
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
@ -232,11 +231,13 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
||||
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..")
|
||||
print("[" + self.dvm_config.NIP89.NAME + "] Done Syncing Notes of the last " + str(
|
||||
self.db_since) + " seconds..")
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
# We build an example here that we can call by either calling this file directly from the main directory,
|
||||
# or by adding it to our playground. You can call the example and adjust it to your needs or redefine it in the
|
||||
# playground or elsewhere
|
||||
|
@ -1,13 +1,11 @@
|
||||
import asyncio
|
||||
import json
|
||||
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, \
|
||||
from nostr_sdk import Timestamp, PublicKey, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Kind, \
|
||||
RelayLimits, RelayFilteringMode
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
@ -18,7 +16,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_wot_network, save_network, print_results
|
||||
from nostr_dvm.utils.wot_utils import build_wot_network
|
||||
|
||||
"""
|
||||
This File contains a Module to update the database for content discovery dvms
|
||||
@ -131,7 +129,8 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface):
|
||||
async def sync_db(self):
|
||||
try:
|
||||
relaylimits = RelayLimits.disable()
|
||||
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_LONG_TIMEOUT))).relay_limits(relaylimits)
|
||||
opts = (Options().wait_for_send(False).send_timeout(
|
||||
timedelta(seconds=self.dvm_config.RELAY_LONG_TIMEOUT))).relay_limits(relaylimits)
|
||||
if self.dvm_config.WOT_FILTERING:
|
||||
opts = opts.filtering_mode(RelayFilteringMode.WHITELIST)
|
||||
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
|
||||
@ -145,19 +144,19 @@ 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:
|
||||
print("Calculating WOT for " + str(self.dvm_config.WOT_BASED_ON_NPUBS))
|
||||
filtering = cli.filtering()
|
||||
index_map, G = await build_wot_network(self.dvm_config.WOT_BASED_ON_NPUBS, depth=self.dvm_config.WOT_DEPTH, max_batch=500, max_time_request=10)
|
||||
index_map, G = await build_wot_network(self.dvm_config.WOT_BASED_ON_NPUBS,
|
||||
depth=self.dvm_config.WOT_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('computing global pagerank...')
|
||||
# tic = time.time()
|
||||
# p_G = nx.pagerank(G, tol=1e-12)
|
||||
# print("network after pagerank: " + str(len(p_G)))
|
||||
|
||||
wot_keys = []
|
||||
@ -166,22 +165,19 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface):
|
||||
None)
|
||||
wot_keys.append(key)
|
||||
|
||||
#toc = time.time()
|
||||
#print(f'finished in {toc - tic} seconds')
|
||||
# toc = time.time()
|
||||
# print(f'finished in {toc - tic} seconds')
|
||||
await filtering.add_public_keys(wot_keys)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Mute public key
|
||||
#await cli. (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
|
||||
filter1 = Filter().kinds(
|
||||
[definitions.EventDefinitions.KIND_NOTE, definitions.EventDefinitions.KIND_REACTION,
|
||||
definitions.EventDefinitions.KIND_ZAP]).since(since) # Notes, reactions, zaps
|
||||
|
||||
# filter = Filter().author(keys.public_key())
|
||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||
@ -194,10 +190,12 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface):
|
||||
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..")
|
||||
"[" + self.dvm_config.IDENTIFIER + "] Done Syncing Notes of the last " + str(
|
||||
self.db_since) + " seconds..")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
# We build an example here that we can call by either calling this file directly from the main directory,
|
||||
# or by adding it to our playground. You can call the example and adjust it to your needs or redefine it in the
|
||||
# playground or elsewhere
|
||||
|
@ -1,10 +1,8 @@
|
||||
import json
|
||||
import os
|
||||
from datetime import timedelta
|
||||
from threading import Thread
|
||||
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayOptions, \
|
||||
RelayLimits, Event
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayLimits
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
||||
@ -96,7 +94,7 @@ class DiscoverReports(DVMTaskInterface):
|
||||
# if we don't add users, e.g. by a wot, we check all our followers.
|
||||
if len(pubkeys) == 0:
|
||||
followers_filter = Filter().author(PublicKey.parse(options["sender"])).kind(Kind(3))
|
||||
followers = await cli.get_events_of([followers_filter],relay_timeout)
|
||||
followers = await cli.get_events_of([followers_filter], relay_timeout)
|
||||
|
||||
if len(followers) > 0:
|
||||
result_list = []
|
||||
|
@ -4,7 +4,7 @@ import os
|
||||
from datetime import timedelta
|
||||
from threading import Thread
|
||||
|
||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayOptions, \
|
||||
from nostr_sdk import Client, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayOptions, \
|
||||
RelayLimits
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
@ -63,7 +63,9 @@ class DiscoverNonFollowers(DVMTaskInterface):
|
||||
from types import SimpleNamespace
|
||||
ns = SimpleNamespace()
|
||||
relaylimits = RelayLimits.disable()
|
||||
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)).relay_limits(relaylimits))
|
||||
opts = (
|
||||
Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)).relay_limits(
|
||||
relaylimits))
|
||||
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
|
||||
keys = Keys.parse(sk.to_hex())
|
||||
signer = NostrSigner.keys(keys)
|
||||
@ -71,7 +73,7 @@ class DiscoverNonFollowers(DVMTaskInterface):
|
||||
# cli.add_relay("wss://relay.nostr.band")
|
||||
for relay in self.dvm_config.RELAY_LIST:
|
||||
await cli.add_relay(relay)
|
||||
#add nostr band, too.
|
||||
# add nostr band, too.
|
||||
ropts = RelayOptions().ping(False)
|
||||
await cli.add_relay("wss://nostr.band")
|
||||
|
||||
|
@ -2,7 +2,7 @@ import json
|
||||
import os
|
||||
from datetime import timedelta
|
||||
|
||||
from nostr_sdk import Tag, Kind, init_logger, LogLevel, Filter, Timestamp, RelayOptions, Client, NostrSigner, Keys, \
|
||||
from nostr_sdk import Tag, Kind, init_logger, LogLevel, Filter, Client, NostrSigner, Keys, \
|
||||
SecretKey, Options, SingleLetterTag, Alphabet, PublicKey
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
@ -11,7 +11,6 @@ from nostr_dvm.utils.definitions import EventDefinitions, relay_timeout_long
|
||||
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
|
||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
||||
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
||||
from nostr_dvm.utils.nostr_utils import check_and_set_private_key
|
||||
from nostr_dvm.utils.output_utils import post_process_list_to_events
|
||||
|
||||
"""
|
||||
@ -82,7 +81,8 @@ class TrendingNotesGleasonator(DVMTaskInterface):
|
||||
|
||||
ltags = ["#e", "pub.ditto.trends"]
|
||||
authors = [PublicKey.parse("db0e60d10b9555a39050c258d460c5c461f6d18f467aa9f62de1a728b8a891a4")]
|
||||
notes_filter = Filter().authors(authors).kind(Kind(1985)).custom_tag(SingleLetterTag.lowercase(Alphabet.L), ltags)
|
||||
notes_filter = Filter().authors(authors).kind(Kind(1985)).custom_tag(SingleLetterTag.lowercase(Alphabet.L),
|
||||
ltags)
|
||||
|
||||
events = await cli.get_events_of([notes_filter], relay_timeout_long)
|
||||
|
||||
@ -140,7 +140,7 @@ def build_example(name, identifier, admin_config, custom_processing_msg):
|
||||
nip89config.CONTENT = json.dumps(nip89info)
|
||||
|
||||
return TrendingNotesGleasonator(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||
admin_config=admin_config)
|
||||
admin_config=admin_config)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -1,5 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
from nostr_sdk import Tag, Kind, init_logger, LogLevel
|
||||
|
||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||
@ -81,7 +82,7 @@ class TrendingNotesNostrBand(DVMTaskInterface):
|
||||
i += 1
|
||||
if i < int(options["max_results"]):
|
||||
e_tag = Tag.parse(["e", note["id"]])
|
||||
#print(e_tag.as_vec())
|
||||
# print(e_tag.as_vec())
|
||||
result_list.append(e_tag.as_vec())
|
||||
else:
|
||||
break
|
||||
|
Loading…
x
Reference in New Issue
Block a user