mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-11-20 02:36:27 +01:00
and another cleanup
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
import asyncio
|
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
from datetime import timedelta
|
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, \
|
||||||
RelayOptions, RelayLimits
|
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Event, Kind, \
|
||||||
|
RelayLimits
|
||||||
|
|
||||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||||
from nostr_dvm.utils import definitions
|
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.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.output_utils import post_process_list_to_events
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This File contains a Module to discover popular notes
|
This File contains a Module to discover popular notes
|
||||||
Accepted Inputs: none
|
Accepted Inputs: none
|
||||||
@@ -69,7 +67,6 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
|||||||
user = event.author().to_hex()
|
user = event.author().to_hex()
|
||||||
max_results = 100
|
max_results = 100
|
||||||
|
|
||||||
|
|
||||||
for tag in event.tags():
|
for tag in event.tags():
|
||||||
if tag.as_vec()[0] == 'i':
|
if tag.as_vec()[0] == 'i':
|
||||||
input_type = tag.as_vec()[2]
|
input_type = tag.as_vec()[2]
|
||||||
@@ -80,8 +77,6 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
|||||||
elif param == "user": # check for param type
|
elif param == "user": # check for param type
|
||||||
user = tag.as_vec()[2]
|
user = tag.as_vec()[2]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
"max_results": max_results,
|
"max_results": max_results,
|
||||||
"user": user,
|
"user": user,
|
||||||
@@ -96,7 +91,9 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
|||||||
|
|
||||||
options = self.set_options(request_form)
|
options = self.set_options(request_form)
|
||||||
relaylimits = RelayLimits.disable()
|
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)
|
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
|
||||||
keys = Keys.parse(sk.to_hex())
|
keys = Keys.parse(sk.to_hex())
|
||||||
signer = NostrSigner.keys(keys)
|
signer = NostrSigner.keys(keys)
|
||||||
@@ -106,22 +103,21 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
|||||||
for relay in self.dvm_config.RECONCILE_DB_RELAY_LIST:
|
for relay in self.dvm_config.RECONCILE_DB_RELAY_LIST:
|
||||||
await cli.add_relay(relay)
|
await cli.add_relay(relay)
|
||||||
|
|
||||||
#ropts = RelayOptions().ping(False)
|
# ropts = RelayOptions().ping(False)
|
||||||
#cli.add_relay_with_opts("wss://nostr.band", ropts)
|
# cli.add_relay_with_opts("wss://nostr.band", ropts)
|
||||||
|
|
||||||
await cli.connect()
|
await cli.connect()
|
||||||
|
|
||||||
user = PublicKey.parse(options["user"])
|
user = PublicKey.parse(options["user"])
|
||||||
followers_filter = Filter().author(user).kinds([Kind(3)])
|
followers_filter = Filter().author(user).kinds([Kind(3)])
|
||||||
followers = await cli.get_events_of([followers_filter], relay_timeout)
|
followers = await cli.get_events_of([followers_filter], relay_timeout)
|
||||||
#print(followers)
|
# print(followers)
|
||||||
|
|
||||||
# Negentropy reconciliation
|
# Negentropy reconciliation
|
||||||
# Query events from database
|
# Query events from database
|
||||||
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
||||||
since = Timestamp.from_secs(timestamp_since)
|
since = Timestamp.from_secs(timestamp_since)
|
||||||
|
|
||||||
|
|
||||||
result_list = []
|
result_list = []
|
||||||
|
|
||||||
if len(followers) > 0:
|
if len(followers) > 0:
|
||||||
@@ -132,7 +128,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
|||||||
newest = entry.created_at().as_secs()
|
newest = entry.created_at().as_secs()
|
||||||
best_entry = entry
|
best_entry = entry
|
||||||
|
|
||||||
#print(best_entry.as_json())
|
# print(best_entry.as_json())
|
||||||
followings = []
|
followings = []
|
||||||
for tag in best_entry.tags():
|
for tag in best_entry.tags():
|
||||||
if tag.as_vec()[0] == "p":
|
if tag.as_vec()[0] == "p":
|
||||||
@@ -146,22 +142,22 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
|||||||
|
|
||||||
ns.finallist = {}
|
ns.finallist = {}
|
||||||
for event in events:
|
for event in events:
|
||||||
#if event.created_at().as_secs() > timestamp_since:
|
# if event.created_at().as_secs() > timestamp_since:
|
||||||
filt = Filter().kinds(
|
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)
|
definitions.EventDefinitions.KIND_NOTE]).event(event.id()).since(since)
|
||||||
reactions = await cli.database().query([filt])
|
reactions = await cli.database().query([filt])
|
||||||
if len(reactions) >= self.min_reactions:
|
if len(reactions) >= self.min_reactions:
|
||||||
ns.finallist[event.id().to_hex()] = len(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:
|
for entry in finallist_sorted:
|
||||||
# print(EventId.parse(entry[0]).to_bech32() + "/" + EventId.parse(entry[0]).to_hex() + ": " + str(entry[1]))
|
# print(EventId.parse(entry[0]).to_bech32() + "/" + EventId.parse(entry[0]).to_hex() + ": " + str(entry[1]))
|
||||||
e_tag = Tag.parse(["e", entry[0]])
|
e_tag = Tag.parse(["e", entry[0]])
|
||||||
result_list.append(e_tag.as_vec())
|
result_list.append(e_tag.as_vec())
|
||||||
#await cli.connect()
|
# await cli.connect()
|
||||||
await cli.shutdown()
|
await cli.shutdown()
|
||||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||||
print("[" + self.dvm_config.NIP89.NAME + "] Filtered " + str(
|
print("[" + self.dvm_config.NIP89.NAME + "] Filtered " + str(
|
||||||
@@ -192,7 +188,6 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
|||||||
self.last_schedule = Timestamp.now().as_secs()
|
self.last_schedule = Timestamp.now().as_secs()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
async def sync_db(self):
|
async def sync_db(self):
|
||||||
try:
|
try:
|
||||||
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_LONG_TIMEOUT)))
|
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,
|
# 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
|
# 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
|
# 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 = build_default_config(identifier)
|
||||||
dvm_config.USE_OWN_VENV = False
|
dvm_config.USE_OWN_VENV = False
|
||||||
dvm_config.SHOWLOG = True
|
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.UPDATE_PROFILE = False
|
||||||
# admin_config.REBROADCAST_NIP89 = 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)
|
admin_config=admin_config)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import asyncio
|
import json
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from datetime import timedelta
|
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, \
|
||||||
RelayOptions, RelayLimits
|
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, EventId, Kind, \
|
||||||
|
RelayLimits
|
||||||
|
|
||||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||||
from nostr_dvm.utils import definitions
|
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.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.output_utils import post_process_list_to_events
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This File contains a Module to discover popular notes
|
This File contains a Module to discover popular notes
|
||||||
Accepted Inputs: none
|
Accepted Inputs: none
|
||||||
@@ -119,7 +119,6 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
|||||||
|
|
||||||
filter1 = Filter().kind(definitions.EventDefinitions.KIND_NIP93_GALLERYENTRY).since(since)
|
filter1 = Filter().kind(definitions.EventDefinitions.KIND_NIP93_GALLERYENTRY).since(since)
|
||||||
|
|
||||||
|
|
||||||
ge_events = await databasegallery.query([filter1])
|
ge_events = await databasegallery.query([filter1])
|
||||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||||
print("[" + self.dvm_config.NIP89.NAME + "] Considering " + str(len(ge_events)) + " Events")
|
print("[" + self.dvm_config.NIP89.NAME + "] Considering " + str(len(ge_events)) + " Events")
|
||||||
@@ -129,7 +128,7 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
|||||||
relays = []
|
relays = []
|
||||||
|
|
||||||
if len(ge_events) == 0:
|
if len(ge_events) == 0:
|
||||||
return[]
|
return []
|
||||||
|
|
||||||
for ge_event in ge_events:
|
for ge_event in ge_events:
|
||||||
|
|
||||||
@@ -138,15 +137,14 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
|||||||
if tag.as_vec()[0] == "e":
|
if tag.as_vec()[0] == "e":
|
||||||
id = EventId.from_hex(tag.as_vec()[1])
|
id = EventId.from_hex(tag.as_vec()[1])
|
||||||
ids.append(id)
|
ids.append(id)
|
||||||
#if len(tag.as_vec()) > 2:
|
# if len(tag.as_vec()) > 2:
|
||||||
#if (tag.as_vec()[2]) not in relays:
|
# if (tag.as_vec()[2]) not in relays:
|
||||||
# relays.append(tag.as_vec()[2])
|
# relays.append(tag.as_vec()[2])
|
||||||
|
|
||||||
if id is None:
|
if id is None:
|
||||||
print("No event id found")
|
print("No event id found")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
relaylimits = RelayLimits.disable()
|
relaylimits = RelayLimits.disable()
|
||||||
opts = (Options().wait_for_send(True).send_timeout(
|
opts = (Options().wait_for_send(True).send_timeout(
|
||||||
timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)).relay_limits(relaylimits))
|
timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)).relay_limits(relaylimits))
|
||||||
@@ -164,19 +162,18 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
|||||||
await cli.connect()
|
await cli.connect()
|
||||||
|
|
||||||
filtreactions = Filter().kinds([definitions.EventDefinitions.KIND_ZAP, definitions.EventDefinitions.KIND_REPOST,
|
filtreactions = Filter().kinds([definitions.EventDefinitions.KIND_ZAP, definitions.EventDefinitions.KIND_REPOST,
|
||||||
definitions.EventDefinitions.KIND_REACTION, definitions.EventDefinitions.KIND_DELETION,
|
definitions.EventDefinitions.KIND_REACTION,
|
||||||
|
definitions.EventDefinitions.KIND_DELETION,
|
||||||
definitions.EventDefinitions.KIND_NOTE]).events(ids).since(since)
|
definitions.EventDefinitions.KIND_NOTE]).events(ids).since(since)
|
||||||
|
|
||||||
dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN)
|
dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN)
|
||||||
await cli.reconcile(filtreactions, dbopts)
|
await cli.reconcile(filtreactions, dbopts)
|
||||||
|
|
||||||
|
|
||||||
filter2 = Filter().ids(ids)
|
filter2 = Filter().ids(ids)
|
||||||
events = await cli.get_events_of([filter2], relay_timeout)
|
events = await cli.get_events_of([filter2], relay_timeout)
|
||||||
|
|
||||||
print(len(events))
|
print(len(events))
|
||||||
|
|
||||||
|
|
||||||
for event in events:
|
for event in events:
|
||||||
if event.created_at().as_secs() > timestamp_since:
|
if event.created_at().as_secs() > timestamp_since:
|
||||||
filt1 = Filter().kinds([definitions.EventDefinitions.KIND_DELETION]).event(event.id()).limit(1)
|
filt1 = Filter().kinds([definitions.EventDefinitions.KIND_DELETION]).event(event.id()).limit(1)
|
||||||
@@ -185,8 +182,6 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
|||||||
print("Deleted event, skipping")
|
print("Deleted event, skipping")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
filt = Filter().kinds([definitions.EventDefinitions.KIND_ZAP, definitions.EventDefinitions.KIND_REPOST,
|
filt = Filter().kinds([definitions.EventDefinitions.KIND_ZAP, definitions.EventDefinitions.KIND_REPOST,
|
||||||
definitions.EventDefinitions.KIND_REACTION,
|
definitions.EventDefinitions.KIND_REACTION,
|
||||||
definitions.EventDefinitions.KIND_NOTE]).event(event.id()).since(since)
|
definitions.EventDefinitions.KIND_NOTE]).event(event.id()).since(since)
|
||||||
@@ -219,7 +214,6 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
|||||||
# await cli.shutdown()
|
# await cli.shutdown()
|
||||||
return json.dumps(result_list)
|
return json.dumps(result_list)
|
||||||
|
|
||||||
|
|
||||||
async def post_process(self, result, event):
|
async def post_process(self, result, event):
|
||||||
"""Overwrite the interface function to return a social client readable format, if requested"""
|
"""Overwrite the interface function to return a social client readable format, if requested"""
|
||||||
for tag in event.tags():
|
for tag in event.tags():
|
||||||
@@ -261,7 +255,8 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
|||||||
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
||||||
since = Timestamp.from_secs(timestamp_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())
|
# filter = Filter().author(keys.public_key())
|
||||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||||
@@ -274,7 +269,8 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
|||||||
await cli.shutdown()
|
await cli.shutdown()
|
||||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||||
print(
|
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:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import asyncio
|
import json
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from datetime import timedelta
|
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, \
|
||||||
RelayOptions
|
ClientBuilder, Filter, init_logger, LogLevel, Kind
|
||||||
|
|
||||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||||
from nostr_dvm.utils import definitions
|
from nostr_dvm.utils import definitions
|
||||||
@@ -106,7 +106,6 @@ class DicoverContentCurrentlyPopularMostr(DVMTaskInterface):
|
|||||||
from nostr_sdk import Filter
|
from nostr_sdk import Filter
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
|
|
||||||
|
|
||||||
ns = SimpleNamespace()
|
ns = SimpleNamespace()
|
||||||
options = self.set_options(request_form)
|
options = self.set_options(request_form)
|
||||||
|
|
||||||
@@ -116,7 +115,6 @@ class DicoverContentCurrentlyPopularMostr(DVMTaskInterface):
|
|||||||
keys = Keys.parse(sk.to_hex())
|
keys = Keys.parse(sk.to_hex())
|
||||||
signer = NostrSigner.keys(keys)
|
signer = NostrSigner.keys(keys)
|
||||||
|
|
||||||
|
|
||||||
database = NostrDatabase.lmdb(self.db_name)
|
database = NostrDatabase.lmdb(self.db_name)
|
||||||
try:
|
try:
|
||||||
await database.delete(Filter().until(Timestamp.from_secs(
|
await database.delete(Filter().until(Timestamp.from_secs(
|
||||||
@@ -125,7 +123,6 @@ class DicoverContentCurrentlyPopularMostr(DVMTaskInterface):
|
|||||||
print(e)
|
print(e)
|
||||||
cli = ClientBuilder().signer(signer).database(database).opts(opts).build()
|
cli = ClientBuilder().signer(signer).database(database).opts(opts).build()
|
||||||
|
|
||||||
|
|
||||||
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
||||||
since = Timestamp.from_secs(timestamp_since)
|
since = Timestamp.from_secs(timestamp_since)
|
||||||
|
|
||||||
@@ -162,7 +159,6 @@ class DicoverContentCurrentlyPopularMostr(DVMTaskInterface):
|
|||||||
# await cli.shutdown()
|
# await cli.shutdown()
|
||||||
return json.dumps(result_list)
|
return json.dumps(result_list)
|
||||||
|
|
||||||
|
|
||||||
async def post_process(self, result, event):
|
async def post_process(self, result, event):
|
||||||
"""Overwrite the interface function to return a social client readable format, if requested"""
|
"""Overwrite the interface function to return a social client readable format, if requested"""
|
||||||
for tag in event.tags():
|
for tag in event.tags():
|
||||||
@@ -220,10 +216,10 @@ class DicoverContentCurrentlyPopularMostr(DVMTaskInterface):
|
|||||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||||
print("[" + self.dvm_config.NIP89.NAME + "] Syncing notes of the last " + str(
|
print("[" + self.dvm_config.NIP89.NAME + "] Syncing notes of the last " + str(
|
||||||
self.db_since) + " seconds.. this might take a while..")
|
self.db_since) + " seconds.. this might take a while..")
|
||||||
#dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN)
|
# dbopts = NegentropyOptions().direction(NegentropyDirection.DOWN)
|
||||||
#await cli.reconcile(filter1, dbopts)
|
# await cli.reconcile(filter1, dbopts)
|
||||||
#await cli.reconcile(filter2, dbopts)
|
# await cli.reconcile(filter2, dbopts)
|
||||||
#await cli.reconcile(filter3, dbopts)
|
# await cli.reconcile(filter3, dbopts)
|
||||||
|
|
||||||
# RECONCOILE NOT POSSIBLE ON THESE RELAYS SO WE FETCH AB BUNCH (will be stored in db)
|
# RECONCOILE NOT POSSIBLE ON THESE RELAYS SO WE FETCH AB BUNCH (will be stored in db)
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import asyncio
|
import json
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from datetime import timedelta
|
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
|
RelayLimits
|
||||||
|
|
||||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||||
@@ -167,7 +168,7 @@ class DicoverContentCurrentlyPopularNonFollowers(DVMTaskInterface):
|
|||||||
newest = entry.created_at().as_secs()
|
newest = entry.created_at().as_secs()
|
||||||
best_entry = entry
|
best_entry = entry
|
||||||
|
|
||||||
#print(best_entry.as_json())
|
# print(best_entry.as_json())
|
||||||
followings = []
|
followings = []
|
||||||
for tag in best_entry.tags():
|
for tag in best_entry.tags():
|
||||||
if tag.as_vec()[0] == "p":
|
if tag.as_vec()[0] == "p":
|
||||||
@@ -211,7 +212,7 @@ class DicoverContentCurrentlyPopularNonFollowers(DVMTaskInterface):
|
|||||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||||
print("[" + self.dvm_config.NIP89.NAME + "] Filtered " + str(
|
print("[" + self.dvm_config.NIP89.NAME + "] Filtered " + str(
|
||||||
len(result_list)) + " fitting events.")
|
len(result_list)) + " fitting events.")
|
||||||
#await cli.shutdown()
|
# await cli.shutdown()
|
||||||
return json.dumps(result_list)
|
return json.dumps(result_list)
|
||||||
|
|
||||||
async def schedule(self, dvm_config):
|
async def schedule(self, dvm_config):
|
||||||
@@ -241,7 +242,8 @@ class DicoverContentCurrentlyPopularNonFollowers(DVMTaskInterface):
|
|||||||
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
||||||
since = Timestamp.from_secs(timestamp_since)
|
since = Timestamp.from_secs(timestamp_since)
|
||||||
|
|
||||||
filter1 = Filter().kinds([definitions.EventDefinitions.KIND_NOTE, definitions.EventDefinitions.KIND_REACTION,
|
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())
|
# filter = Filter().author(keys.public_key())
|
||||||
@@ -255,7 +257,8 @@ class DicoverContentCurrentlyPopularNonFollowers(DVMTaskInterface):
|
|||||||
await cli.shutdown()
|
await cli.shutdown()
|
||||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||||
print(
|
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:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import asyncio
|
import json
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from datetime import timedelta
|
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.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||||
from nostr_dvm.utils import definitions
|
from nostr_dvm.utils import definitions
|
||||||
@@ -39,7 +40,6 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
|||||||
result = ""
|
result = ""
|
||||||
database = None
|
database = None
|
||||||
|
|
||||||
|
|
||||||
async def init_dvm(self, name, dvm_config: DVMConfig, nip89config: NIP89Config, nip88config: NIP88Config = None,
|
async def init_dvm(self, name, dvm_config: DVMConfig, nip89config: NIP89Config, nip88config: NIP88Config = None,
|
||||||
admin_config: AdminConfig = None, options=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)
|
filter = Filter().kind(definitions.EventDefinitions.KIND_NOTE).since(since).search(word)
|
||||||
filters.append(filter)
|
filters.append(filter)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
events = await self.database.query(filters)
|
events = await self.database.query(filters)
|
||||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||||
print("[" + self.dvm_config.NIP89.NAME + "] Considering " + str(len(events)) + " Events")
|
print("[" + self.dvm_config.NIP89.NAME + "] Considering " + str(len(events)) + " Events")
|
||||||
@@ -168,7 +166,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
|||||||
|
|
||||||
for event in events:
|
for event in events:
|
||||||
if all(ele in event.content().lower() for ele in self.must_list):
|
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):
|
if not any(ele in event.content().lower() for ele in self.avoid_list):
|
||||||
filt = Filter().kinds(
|
filt = Filter().kinds(
|
||||||
[definitions.EventDefinitions.KIND_ZAP, definitions.EventDefinitions.KIND_REACTION,
|
[definitions.EventDefinitions.KIND_ZAP, definitions.EventDefinitions.KIND_REACTION,
|
||||||
@@ -187,7 +185,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
|||||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||||
print("[" + self.dvm_config.NIP89.NAME + "] Filtered " + str(
|
print("[" + self.dvm_config.NIP89.NAME + "] Filtered " + str(
|
||||||
len(result_list)) + " fitting events.")
|
len(result_list)) + " fitting events.")
|
||||||
#await cli.shutdown()
|
# await cli.shutdown()
|
||||||
return json.dumps(result_list)
|
return json.dumps(result_list)
|
||||||
|
|
||||||
async def schedule(self, dvm_config):
|
async def schedule(self, dvm_config):
|
||||||
@@ -219,7 +217,8 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
|||||||
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
||||||
since = Timestamp.from_secs(timestamp_since)
|
since = Timestamp.from_secs(timestamp_since)
|
||||||
|
|
||||||
filter1 = Filter().kinds([definitions.EventDefinitions.KIND_NOTE, definitions.EventDefinitions.KIND_REACTION,
|
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())
|
# filter = Filter().author(keys.public_key())
|
||||||
@@ -232,11 +231,13 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
|||||||
Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesn't get too full.
|
Timestamp.now().as_secs() - self.db_since))) # Clear old events so db doesn't get too full.
|
||||||
await cli.shutdown()
|
await cli.shutdown()
|
||||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
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:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
# We build an example here that we can call by either calling this file directly from the main directory,
|
# 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
|
# 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
|
# playground or elsewhere
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
import asyncio
|
import json
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from itertools import islice
|
from itertools import islice
|
||||||
|
|
||||||
import networkx as nx
|
from nostr_sdk import Timestamp, PublicKey, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
||||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
|
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Kind, \
|
||||||
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Event, EventId, Kind, \
|
|
||||||
RelayLimits, RelayFilteringMode
|
RelayLimits, RelayFilteringMode
|
||||||
|
|
||||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
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.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.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.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
|
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):
|
async def sync_db(self):
|
||||||
try:
|
try:
|
||||||
relaylimits = RelayLimits.disable()
|
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:
|
if self.dvm_config.WOT_FILTERING:
|
||||||
opts = opts.filtering_mode(RelayFilteringMode.WHITELIST)
|
opts = opts.filtering_mode(RelayFilteringMode.WHITELIST)
|
||||||
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
|
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:
|
for relay in self.dvm_config.RECONCILE_DB_RELAY_LIST:
|
||||||
await cli.add_relay(relay)
|
await cli.add_relay(relay)
|
||||||
|
|
||||||
|
|
||||||
await cli.connect()
|
await cli.connect()
|
||||||
|
|
||||||
|
|
||||||
if self.dvm_config.WOT_FILTERING:
|
if self.dvm_config.WOT_FILTERING:
|
||||||
print("Calculating WOT for " + str(self.dvm_config.WOT_BASED_ON_NPUBS))
|
print("Calculating WOT for " + str(self.dvm_config.WOT_BASED_ON_NPUBS))
|
||||||
filtering = cli.filtering()
|
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?
|
# Do we actually need pagerank here?
|
||||||
#print('computing global pagerank...')
|
# print('computing global pagerank...')
|
||||||
#tic = time.time()
|
# tic = time.time()
|
||||||
#p_G = nx.pagerank(G, tol=1e-12)
|
# p_G = nx.pagerank(G, tol=1e-12)
|
||||||
# print("network after pagerank: " + str(len(p_G)))
|
# print("network after pagerank: " + str(len(p_G)))
|
||||||
|
|
||||||
wot_keys = []
|
wot_keys = []
|
||||||
@@ -166,21 +165,18 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface):
|
|||||||
None)
|
None)
|
||||||
wot_keys.append(key)
|
wot_keys.append(key)
|
||||||
|
|
||||||
#toc = time.time()
|
# toc = time.time()
|
||||||
#print(f'finished in {toc - tic} seconds')
|
# print(f'finished in {toc - tic} seconds')
|
||||||
await filtering.add_public_keys(wot_keys)
|
await filtering.add_public_keys(wot_keys)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Mute public key
|
# Mute public key
|
||||||
#await cli. (self.dvm_config.MUTE)
|
# await cli. (self.dvm_config.MUTE)
|
||||||
|
|
||||||
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
||||||
since = Timestamp.from_secs(timestamp_since)
|
since = Timestamp.from_secs(timestamp_since)
|
||||||
|
|
||||||
filter1 = Filter().kinds([definitions.EventDefinitions.KIND_NOTE, definitions.EventDefinitions.KIND_REACTION,
|
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())
|
# filter = Filter().author(keys.public_key())
|
||||||
@@ -194,10 +190,12 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface):
|
|||||||
await cli.shutdown()
|
await cli.shutdown()
|
||||||
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
|
||||||
print(
|
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:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
# We build an example here that we can call by either calling this file directly from the main directory,
|
# 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
|
# 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
|
# playground or elsewhere
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from datetime import timedelta
|
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, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind, RelayLimits
|
||||||
RelayLimits, Event
|
|
||||||
|
|
||||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||||
from nostr_dvm.utils.admin_utils import AdminConfig
|
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 we don't add users, e.g. by a wot, we check all our followers.
|
||||||
if len(pubkeys) == 0:
|
if len(pubkeys) == 0:
|
||||||
followers_filter = Filter().author(PublicKey.parse(options["sender"])).kind(Kind(3))
|
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:
|
if len(followers) > 0:
|
||||||
result_list = []
|
result_list = []
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import os
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from threading import Thread
|
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
|
RelayLimits
|
||||||
|
|
||||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||||
@@ -63,7 +63,9 @@ class DiscoverNonFollowers(DVMTaskInterface):
|
|||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
ns = SimpleNamespace()
|
ns = SimpleNamespace()
|
||||||
relaylimits = RelayLimits.disable()
|
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)
|
sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
|
||||||
keys = Keys.parse(sk.to_hex())
|
keys = Keys.parse(sk.to_hex())
|
||||||
signer = NostrSigner.keys(keys)
|
signer = NostrSigner.keys(keys)
|
||||||
@@ -71,7 +73,7 @@ class DiscoverNonFollowers(DVMTaskInterface):
|
|||||||
# cli.add_relay("wss://relay.nostr.band")
|
# cli.add_relay("wss://relay.nostr.band")
|
||||||
for relay in self.dvm_config.RELAY_LIST:
|
for relay in self.dvm_config.RELAY_LIST:
|
||||||
await cli.add_relay(relay)
|
await cli.add_relay(relay)
|
||||||
#add nostr band, too.
|
# add nostr band, too.
|
||||||
ropts = RelayOptions().ping(False)
|
ropts = RelayOptions().ping(False)
|
||||||
await cli.add_relay("wss://nostr.band")
|
await cli.add_relay("wss://nostr.band")
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
from datetime import timedelta
|
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
|
SecretKey, Options, SingleLetterTag, Alphabet, PublicKey
|
||||||
|
|
||||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
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.dvmconfig import DVMConfig, build_default_config
|
||||||
from nostr_dvm.utils.nip88_utils import NIP88Config
|
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.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
|
from nostr_dvm.utils.output_utils import post_process_list_to_events
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -82,7 +81,8 @@ class TrendingNotesGleasonator(DVMTaskInterface):
|
|||||||
|
|
||||||
ltags = ["#e", "pub.ditto.trends"]
|
ltags = ["#e", "pub.ditto.trends"]
|
||||||
authors = [PublicKey.parse("db0e60d10b9555a39050c258d460c5c461f6d18f467aa9f62de1a728b8a891a4")]
|
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)
|
events = await cli.get_events_of([notes_filter], relay_timeout_long)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from nostr_sdk import Tag, Kind, init_logger, LogLevel
|
from nostr_sdk import Tag, Kind, init_logger, LogLevel
|
||||||
|
|
||||||
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
|
||||||
@@ -81,7 +82,7 @@ class TrendingNotesNostrBand(DVMTaskInterface):
|
|||||||
i += 1
|
i += 1
|
||||||
if i < int(options["max_results"]):
|
if i < int(options["max_results"]):
|
||||||
e_tag = Tag.parse(["e", note["id"]])
|
e_tag = Tag.parse(["e", note["id"]])
|
||||||
#print(e_tag.as_vec())
|
# print(e_tag.as_vec())
|
||||||
result_list.append(e_tag.as_vec())
|
result_list.append(e_tag.as_vec())
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user