mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-11-19 00:46:41 +01:00
use a shared db for content dvms
This commit is contained in:
@@ -47,11 +47,19 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
|||||||
|
|
||||||
self.last_schedule = Timestamp.now().as_secs()
|
self.last_schedule = Timestamp.now().as_secs()
|
||||||
|
|
||||||
|
if self.options.get("db_name"):
|
||||||
|
self.db_name = self.options.get("db_name")
|
||||||
|
if self.options.get("db_since"):
|
||||||
|
self.db_since = int(self.options.get("db_since"))
|
||||||
|
|
||||||
|
|
||||||
use_logger = False
|
use_logger = False
|
||||||
if use_logger:
|
if use_logger:
|
||||||
init_logger(LogLevel.DEBUG)
|
init_logger(LogLevel.DEBUG)
|
||||||
|
|
||||||
self.sync_db()
|
if self.dvm_config.UPDATE_DATABASE:
|
||||||
|
self.sync_db()
|
||||||
|
|
||||||
if not self.personalized:
|
if not self.personalized:
|
||||||
self.result = self.calculate_result(self.request_form)
|
self.result = self.calculate_result(self.request_form)
|
||||||
|
|
||||||
@@ -117,16 +125,16 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
|||||||
# Negentropy reconciliation
|
# Negentropy reconciliation
|
||||||
# Query events from database
|
# Query events from database
|
||||||
timestamp_hour_ago = Timestamp.now().as_secs() - self.db_since
|
timestamp_hour_ago = Timestamp.now().as_secs() - self.db_since
|
||||||
lasthour = Timestamp.from_secs(timestamp_hour_ago)
|
since = Timestamp.from_secs(timestamp_hour_ago)
|
||||||
|
|
||||||
filter1 = Filter().kind(definitions.EventDefinitions.KIND_NOTE).since(lasthour)
|
filter1 = Filter().kind(definitions.EventDefinitions.KIND_NOTE).since(since)
|
||||||
events = cli.database().query([filter1])
|
events = cli.database().query([filter1])
|
||||||
ns.finallist = {}
|
ns.finallist = {}
|
||||||
for event in events:
|
for event in events:
|
||||||
if event.created_at().as_secs() > timestamp_hour_ago:
|
if event.created_at().as_secs() > timestamp_hour_ago:
|
||||||
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(lasthour)
|
definitions.EventDefinitions.KIND_NOTE]).event(event.id()).since(since)
|
||||||
reactions = cli.database().query([filt])
|
reactions = 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)
|
||||||
@@ -156,7 +164,8 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
|||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
if Timestamp.now().as_secs() >= self.last_schedule + dvm_config.SCHEDULE_UPDATES_SECONDS:
|
if Timestamp.now().as_secs() >= self.last_schedule + dvm_config.SCHEDULE_UPDATES_SECONDS:
|
||||||
self.sync_db()
|
if self.dvm_config.UPDATE_DATABASE:
|
||||||
|
self.sync_db()
|
||||||
self.last_schedule = Timestamp.now().as_secs()
|
self.last_schedule = Timestamp.now().as_secs()
|
||||||
self.result = self.calculate_result(self.request_form)
|
self.result = self.calculate_result(self.request_form)
|
||||||
return 1
|
return 1
|
||||||
@@ -193,11 +202,12 @@ class DicoverContentCurrentlyPopular(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, processing_msg=None):
|
def build_example(name, identifier, admin_config, options, 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
|
||||||
dvm_config.SCHEDULE_UPDATES_SECONDS = 600 # Every 10 minutes
|
dvm_config.SCHEDULE_UPDATES_SECONDS = 600 # Every 10 minutes
|
||||||
|
dvm_config.UPDATE_DATABASE = update_db
|
||||||
# Activate these to use a subscription based model instead
|
# Activate these to use a subscription based model instead
|
||||||
# dvm_config.SUBSCRIPTION_REQUIRED = True
|
# dvm_config.SUBSCRIPTION_REQUIRED = True
|
||||||
# dvm_config.SUBSCRIPTION_DAILY_COST = 1
|
# dvm_config.SUBSCRIPTION_DAILY_COST = 1
|
||||||
@@ -234,14 +244,15 @@ def build_example(name, identifier, admin_config, processing_msg=None):
|
|||||||
#admin_config.REBROADCAST_NIP89 = False
|
#admin_config.REBROADCAST_NIP89 = False
|
||||||
|
|
||||||
return DicoverContentCurrentlyPopular(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
return DicoverContentCurrentlyPopular(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||||
admin_config=admin_config)
|
admin_config=admin_config, options=options)
|
||||||
|
|
||||||
|
|
||||||
def build_example_subscription(name, identifier, admin_config, processing_msg=None):
|
def build_example_subscription(name, identifier, admin_config, options, 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
|
||||||
dvm_config.SCHEDULE_UPDATES_SECONDS = 600 # Every 10 minutes
|
dvm_config.SCHEDULE_UPDATES_SECONDS = 180 # Every 3 minutes
|
||||||
|
dvm_config.UPDATE_DATABASE = update_db
|
||||||
# Activate these to use a subscription based model instead
|
# Activate these to use a subscription based model instead
|
||||||
# dvm_config.SUBSCRIPTION_DAILY_COST = 1
|
# dvm_config.SUBSCRIPTION_DAILY_COST = 1
|
||||||
dvm_config.FIX_COST = 0
|
dvm_config.FIX_COST = 0
|
||||||
@@ -295,7 +306,7 @@ def build_example_subscription(name, identifier, admin_config, processing_msg=No
|
|||||||
# admin_config.PRIVKEY = dvm_config.PRIVATE_KEY
|
# admin_config.PRIVKEY = dvm_config.PRIVATE_KEY
|
||||||
|
|
||||||
return DicoverContentCurrentlyPopular(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
return DicoverContentCurrentlyPopular(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||||
nip88config=nip88config,
|
nip88config=nip88config, options=options,
|
||||||
admin_config=admin_config)
|
admin_config=admin_config)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,11 +40,17 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
|||||||
|
|
||||||
self.last_schedule = Timestamp.now().as_secs()
|
self.last_schedule = Timestamp.now().as_secs()
|
||||||
|
|
||||||
|
if self.options.get("db_name"):
|
||||||
|
self.db_name = self.options.get("db_name")
|
||||||
|
if self.options.get("db_since"):
|
||||||
|
self.db_since = int(self.options.get("db_since"))
|
||||||
|
|
||||||
use_logger = False
|
use_logger = False
|
||||||
if use_logger:
|
if use_logger:
|
||||||
init_logger(LogLevel.DEBUG)
|
init_logger(LogLevel.DEBUG)
|
||||||
|
|
||||||
self.sync_db()
|
if self.dvm_config.UPDATE_DATABASE:
|
||||||
|
self.sync_db()
|
||||||
|
|
||||||
def is_input_supported(self, tags, client=None, dvm_config=None):
|
def is_input_supported(self, tags, client=None, dvm_config=None):
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
@@ -101,7 +107,7 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
|||||||
cli = ClientBuilder().database(database).signer(signer).opts(opts).build()
|
cli = ClientBuilder().database(database).signer(signer).opts(opts).build()
|
||||||
cli.add_relay("wss://relay.damus.io")
|
cli.add_relay("wss://relay.damus.io")
|
||||||
cli.add_relay("wss://nos.lol")
|
cli.add_relay("wss://nos.lol")
|
||||||
cli.add_relay("wss://pablof7z.nostr1.com")
|
cli.add_relay("wss://nostr.mom")
|
||||||
|
|
||||||
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)
|
||||||
@@ -115,8 +121,8 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
|||||||
|
|
||||||
# Negentropy reconciliation
|
# Negentropy reconciliation
|
||||||
# Query events from database
|
# Query events from database
|
||||||
timestamp_hour_ago = Timestamp.now().as_secs() - self.db_since
|
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
||||||
lasthour = Timestamp.from_secs(timestamp_hour_ago)
|
since = Timestamp.from_secs(timestamp_since)
|
||||||
|
|
||||||
|
|
||||||
result_list = []
|
result_list = []
|
||||||
@@ -136,18 +142,18 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
|||||||
following = PublicKey.parse(tag.as_vec()[1])
|
following = PublicKey.parse(tag.as_vec()[1])
|
||||||
followings.append(following)
|
followings.append(following)
|
||||||
|
|
||||||
filter1 = Filter().kind(definitions.EventDefinitions.KIND_NOTE).authors(followings).since(lasthour)
|
filter1 = Filter().kind(definitions.EventDefinitions.KIND_NOTE).authors(followings).since(since)
|
||||||
events = cli.database().query([filter1])
|
events = cli.database().query([filter1])
|
||||||
|
|
||||||
ns.finallist = {}
|
ns.finallist = {}
|
||||||
for event in events:
|
for event in events:
|
||||||
if event.created_at().as_secs() > timestamp_hour_ago:
|
#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(lasthour)
|
definitions.EventDefinitions.KIND_NOTE]).event(event.id()).since(since)
|
||||||
reactions = cli.database().query([filt])
|
reactions = 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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -177,7 +183,8 @@ class DicoverContentCurrentlyPopularFollowers(DVMTaskInterface):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
if Timestamp.now().as_secs() >= self.last_schedule + dvm_config.SCHEDULE_UPDATES_SECONDS:
|
if Timestamp.now().as_secs() >= self.last_schedule + dvm_config.SCHEDULE_UPDATES_SECONDS:
|
||||||
self.sync_db()
|
if self.dvm_config.UPDATE_DATABASE:
|
||||||
|
self.sync_db()
|
||||||
self.last_schedule = Timestamp.now().as_secs()
|
self.last_schedule = Timestamp.now().as_secs()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@@ -211,11 +218,12 @@ 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, processing_msg=None):
|
def build_example(name, identifier, admin_config, options, 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
|
||||||
dvm_config.SCHEDULE_UPDATES_SECONDS = 600 # Every 10 minutes
|
dvm_config.SCHEDULE_UPDATES_SECONDS = 600 # Every 10 minutes
|
||||||
|
dvm_config.UPDATE_DATABASE = update_db
|
||||||
# Activate these to use a subscription based model instead
|
# Activate these to use a subscription based model instead
|
||||||
# dvm_config.SUBSCRIPTION_REQUIRED = True
|
# dvm_config.SUBSCRIPTION_REQUIRED = True
|
||||||
# dvm_config.SUBSCRIPTION_DAILY_COST = 1
|
# dvm_config.SUBSCRIPTION_DAILY_COST = 1
|
||||||
@@ -250,15 +258,16 @@ def build_example(name, identifier, admin_config, processing_msg=None):
|
|||||||
# 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,
|
return DicoverContentCurrentlyPopularFollowers(name=name, dvm_config=dvm_config, nip89config=nip89config, options=options,
|
||||||
admin_config=admin_config)
|
admin_config=admin_config)
|
||||||
|
|
||||||
|
|
||||||
def build_example_subscription(name, identifier, admin_config, processing_msg=None):
|
def build_example_subscription(name, identifier, admin_config, options, 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
|
||||||
dvm_config.SCHEDULE_UPDATES_SECONDS = 600 # Every 10 minutes
|
dvm_config.SCHEDULE_UPDATES_SECONDS = 180 # Every 3 minutes
|
||||||
|
dvm_config.UPDATE_DATABASE = update_db
|
||||||
# Activate these to use a subscription based model instead
|
# Activate these to use a subscription based model instead
|
||||||
# dvm_config.SUBSCRIPTION_DAILY_COST = 1
|
# dvm_config.SUBSCRIPTION_DAILY_COST = 1
|
||||||
dvm_config.FIX_COST = 0
|
dvm_config.FIX_COST = 0
|
||||||
@@ -305,7 +314,7 @@ def build_example_subscription(name, identifier, admin_config, processing_msg=No
|
|||||||
# admin_config.PRIVKEY = dvm_config.PRIVATE_KEY
|
# admin_config.PRIVKEY = dvm_config.PRIVATE_KEY
|
||||||
|
|
||||||
return DicoverContentCurrentlyPopularFollowers(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
return DicoverContentCurrentlyPopularFollowers(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||||
nip88config=nip88config,
|
nip88config=nip88config, options=options,
|
||||||
admin_config=admin_config)
|
admin_config=admin_config)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,8 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
|||||||
if use_logger:
|
if use_logger:
|
||||||
init_logger(LogLevel.DEBUG)
|
init_logger(LogLevel.DEBUG)
|
||||||
|
|
||||||
self.sync_db()
|
if self.dvm_config.UPDATE_DATABASE:
|
||||||
|
self.sync_db()
|
||||||
if not self.personalized:
|
if not self.personalized:
|
||||||
self.result = self.calculate_result(self.request_form)
|
self.result = self.calculate_result(self.request_form)
|
||||||
|
|
||||||
@@ -149,8 +150,10 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
|||||||
|
|
||||||
# Negentropy reconciliation
|
# Negentropy reconciliation
|
||||||
# Query events from database
|
# Query events from database
|
||||||
|
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
||||||
|
since = Timestamp.from_secs(timestamp_since)
|
||||||
|
|
||||||
filter1 = Filter().kind(definitions.EventDefinitions.KIND_NOTE)
|
filter1 = Filter().kind(definitions.EventDefinitions.KIND_NOTE).since(since)
|
||||||
|
|
||||||
events = cli.database().query([filter1])
|
events = cli.database().query([filter1])
|
||||||
print(len(events))
|
print(len(events))
|
||||||
@@ -160,10 +163,11 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
|||||||
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,
|
||||||
definitions.EventDefinitions.KIND_REPOST,
|
definitions.EventDefinitions.KIND_REPOST,
|
||||||
definitions.EventDefinitions.KIND_NOTE]).event(event.id())
|
definitions.EventDefinitions.KIND_NOTE]).event(event.id()).since(since)
|
||||||
reactions = cli.database().query([filt])
|
reactions = 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)
|
||||||
@@ -183,7 +187,8 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
|||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
if Timestamp.now().as_secs() >= self.last_schedule + dvm_config.SCHEDULE_UPDATES_SECONDS:
|
if Timestamp.now().as_secs() >= self.last_schedule + dvm_config.SCHEDULE_UPDATES_SECONDS:
|
||||||
self.sync_db()
|
if self.dvm_config.UPDATE_DATABASE:
|
||||||
|
self.sync_db()
|
||||||
self.last_schedule = Timestamp.now().as_secs()
|
self.last_schedule = Timestamp.now().as_secs()
|
||||||
self.result = self.calculate_result(self.request_form)
|
self.result = self.calculate_result(self.request_form)
|
||||||
#print(self.result)
|
#print(self.result)
|
||||||
@@ -198,12 +203,22 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
|||||||
cli = ClientBuilder().signer(signer).database(database).opts(opts).build()
|
cli = ClientBuilder().signer(signer).database(database).opts(opts).build()
|
||||||
|
|
||||||
cli.add_relay("wss://relay.damus.io")
|
cli.add_relay("wss://relay.damus.io")
|
||||||
|
cli.add_relay("wss://nostr.oxtr.dev")
|
||||||
|
cli.add_relay("wss://relay.nostr.net")
|
||||||
|
cli.add_relay("wss://relay.nostr.bg")
|
||||||
|
cli.add_relay("wss://nostr.wine")
|
||||||
|
cli.add_relay("wss://nostr21.com")
|
||||||
|
|
||||||
|
#RELAY_LIST = [ "wss://nostr.wine",
|
||||||
|
# , "wss://relay.nostr.bg",
|
||||||
|
# , "wss://relay.nostr.net"
|
||||||
|
# ]
|
||||||
cli.connect()
|
cli.connect()
|
||||||
|
|
||||||
timestamp_hour_ago = Timestamp.now().as_secs() - self.db_since
|
timestamp_since = Timestamp.now().as_secs() - self.db_since
|
||||||
lasthour = Timestamp.from_secs(timestamp_hour_ago)
|
since = Timestamp.from_secs(timestamp_since)
|
||||||
|
|
||||||
filter1 = Filter().kinds([definitions.EventDefinitions.KIND_NOTE, definitions.EventDefinitions.KIND_REACTION, definitions.EventDefinitions.KIND_ZAP]).since(lasthour) # 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())
|
# filter = Filter().author(keys.public_key())
|
||||||
print("[" + self.dvm_config.IDENTIFIER + "] Syncing notes of the last " + str(self.db_since) + " seconds.. this might take a while..")
|
print("[" + self.dvm_config.IDENTIFIER + "] Syncing notes of the last " + str(self.db_since) + " seconds.. this might take a while..")
|
||||||
@@ -218,11 +233,12 @@ class DicoverContentCurrentlyPopularbyTopic(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, image, description, processing_msg=None):
|
def build_example(name, identifier, admin_config, options, image, description, 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
|
||||||
dvm_config.SCHEDULE_UPDATES_SECONDS = 600 # Every 10 minutes
|
dvm_config.SCHEDULE_UPDATES_SECONDS = 600 # Every 10 minutes
|
||||||
|
dvm_config.UPDATE_DATABASE = update_db
|
||||||
# Activate these to use a subscription based model instead
|
# Activate these to use a subscription based model instead
|
||||||
# dvm_config.SUBSCRIPTION_REQUIRED = True
|
# dvm_config.SUBSCRIPTION_REQUIRED = True
|
||||||
# dvm_config.SUBSCRIPTION_DAILY_COST = 1
|
# dvm_config.SUBSCRIPTION_DAILY_COST = 1
|
||||||
@@ -258,11 +274,12 @@ def build_example(name, identifier, admin_config, options, image, description, p
|
|||||||
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):
|
def build_example_subscription(name, identifier, admin_config, options, image, description, 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
|
||||||
dvm_config.SCHEDULE_UPDATES_SECONDS = 600 # Every 10 minutes
|
dvm_config.SCHEDULE_UPDATES_SECONDS = 600 # Every 10 minutes
|
||||||
|
dvm_config.UPDATE_DATABASE = update_db
|
||||||
# Activate these to use a subscription based model instead
|
# Activate these to use a subscription based model instead
|
||||||
dvm_config.FIX_COST = 0
|
dvm_config.FIX_COST = 0
|
||||||
dvm_config.CUSTOM_PROCESSING_MESSAGE = processing_msg
|
dvm_config.CUSTOM_PROCESSING_MESSAGE = processing_msg
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class DVMConfig:
|
|||||||
|
|
||||||
RELAY_LIST = ["wss://relay.damus.io", "wss://nos.lol", "wss://nostr.wine",
|
RELAY_LIST = ["wss://relay.damus.io", "wss://nos.lol", "wss://nostr.wine",
|
||||||
"wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg",
|
"wss://nostr.mom", "wss://nostr.oxtr.dev", "wss://relay.nostr.bg",
|
||||||
"wss://relay.f7z.io", "wss://pablof7z.nostr1.com", "wss://relay.nostr.net", "wss://140.f7z.io",
|
"wss://relay.f7z.io", "wss://relay.nostr.net"
|
||||||
]
|
]
|
||||||
|
|
||||||
RELAY_TIMEOUT = 5
|
RELAY_TIMEOUT = 5
|
||||||
@@ -38,6 +38,7 @@ class DVMConfig:
|
|||||||
SEND_FEEDBACK_EVENTS = True
|
SEND_FEEDBACK_EVENTS = True
|
||||||
SHOW_RESULT_BEFORE_PAYMENT: bool = False # if this is true show results even when not paid right after autoprocess
|
SHOW_RESULT_BEFORE_PAYMENT: bool = False # if this is true show results even when not paid right after autoprocess
|
||||||
SCHEDULE_UPDATES_SECONDS = 0
|
SCHEDULE_UPDATES_SECONDS = 0
|
||||||
|
UPDATE_DATABASE = True # DVMs that use a db manage their db by default. If a dvm should use the same db as another DVM, deactive it for those who do.
|
||||||
CUSTOM_PROCESSING_MESSAGE = None
|
CUSTOM_PROCESSING_MESSAGE = None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -1,6 +1,6 @@
|
|||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
VERSION = '0.4.0'
|
VERSION = '0.4.1'
|
||||||
DESCRIPTION = 'A framework to build and run Nostr NIP90 Data Vending Machines'
|
DESCRIPTION = 'A framework to build and run Nostr NIP90 Data Vending Machines'
|
||||||
LONG_DESCRIPTION = ('A framework to build and run Nostr NIP90 Data Vending Machines. See the github repository for more information')
|
LONG_DESCRIPTION = ('A framework to build and run Nostr NIP90 Data Vending Machines. See the github repository for more information')
|
||||||
|
|
||||||
|
|||||||
@@ -16,11 +16,14 @@ from nostr_dvm.utils.zap_utils import check_and_set_ln_bits_keys
|
|||||||
|
|
||||||
|
|
||||||
def playground():
|
def playground():
|
||||||
# Generate an optional Admin Config, in this case, whenever we give our DVMs this config, they will (re)broadcast
|
# Popular NOSTR.band
|
||||||
# their NIP89 announcement
|
admin_config_trending_nostr_band = AdminConfig()
|
||||||
# You can create individual admins configs and hand them over when initializing the dvm,
|
custom_processing_msg = "Looking for trending notes on nostr.band.."
|
||||||
# for example to whilelist users or add to their balance.
|
trending_nb = discovery_trending_notes_nostrband.build_example("Trending Notes on nostr.band",
|
||||||
# If you use this global config, options will be set for all dvms that use it.
|
"trending_notes_nostrband",
|
||||||
|
admin_config_trending_nostr_band,
|
||||||
|
custom_processing_msg)
|
||||||
|
trending_nb.run()
|
||||||
|
|
||||||
# Popular Garden&Plants
|
# Popular Garden&Plants
|
||||||
admin_config_plants = AdminConfig()
|
admin_config_plants = AdminConfig()
|
||||||
@@ -33,9 +36,9 @@ def playground():
|
|||||||
options_plants = {
|
options_plants = {
|
||||||
"search_list": ["garden", "gardening", "nature", " plants ", " plant ", " herb ", " herbs " " pine ",
|
"search_list": ["garden", "gardening", "nature", " plants ", " plant ", " herb ", " herbs " " pine ",
|
||||||
"homesteading", "rosemary", "chicken", "🪻", "🌿", "☘️", "🌲", "flower", "forest", "watering",
|
"homesteading", "rosemary", "chicken", "🪻", "🌿", "☘️", "🌲", "flower", "forest", "watering",
|
||||||
"permies", "planting", "farm", "vegetable", "fruit", " grass ", "sunshine",
|
"permies", "planting", "farm", "vegetable", "fruit", " grass ", "sunshine",
|
||||||
"#flowerstr", "#bloomscrolling", "#treestr", "#plantstr", "touchgrass",],
|
"#flowerstr", "#bloomscrolling", "#treestr", "#plantstr", "touchgrass", ],
|
||||||
"avoid_list": ["porn", "smoke", "nsfw", "bitcoin", "bolt12", "bolt11", "github", "currency", "utxo",
|
"avoid_list": ["porn", "smoke", "nsfw", "bitcoin", "bolt12", "bolt11", "github", "currency", "utxo",
|
||||||
"encryption", "government", "airpod", "ipad", "iphone", "android", "warren",
|
"encryption", "government", "airpod", "ipad", "iphone", "android", "warren",
|
||||||
"moderna", "pfizer",
|
"moderna", "pfizer",
|
||||||
"murder", "tax", "engagement", "hodlers", "hodl", "gdp", "global markets", "crypto", "wherostr",
|
"murder", "tax", "engagement", "hodlers", "hodl", "gdp", "global markets", "crypto", "wherostr",
|
||||||
@@ -43,19 +46,24 @@ def playground():
|
|||||||
"white house", "blocks", "streaming", "summary", "wealth", "beef", "cunt", "nigger", "business",
|
"white house", "blocks", "streaming", "summary", "wealth", "beef", "cunt", "nigger", "business",
|
||||||
"retail", "bakery", "synth", "slaughterhouse", "hamas", "dog days", "ww3", "socialmedia",
|
"retail", "bakery", "synth", "slaughterhouse", "hamas", "dog days", "ww3", "socialmedia",
|
||||||
"nintendo", "signature", "deepfake", "congressman", "cypherpunk", "minister", "dissentwatch",
|
"nintendo", "signature", "deepfake", "congressman", "cypherpunk", "minister", "dissentwatch",
|
||||||
"inkblot", "covid", "robot", "pandemic", "bethesda", "zap farming", " defi ", " minister ",
|
"inkblot", "covid", "robot", "pandemic", "bethesda", "zap farming", " defi ", " minister ",
|
||||||
"nostr-hotter-site", " ai ", "palestine", "https://boards.4chan", "https://techcrunch.com", "https://screenrant.com"],
|
"nostr-hotter-site", " ai ", "palestine", "https://boards.4chan", "https://techcrunch.com",
|
||||||
"db_name": "db/nostr_recent_notes_plants.db",
|
"https://screenrant.com"],
|
||||||
"db_since": 10 * 60 * 60, # 10h
|
"db_name": "db/nostr_recent_notes.db",
|
||||||
|
"db_since": 10 * 60 * 60, # 10h since gmt
|
||||||
"personalized": False}
|
"personalized": False}
|
||||||
|
|
||||||
image = "https://image.nostr.build/a816f3f5e98e91e8a47d50f4cd7a2c17545f556d9bb0a6086a659b9abdf7ab68.jpg"
|
image = "https://image.nostr.build/a816f3f5e98e91e8a47d50f4cd7a2c17545f556d9bb0a6086a659b9abdf7ab68.jpg"
|
||||||
description = "I show recent notes about plants and gardening"
|
description = "I show recent notes about plants and gardening"
|
||||||
custom_processing_msg = ["Finding the best notes for you.. #blooming", "Looking for some positivity.. #touchgrass", "Looking for #goodvibes.."]
|
custom_processing_msg = ["Finding the best notes for you.. #blooming", "Looking for some positivity.. #touchgrass",
|
||||||
|
"Looking for #goodvibes.."]
|
||||||
|
update_db = False
|
||||||
discovery_test_sub = content_discovery_currently_popular_topic.build_example("Garden & Growth",
|
discovery_test_sub = content_discovery_currently_popular_topic.build_example("Garden & Growth",
|
||||||
"discovery_content_garden",
|
"discovery_content_garden",
|
||||||
admin_config_plants, options_plants, image,
|
admin_config_plants, options_plants,
|
||||||
description, custom_processing_msg)
|
image,
|
||||||
|
description, custom_processing_msg,
|
||||||
|
update_db)
|
||||||
discovery_test_sub.run()
|
discovery_test_sub.run()
|
||||||
|
|
||||||
# Popular Animals (Fluffy frens)
|
# Popular Animals (Fluffy frens)
|
||||||
@@ -63,8 +71,10 @@ def playground():
|
|||||||
admin_config_animals.REBROADCAST_NIP89 = False
|
admin_config_animals.REBROADCAST_NIP89 = False
|
||||||
admin_config_animals.UPDATE_PROFILE = False
|
admin_config_animals.UPDATE_PROFILE = False
|
||||||
options_animal = {
|
options_animal = {
|
||||||
"search_list": ["catstr", "pawstr", "dogstr", " cat ", " cats ", "🐾", "🐈", "🐕" , " dog ", " dogs ", " fluffy ", "animal",
|
"search_list": ["catstr", "pawstr", "dogstr", " cat ", " cats ", "🐾", "🐈", "🐕", " dog ", " dogs ", " fluffy ",
|
||||||
" duck", " lion ", " lions ", " fox ", " foxes ", " koala ", " koalas ", "capybara", "squirrel", "monkey", "panda", "alpaca", " otter"],
|
"animal",
|
||||||
|
" duck", " lion ", " lions ", " fox ", " foxes ", " koala ", " koalas ", "capybara", "squirrel",
|
||||||
|
"monkey", "panda", "alpaca", " otter"],
|
||||||
"avoid_list": ["porn", "smoke", "nsfw", "bitcoin", "bolt12", "bolt11", "github", "currency", "utxo",
|
"avoid_list": ["porn", "smoke", "nsfw", "bitcoin", "bolt12", "bolt11", "github", "currency", "utxo",
|
||||||
"encryption", "government", "airpod", "ipad", "iphone", "android", "warren",
|
"encryption", "government", "airpod", "ipad", "iphone", "android", "warren",
|
||||||
"moderna", "pfizer",
|
"moderna", "pfizer",
|
||||||
@@ -74,63 +84,73 @@ def playground():
|
|||||||
"retail", "bakery", "synth", "slaughterhouse", "hamas", "dog days", "ww3", "socialmedia",
|
"retail", "bakery", "synth", "slaughterhouse", "hamas", "dog days", "ww3", "socialmedia",
|
||||||
"nintendo", "signature", "deepfake", "congressman", "fried chicken", "cypherpunk",
|
"nintendo", "signature", "deepfake", "congressman", "fried chicken", "cypherpunk",
|
||||||
"chef", "cooked", "foodstr", "minister", "dissentwatch", "inkblot", "covid", "robot", "pandemic",
|
"chef", "cooked", "foodstr", "minister", "dissentwatch", "inkblot", "covid", "robot", "pandemic",
|
||||||
" dies ", "bethesda", " defi ", " minister ", "nostr-hotter-site", " ai ", "palestine", " hit by a", "https://boards.4chan", "https://techcrunch.com", "https://screenrant.com"],
|
" dies ", "bethesda", " defi ", " minister ", "nostr-hotter-site", " ai ", "palestine", "animalistic",
|
||||||
|
" hit by a", "https://boards.4chan", "https://techcrunch.com", "https://screenrant.com"],
|
||||||
|
|
||||||
|
"must_list": ["http"],
|
||||||
"must_list": ["http"],
|
"db_name": "db/nostr_recent_notes.db",
|
||||||
"db_name": "db/nostr_recent_notes_animals.db",
|
"db_since": 48 * 60 * 60, # 48h since gmt,
|
||||||
"db_since": 48 * 60 * 60, # 48h,
|
"personalized": False}
|
||||||
"personalized": False}
|
|
||||||
|
|
||||||
image = "https://image.nostr.build/f609311532c470f663e129510a76c9a1912ae9bc4aaaf058e5ba21cfb512c88e.jpg"
|
image = "https://image.nostr.build/f609311532c470f663e129510a76c9a1912ae9bc4aaaf058e5ba21cfb512c88e.jpg"
|
||||||
description = "I show recent notes about animals"
|
description = "I show recent notes about animals"
|
||||||
|
|
||||||
custom_processing_msg = ["Looking for fluffy frens...", "Let's see if we find some animals for you..", "Looking for the goodest bois and girls.."]
|
custom_processing_msg = ["Looking for fluffy frens...", "Let's see if we find some animals for you..",
|
||||||
|
"Looking for the goodest bois and girls.."]
|
||||||
|
update_db = True #As this is our largerst DB we update it here, and the other dvms use it. TODO make an own scheduler that only updates the db
|
||||||
discovery_animals = content_discovery_currently_popular_topic.build_example("Fluffy Frens",
|
discovery_animals = content_discovery_currently_popular_topic.build_example("Fluffy Frens",
|
||||||
"discovery_content_fluffy",
|
"discovery_content_fluffy",
|
||||||
admin_config_animals, options_animal, image,
|
admin_config_animals, options_animal,
|
||||||
description, custom_processing_msg)
|
image,
|
||||||
|
description, custom_processing_msg,
|
||||||
|
update_db)
|
||||||
discovery_animals.run()
|
discovery_animals.run()
|
||||||
|
|
||||||
# Popular Followers
|
# Popular Followers
|
||||||
admin_config_followers = AdminConfig()
|
admin_config_followers = AdminConfig()
|
||||||
admin_config_followers.REBROADCAST_NIP89 = False
|
admin_config_followers.REBROADCAST_NIP89 = False
|
||||||
admin_config_followers.UPDATE_PROFILE = False
|
admin_config_followers.UPDATE_PROFILE = False
|
||||||
custom_processing_msg = ["Looking for popular notes from npubs you follow..", "Let's see what npubs you follow have been up to..", "Processing a personalized feed, just for you.."]
|
custom_processing_msg = ["Looking for popular notes from npubs you follow..",
|
||||||
|
"Let's see what npubs you follow have been up to..",
|
||||||
|
"Processing a personalized feed, just for you.."]
|
||||||
|
update_db = False
|
||||||
|
options_followers_popular = {
|
||||||
|
"db_name": "db/nostr_recent_notes.db",
|
||||||
|
"db_since": 2 * 60 * 60, # 2h since gmt,
|
||||||
|
}
|
||||||
|
|
||||||
discovery_followers = content_discovery_currently_popular_followers.build_example("Currently Popular Notes from npubs you follow",
|
discovery_followers = content_discovery_currently_popular_followers.build_example(
|
||||||
"discovery_content_followers",
|
"Currently Popular Notes from npubs you follow",
|
||||||
admin_config_followers,
|
"discovery_content_followers",
|
||||||
custom_processing_msg)
|
admin_config=admin_config_followers,
|
||||||
|
options=options_followers_popular,
|
||||||
|
processing_msg=custom_processing_msg,
|
||||||
|
update_db=update_db)
|
||||||
discovery_followers.run()
|
discovery_followers.run()
|
||||||
|
|
||||||
#Popular Global
|
# Popular Global
|
||||||
admin_config_global_popular = AdminConfig()
|
admin_config_global_popular = AdminConfig()
|
||||||
admin_config_global_popular.REBROADCAST_NIP89 = False
|
admin_config_global_popular.REBROADCAST_NIP89 = False
|
||||||
admin_config_global_popular.UPDATE_PROFILE = False
|
admin_config_global_popular.UPDATE_PROFILE = False
|
||||||
custom_processing_msg = ["Looking for popular notes on the Nostr..", "Let's see what's trending on Nostr..", "Finding the best notes for you.."]
|
custom_processing_msg = ["Looking for popular notes on the Nostr..", "Let's see what's trending on Nostr..",
|
||||||
|
"Finding the best notes for you.."]
|
||||||
|
update_db = False
|
||||||
|
|
||||||
|
options_global_popular = {
|
||||||
|
"db_name": "db/nostr_recent_notes.db",
|
||||||
|
"db_since": 60 * 60, # 1h since gmt,
|
||||||
|
}
|
||||||
discovery_global = content_discovery_currently_popular.build_example("Currently Popular Notes DVM",
|
discovery_global = content_discovery_currently_popular.build_example("Currently Popular Notes DVM",
|
||||||
"discovery_content_test",
|
"discovery_content_test",
|
||||||
admin_config_global_popular,
|
admin_config=admin_config_global_popular,
|
||||||
custom_processing_msg)
|
options=options_global_popular,
|
||||||
|
processing_msg=custom_processing_msg,
|
||||||
|
update_db=update_db)
|
||||||
discovery_global.run()
|
discovery_global.run()
|
||||||
|
|
||||||
|
|
||||||
# discovery_test_sub = content_discovery_currently_popular.build_example_subscription("Currently Popular Notes DVM (with Subscriptions)", "discovery_content_test", admin_config)
|
# discovery_test_sub = content_discovery_currently_popular.build_example_subscription("Currently Popular Notes DVM (with Subscriptions)", "discovery_content_test", admin_config)
|
||||||
# discovery_test_sub.run()
|
# discovery_test_sub.run()
|
||||||
|
|
||||||
|
|
||||||
#Popular NOSTR.band
|
|
||||||
admin_config_trending_nostr_band = AdminConfig()
|
|
||||||
custom_processing_msg = "Looking for trending notes on nostr.band.."
|
|
||||||
trending_nb = discovery_trending_notes_nostrband.build_example("Trending Notes on nostr.band",
|
|
||||||
"trending_notes_nostrband", admin_config_trending_nostr_band, custom_processing_msg)
|
|
||||||
trending_nb.run()
|
|
||||||
|
|
||||||
|
|
||||||
# Subscription Manager DVM
|
# Subscription Manager DVM
|
||||||
subscription_config = DVMConfig()
|
subscription_config = DVMConfig()
|
||||||
subscription_config.PRIVATE_KEY = check_and_set_private_key("dvm_subscription")
|
subscription_config.PRIVATE_KEY = check_and_set_private_key("dvm_subscription")
|
||||||
|
|||||||
Reference in New Issue
Block a user