mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-10-10 22:42:30 +02:00
update popular notes with personalized flag
This commit is contained in:
@@ -30,6 +30,8 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
|||||||
db_since = 3600
|
db_since = 3600
|
||||||
db_name = "db/nostr_recent_notes.db"
|
db_name = "db/nostr_recent_notes.db"
|
||||||
min_reactions = 2
|
min_reactions = 2
|
||||||
|
personalized = False
|
||||||
|
result = ""
|
||||||
|
|
||||||
def __init__(self, name, dvm_config: DVMConfig, nip89config: NIP89Config, nip88config: NIP88Config = None,
|
def __init__(self, name, dvm_config: DVMConfig, nip89config: NIP89Config, nip88config: NIP88Config = None,
|
||||||
admin_config: AdminConfig = None, options=None):
|
admin_config: AdminConfig = None, options=None):
|
||||||
@@ -37,6 +39,12 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
|||||||
super().__init__(name=name, dvm_config=dvm_config, nip89config=nip89config, nip88config=nip88config,
|
super().__init__(name=name, dvm_config=dvm_config, nip89config=nip89config, nip88config=nip88config,
|
||||||
admin_config=admin_config, options=options)
|
admin_config=admin_config, options=options)
|
||||||
|
|
||||||
|
self.request_form = {"jobID": "generic"}
|
||||||
|
opts = {
|
||||||
|
"max_results": 200,
|
||||||
|
}
|
||||||
|
self.request_form['options'] = json.dumps(opts)
|
||||||
|
|
||||||
self.last_schedule = Timestamp.now().as_secs()
|
self.last_schedule = Timestamp.now().as_secs()
|
||||||
|
|
||||||
use_logger = False
|
use_logger = False
|
||||||
@@ -44,6 +52,8 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
|||||||
init_logger(LogLevel.DEBUG)
|
init_logger(LogLevel.DEBUG)
|
||||||
|
|
||||||
self.sync_db()
|
self.sync_db()
|
||||||
|
if not self.personalized:
|
||||||
|
self.result = self.calculate_result(self.request_form)
|
||||||
|
|
||||||
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:
|
||||||
@@ -79,6 +89,14 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
|||||||
return request_form
|
return request_form
|
||||||
|
|
||||||
def process(self, request_form):
|
def process(self, request_form):
|
||||||
|
# if the dvm supports individual results, recalculate it every time for the request
|
||||||
|
if self.personalized:
|
||||||
|
return self.calculate_result(request_form)
|
||||||
|
#else return the result that gets updated once every schenduled update. In this case on database update.
|
||||||
|
else:
|
||||||
|
return self.result
|
||||||
|
|
||||||
|
def calculate_result(self, request_form):
|
||||||
from nostr_sdk import Filter
|
from nostr_sdk import Filter
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
ns = SimpleNamespace()
|
ns = SimpleNamespace()
|
||||||
@@ -138,6 +156,7 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
|
|||||||
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()
|
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)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def sync_db(self):
|
def sync_db(self):
|
||||||
@@ -187,6 +206,7 @@ def build_example(name, identifier, admin_config):
|
|||||||
"lud16": dvm_config.LN_ADDRESS,
|
"lud16": dvm_config.LN_ADDRESS,
|
||||||
"encryptionSupported": True,
|
"encryptionSupported": True,
|
||||||
"cashuAccepted": True,
|
"cashuAccepted": True,
|
||||||
|
"personalized": False,
|
||||||
"amount": "free",
|
"amount": "free",
|
||||||
"nip90Params": {
|
"nip90Params": {
|
||||||
"max_results": {
|
"max_results": {
|
||||||
@@ -226,6 +246,7 @@ def build_example_subscription(name, identifier, admin_config):
|
|||||||
"encryptionSupported": True,
|
"encryptionSupported": True,
|
||||||
"cashuAccepted": True,
|
"cashuAccepted": True,
|
||||||
"subscription": True,
|
"subscription": True,
|
||||||
|
"personalized": False,
|
||||||
"nip90Params": {
|
"nip90Params": {
|
||||||
"max_results": {
|
"max_results": {
|
||||||
"required": False,
|
"required": False,
|
||||||
|
@@ -229,7 +229,7 @@ def build_example(name, identifier, admin_config):
|
|||||||
"lud16": dvm_config.LN_ADDRESS,
|
"lud16": dvm_config.LN_ADDRESS,
|
||||||
"encryptionSupported": True,
|
"encryptionSupported": True,
|
||||||
"cashuAccepted": True,
|
"cashuAccepted": True,
|
||||||
"personalized": False,
|
"personalized": True,
|
||||||
"amount": "free",
|
"amount": "free",
|
||||||
"nip90Params": {
|
"nip90Params": {
|
||||||
"max_results": {
|
"max_results": {
|
||||||
@@ -268,7 +268,7 @@ def build_example_subscription(name, identifier, admin_config):
|
|||||||
"lud16": dvm_config.LN_ADDRESS,
|
"lud16": dvm_config.LN_ADDRESS,
|
||||||
"encryptionSupported": True,
|
"encryptionSupported": True,
|
||||||
"cashuAccepted": True,
|
"cashuAccepted": True,
|
||||||
"personalized": False,
|
"personalized": True,
|
||||||
"subscription": True,
|
"subscription": True,
|
||||||
"nip90Params": {
|
"nip90Params": {
|
||||||
"max_results": {
|
"max_results": {
|
||||||
|
@@ -75,7 +75,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
|||||||
|
|
||||||
self.sync_db()
|
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)
|
||||||
|
|
||||||
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:
|
||||||
@@ -130,7 +130,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
|||||||
|
|
||||||
# if not text/plain, don't post-process
|
# if not text/plain, don't post-process
|
||||||
return result
|
return result
|
||||||
def calculate_Result(self, request_form):
|
def calculate_result(self, request_form):
|
||||||
from nostr_sdk import Filter
|
from nostr_sdk import Filter
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
ns = SimpleNamespace()
|
ns = SimpleNamespace()
|
||||||
@@ -186,7 +186,7 @@ class DicoverContentCurrentlyPopularbyTopic(DVMTaskInterface):
|
|||||||
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()
|
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)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@@ -237,6 +237,7 @@ def build_example(name, identifier, admin_config, options, image, description):
|
|||||||
"lud16": dvm_config.LN_ADDRESS,
|
"lud16": dvm_config.LN_ADDRESS,
|
||||||
"encryptionSupported": True,
|
"encryptionSupported": True,
|
||||||
"cashuAccepted": True,
|
"cashuAccepted": True,
|
||||||
|
"personalized": False,
|
||||||
"amount": "free",
|
"amount": "free",
|
||||||
"nip90Params": {
|
"nip90Params": {
|
||||||
"max_results": {
|
"max_results": {
|
||||||
@@ -278,6 +279,7 @@ def build_example_subscription(name, identifier, admin_config, options, image, d
|
|||||||
"encryptionSupported": True,
|
"encryptionSupported": True,
|
||||||
"cashuAccepted": True,
|
"cashuAccepted": True,
|
||||||
"subscription": True,
|
"subscription": True,
|
||||||
|
"personalized": False,
|
||||||
"nip90Params": {
|
"nip90Params": {
|
||||||
"max_results": {
|
"max_results": {
|
||||||
"required": False,
|
"required": False,
|
||||||
|
Reference in New Issue
Block a user