mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-11-20 16:46:42 +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)
|
||||||
@@ -121,7 +118,6 @@ class DicoverContentCurrentlyPopularFollowers(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)
|
||||||
|
|
||||||
|
|
||||||
result_list = []
|
result_list = []
|
||||||
|
|
||||||
if len(followers) > 0:
|
if len(followers) > 0:
|
||||||
@@ -148,15 +144,15 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
|||||||
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]])
|
||||||
@@ -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")
|
||||||
@@ -146,7 +145,6 @@ class DicoverContentCurrentlyPopularGallery(DVMTaskInterface):
|
|||||||
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():
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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")
|
||||||
@@ -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,14 +144,14 @@ 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...')
|
||||||
@@ -170,17 +169,14 @@ class DicoverContentDBUpdateScheduler(DVMTaskInterface):
|
|||||||
# 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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user