mirror of
https://github.com/aljazceru/nostrdvm.git
synced 2025-12-23 17:04:27 +01:00
code cleanup
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
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, Kind, RelayOptions
|
|
||||||
|
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Kind
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from nostr_sdk import Client, Timestamp, PublicKey, Tag, Keys, Options, SecretKey, NostrSigner, Event, Kind
|
from nostr_sdk import Timestamp, PublicKey, Tag, Kind
|
||||||
|
|
||||||
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
|
||||||
@@ -85,7 +84,6 @@ class AdvancedSearchWine(DVMTaskInterface):
|
|||||||
return request_form
|
return request_form
|
||||||
|
|
||||||
async def process(self, request_form):
|
async def process(self, request_form):
|
||||||
from nostr_sdk import Filter
|
|
||||||
options = self.set_options(request_form)
|
options = self.set_options(request_form)
|
||||||
userkeys = []
|
userkeys = []
|
||||||
for user in options["users"]:
|
for user in options["users"]:
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
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, 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
|
||||||
@@ -14,7 +15,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
|
||||||
@@ -113,7 +113,7 @@ class DicoverContentLatestLongForm(DVMTaskInterface):
|
|||||||
signer = NostrSigner.keys(keys)
|
signer = NostrSigner.keys(keys)
|
||||||
|
|
||||||
database = NostrDatabase.lmdb(self.db_name)
|
database = NostrDatabase.lmdb(self.db_name)
|
||||||
#print(self.db_name)
|
# print(self.db_name)
|
||||||
cli = ClientBuilder().database(database).signer(signer).opts(opts).build()
|
cli = ClientBuilder().database(database).signer(signer).opts(opts).build()
|
||||||
await cli.connect()
|
await cli.connect()
|
||||||
|
|
||||||
@@ -130,8 +130,8 @@ class DicoverContentLatestLongForm(DVMTaskInterface):
|
|||||||
index = options["max_results"]
|
index = options["max_results"]
|
||||||
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:
|
||||||
ns.finallist[event.id().to_hex()] = index
|
ns.finallist[event.id().to_hex()] = index
|
||||||
index = index-1
|
index = index - 1
|
||||||
if len(ns.finallist) == 0:
|
if len(ns.finallist) == 0:
|
||||||
await cli.shutdown()
|
await cli.shutdown()
|
||||||
return self.result
|
return self.result
|
||||||
@@ -189,7 +189,8 @@ class DicoverContentLatestLongForm(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_LONGFORM]).since(since) # Notes, reactions, zaps
|
filter1 = Filter().kinds([definitions.EventDefinitions.KIND_LONGFORM]).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:
|
||||||
@@ -202,10 +203,12 @@ class DicoverContentLatestLongForm(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)
|
||||||
|
|
||||||
|
|
||||||
# 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
|
||||||
@@ -254,7 +257,7 @@ def build_example(name, identifier, admin_config, options, cost=0, update_rate=1
|
|||||||
# admin_config.REBROADCAST_NIP89 = False
|
# admin_config.REBROADCAST_NIP89 = False
|
||||||
|
|
||||||
return DicoverContentLatestLongForm(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
return DicoverContentLatestLongForm(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||||
admin_config=admin_config, options=options)
|
admin_config=admin_config, options=options)
|
||||||
|
|
||||||
|
|
||||||
def build_example_subscription(name, identifier, admin_config, options, update_rate=180, processing_msg=None,
|
def build_example_subscription(name, identifier, admin_config, options, update_rate=180, processing_msg=None,
|
||||||
@@ -317,8 +320,8 @@ def build_example_subscription(name, identifier, admin_config, options, update_r
|
|||||||
# admin_config.PRIVKEY = dvm_config.PRIVATE_KEY
|
# admin_config.PRIVKEY = dvm_config.PRIVATE_KEY
|
||||||
|
|
||||||
return DicoverContentLatestLongForm(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
return DicoverContentLatestLongForm(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
||||||
nip88config=nip88config, options=options,
|
nip88config=nip88config, options=options,
|
||||||
admin_config=admin_config)
|
admin_config=admin_config)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user