code cleanup

This commit is contained in:
Believethehype
2024-10-17 16:10:35 +02:00
parent 3c4a900ff0
commit a3ad0bebc7
4 changed files with 45 additions and 45 deletions

View File

@@ -1,11 +1,8 @@
import asyncio
import json
import os
import time
from io import BytesIO
import requests
import urllib.request
from PIL import Image
from nostr_sdk import Kind
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
@@ -14,7 +11,6 @@ from nostr_dvm.utils.definitions import EventDefinitions
from nostr_dvm.utils.dvmconfig import DVMConfig, build_default_config
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.output_utils import upload_media_to_hoster
from nostr_dvm.utils.zap_utils import get_price_per_sat
"""
@@ -139,7 +135,7 @@ class AudioGenerationSonoAI(DVMTaskInterface):
response2 = self.get_clip(data[1]['id'])
print(response2['video_url'])
#print(response2['prompt']) #same as 1
# print(response2['prompt']) #same as 1
return response1['video_url'] + "\n" + response2['video_url'] + "\n" + response1['prompt']

View File

@@ -1,9 +1,10 @@
import json
import os
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, \
RelayOptions, RelayLimits
from nostr_sdk import Timestamp, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
ClientBuilder, Filter, NegentropyOptions, NegentropyDirection, init_logger, LogLevel, Kind, \
RelayLimits
from nostr_dvm.interfaces.dvmtaskinterface import DVMTaskInterface, process_venv
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.output_utils import post_process_list_to_events
"""
This File contains a Module to discover popular notes
Accepted Inputs: none
@@ -113,7 +113,7 @@ class DicoverContentLatestWiki(DVMTaskInterface):
signer = NostrSigner.keys(keys)
database = NostrDatabase.lmdb(self.db_name)
#print(self.db_name)
# print(self.db_name)
cli = ClientBuilder().database(database).signer(signer).opts(opts).build()
await cli.connect()
@@ -130,8 +130,8 @@ class DicoverContentLatestWiki(DVMTaskInterface):
index = options["max_results"]
for event in events:
if event.created_at().as_secs() > timestamp_hour_ago:
ns.finallist[event.id().to_hex()] = index
index = index-1
ns.finallist[event.id().to_hex()] = index
index = index - 1
if len(ns.finallist) == 0:
await cli.shutdown()
return self.result
@@ -202,10 +202,12 @@ class DicoverContentLatestWiki(DVMTaskInterface):
await cli.shutdown()
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..")
"[" + self.dvm_config.NIP89.NAME + "] Done Syncing Notes of the last " + str(
self.db_since) + " seconds..")
except Exception as e:
print(e)
# 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
# playground or elsewhere
@@ -254,7 +256,7 @@ def build_example(name, identifier, admin_config, options, cost=0, update_rate=1
# admin_config.REBROADCAST_NIP89 = False
return DicoverContentLatestWiki(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,
@@ -317,8 +319,8 @@ def build_example_subscription(name, identifier, admin_config, options, update_r
# admin_config.PRIVKEY = dvm_config.PRIVATE_KEY
return DicoverContentLatestWiki(name=name, dvm_config=dvm_config, nip89config=nip89config,
nip88config=nip88config, options=options,
admin_config=admin_config)
nip88config=nip88config, options=options,
admin_config=admin_config)
if __name__ == '__main__':

View File

@@ -1,10 +1,10 @@
import asyncio
import json
import json
import os
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, \
RelayOptions
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.utils import definitions
@@ -15,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.output_utils import post_process_list_to_events
"""
This File contains a Module to discover popular notes
Accepted Inputs: none
@@ -144,7 +143,6 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
# await cli.shutdown()
return json.dumps(result_list)
async def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags():
@@ -186,8 +184,9 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
timestamp_since = Timestamp.now().as_secs() - self.db_since
since = Timestamp.from_secs(timestamp_since)
filter1 = Filter().kinds([definitions.EventDefinitions.KIND_NOTE, definitions.EventDefinitions.KIND_REACTION,
definitions.EventDefinitions.KIND_ZAP]).since(since) # 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())
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
@@ -200,10 +199,12 @@ class DicoverContentCurrentlyPopular(DVMTaskInterface):
await cli.shutdown()
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..")
"[" + self.dvm_config.NIP89.NAME + "] Done Syncing Notes of the last " + str(
self.db_since) + " seconds..")
except Exception as e:
print(e)
# 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
# playground or elsewhere

View File

@@ -1,10 +1,8 @@
import asyncio
import json
import os
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, \
RelayOptions
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.utils import definitions
@@ -14,7 +12,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.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.zap_utils import parse_zap_event_tags, parse_amount_from_bolt11_invoice
from nostr_dvm.utils.zap_utils import parse_amount_from_bolt11_invoice
"""
This File contains a Module to discover popular notes by amount of zaps
@@ -39,7 +37,7 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface):
logger = False
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):
self.request_form = {"jobID": "generic"}
opts = {
@@ -110,15 +108,15 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface):
options = self.set_options(request_form)
#opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)))
#sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
#keys = Keys.parse(sk.to_hex())
#signer = NostrSigner.keys(keys)
# opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT)))
# sk = SecretKey.from_hex(self.dvm_config.PRIVATE_KEY)
# keys = Keys.parse(sk.to_hex())
# signer = NostrSigner.keys(keys)
database = NostrDatabase.lmdb(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()
# Negentropy reconciliation
# Query events from database
@@ -143,7 +141,7 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface):
overall_amount = 0
for zap in zaps:
if event_author == zap.author().to_hex():
continue #Skip self zaps..
continue # Skip self zaps..
invoice_amount = 0
for tag in zap.tags():
@@ -165,7 +163,7 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface):
if has_amount:
overall_amount += invoice_amount
break
#elif tag.as_vec()[0] == 'description':
# elif tag.as_vec()[0] == 'description':
# try:
# event = Event.from_json(tag.as_vec()[1])
# for tag in event.tags():
@@ -194,7 +192,7 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface):
print("[" + self.dvm_config.NIP89.NAME + "] Filtered " + str(
len(result_list)) + " fitting events.")
#await cli.shutdown()
# await cli.shutdown()
return json.dumps(result_list)
@@ -241,8 +239,9 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface):
timestamp_since = Timestamp.now().as_secs() - self.db_since
since = Timestamp.from_secs(timestamp_since)
filter1 = Filter().kinds([definitions.EventDefinitions.KIND_NOTE, definitions.EventDefinitions.KIND_REACTION,
definitions.EventDefinitions.KIND_ZAP]).since(since) # 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())
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
@@ -255,10 +254,12 @@ class DicoverContentCurrentlyPopularZaps(DVMTaskInterface):
await cli.shutdown()
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..")
"[" + self.dvm_config.NIP89.NAME + "] Done Syncing Notes of the last " + str(
self.db_since) + " seconds..")
except Exception as e:
print(e)
# 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
# playground or elsewhere