fix threading on inactive followers

This commit is contained in:
Believethehype 2024-06-24 09:07:35 +02:00
parent b40467f6c8
commit 3fc15ee114
4 changed files with 32 additions and 20 deletions

View File

@ -1,3 +1,4 @@
import asyncio
import json
import os
from datetime import timedelta
@ -26,7 +27,7 @@ Params: None
class DiscoverInactiveFollows(DVMTaskInterface):
KIND: Kind = EventDefinitions.KIND_NIP90_PEOPLE_DISCOVERY
TASK: str = "inactive-followings"
FIX_COST: float = 100
FIX_COST: float = 0
client: Client
dvm_config: DVMConfig
@ -71,12 +72,13 @@ class DiscoverInactiveFollows(DVMTaskInterface):
keys = Keys.parse(sk.to_hex())
signer = NostrSigner.keys(keys)
#relaylimits = RelayLimits().event_max_num_tags(max_num_tags=10000)
#relaylimits.event_max_size(None)
# relaylimits = RelayLimits().event_max_num_tags(max_num_tags=10000)
# relaylimits.event_max_size(None)
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)
cli = Client.with_opts(signer, opts)
for relay in self.dvm_config.RELAY_LIST:
@ -92,7 +94,6 @@ class DiscoverInactiveFollows(DVMTaskInterface):
followers_filter = Filter().author(PublicKey.parse(options["user"])).kind(Kind(3))
followers = await cli.get_events_of([followers_filter], timedelta(seconds=5))
if len(followers) > 0:
result_list = []
newest = 0
@ -104,7 +105,6 @@ class DiscoverInactiveFollows(DVMTaskInterface):
newest = entry.created_at().as_secs()
best_entry = entry
print(best_entry.as_json())
print(len(best_entry.tags()))
print(best_entry.created_at().as_secs())
@ -150,15 +150,14 @@ class DiscoverInactiveFollows(DVMTaskInterface):
begin = 0
# Spawn some threads to speed things up
while begin < len(followings) - step:
args = [followings, ns, begin, step, not_active_since]
t = Thread(target=scanList, args=args)
t = Thread(target=asyncio.run, args=(scanList(followings, ns, begin, step, not_active_since),))
threads.append(t)
begin = begin + step -1
begin = begin + step - 1
# last to step size
missing_scans = (len(followings) - begin)
args = [followings, ns, begin, missing_scans, not_active_since]
t = Thread(target=scanList, args=args)
t = Thread(target=asyncio.run, args=(scanList(followings, ns, begin, missing_scans, not_active_since),))
threads.append(t)
# Start all threads
@ -202,7 +201,7 @@ def build_example(name, identifier, admin_config):
"name": name,
"image": "https://image.nostr.build/c33ca6fc4cc038ca4adb46fdfdfda34951656f87ee364ef59095bae1495ce669.jpg",
"about": "I discover users you follow, but that have been inactive on Nostr",
"action": "unfollow", #follow, mute, unmute
"action": "unfollow", # follow, mute, unmute
"encryptionSupported": True,
"cashuAccepted": True,
"nip90Params": {

View File

@ -1,3 +1,4 @@
import asyncio
import json
import os
from datetime import timedelta
@ -148,14 +149,14 @@ class DiscoverNonFollowers(DVMTaskInterface):
# Spawn some threads to speed things up
while begin < len(followings) - step:
args = [followings, ns, begin, step]
t = Thread(target=scanList, args=args)
t = Thread(target=asyncio.run, args=(scanList(followings, ns, begin, step),))
threads.append(t)
begin = begin + step - 1
# last to step size
missing_scans = (len(followings) - begin)
args = [followings, ns, begin, missing_scans]
t = Thread(target=scanList, args=args)
t = Thread(target=asyncio.run, args=(scanList(followings, ns, begin, missing_scans),))
threads.append(t)
# Start all threads

View File

@ -37,9 +37,9 @@ async def input_data_file_duration(event, dvm_config, client, start=0, end=0):
return len(input_value)
if input_type == "url":
source_type = check_source_type(input_value)
duration = get_media_duration(input_value)
if duration is None:
source_type = check_source_type(input_value)
filename, start, end, type = get_file_start_end_type(input_value, source_type, start, end, True)
if type != "audio" and type != "video":
return 1
@ -79,9 +79,12 @@ async def organize_input_media_data(input_value, input_type, start, end, dvm_con
if type != "audio" and type != "video":
return filename
try:
# file_reader = AudioReader(filename, ctx=cpu(0), mono=False)
# duration = float(file_reader.duration())
duration = ffmpegio.probe.format_basic(filename)['duration']
source_type = check_source_type(input_value)
duration = get_media_duration(input_value)
if duration is None:
# file_reader = AudioReader(filename, ctx=cpu(0), mono=False)
# duration = float(file_reader.duration())
duration = ffmpegio.probe.format_basic(filename)['duration']
except Exception as e:
print(e)

View File

@ -8,7 +8,7 @@ import dotenv
from nostr_sdk import Keys
from nostr_dvm.bot import Bot
from nostr_dvm.tasks import textextraction_pdf, convert_media
from nostr_dvm.tasks import textextraction_pdf, convert_media, discovery_inactive_follows
from nostr_dvm.utils.admin_utils import AdminConfig
from nostr_dvm.utils.backend_utils import keep_alive
from nostr_dvm.utils.definitions import EventDefinitions
@ -55,6 +55,15 @@ def playground():
bot_config.SUPPORTED_DVMS.append(media_bringer)
media_bringer.run()
admin_config_followers = AdminConfig()
admin_config_followers.UPDATE_PROFILE = True
admin_config_followers.REBROADCAST_NIP65_RELAY_LIST = True
discover_inactive = discovery_inactive_follows.build_example("Those who left",
"discovery_inactive_follows", admin_config_followers)
bot_config.SUPPORTED_DVMS.append(discover_inactive)
discover_inactive.run()
admin_config = AdminConfig()
admin_config.REBROADCAST_NIP65_RELAY_LIST = True
admin_config.UPDATE_PROFILE = True