mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-11-18 23:16:28 +01:00
fix threading on inactive followers
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
@@ -26,7 +27,7 @@ Params: None
|
|||||||
class DiscoverInactiveFollows(DVMTaskInterface):
|
class DiscoverInactiveFollows(DVMTaskInterface):
|
||||||
KIND: Kind = EventDefinitions.KIND_NIP90_PEOPLE_DISCOVERY
|
KIND: Kind = EventDefinitions.KIND_NIP90_PEOPLE_DISCOVERY
|
||||||
TASK: str = "inactive-followings"
|
TASK: str = "inactive-followings"
|
||||||
FIX_COST: float = 100
|
FIX_COST: float = 0
|
||||||
client: Client
|
client: Client
|
||||||
dvm_config: DVMConfig
|
dvm_config: DVMConfig
|
||||||
|
|
||||||
@@ -71,12 +72,13 @@ class DiscoverInactiveFollows(DVMTaskInterface):
|
|||||||
keys = Keys.parse(sk.to_hex())
|
keys = Keys.parse(sk.to_hex())
|
||||||
signer = NostrSigner.keys(keys)
|
signer = NostrSigner.keys(keys)
|
||||||
|
|
||||||
#relaylimits = RelayLimits().event_max_num_tags(max_num_tags=10000)
|
# relaylimits = RelayLimits().event_max_num_tags(max_num_tags=10000)
|
||||||
#relaylimits.event_max_size(None)
|
# relaylimits.event_max_size(None)
|
||||||
relaylimits = RelayLimits.disable()
|
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)
|
cli = Client.with_opts(signer, opts)
|
||||||
for relay in self.dvm_config.RELAY_LIST:
|
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_filter = Filter().author(PublicKey.parse(options["user"])).kind(Kind(3))
|
||||||
followers = await cli.get_events_of([followers_filter], timedelta(seconds=5))
|
followers = await cli.get_events_of([followers_filter], timedelta(seconds=5))
|
||||||
|
|
||||||
|
|
||||||
if len(followers) > 0:
|
if len(followers) > 0:
|
||||||
result_list = []
|
result_list = []
|
||||||
newest = 0
|
newest = 0
|
||||||
@@ -104,7 +105,6 @@ class DiscoverInactiveFollows(DVMTaskInterface):
|
|||||||
newest = entry.created_at().as_secs()
|
newest = entry.created_at().as_secs()
|
||||||
best_entry = entry
|
best_entry = entry
|
||||||
|
|
||||||
|
|
||||||
print(best_entry.as_json())
|
print(best_entry.as_json())
|
||||||
print(len(best_entry.tags()))
|
print(len(best_entry.tags()))
|
||||||
print(best_entry.created_at().as_secs())
|
print(best_entry.created_at().as_secs())
|
||||||
@@ -150,15 +150,14 @@ class DiscoverInactiveFollows(DVMTaskInterface):
|
|||||||
begin = 0
|
begin = 0
|
||||||
# Spawn some threads to speed things up
|
# Spawn some threads to speed things up
|
||||||
while begin < len(followings) - step:
|
while begin < len(followings) - step:
|
||||||
args = [followings, ns, begin, step, not_active_since]
|
t = Thread(target=asyncio.run, args=(scanList(followings, ns, begin, step, not_active_since),))
|
||||||
t = Thread(target=scanList, args=args)
|
|
||||||
threads.append(t)
|
threads.append(t)
|
||||||
begin = begin + step -1
|
begin = begin + step - 1
|
||||||
|
|
||||||
# last to step size
|
# last to step size
|
||||||
missing_scans = (len(followings) - begin)
|
missing_scans = (len(followings) - begin)
|
||||||
args = [followings, ns, begin, missing_scans, not_active_since]
|
t = Thread(target=asyncio.run, args=(scanList(followings, ns, begin, missing_scans, not_active_since),))
|
||||||
t = Thread(target=scanList, args=args)
|
|
||||||
threads.append(t)
|
threads.append(t)
|
||||||
|
|
||||||
# Start all threads
|
# Start all threads
|
||||||
@@ -202,7 +201,7 @@ def build_example(name, identifier, admin_config):
|
|||||||
"name": name,
|
"name": name,
|
||||||
"image": "https://image.nostr.build/c33ca6fc4cc038ca4adb46fdfdfda34951656f87ee364ef59095bae1495ce669.jpg",
|
"image": "https://image.nostr.build/c33ca6fc4cc038ca4adb46fdfdfda34951656f87ee364ef59095bae1495ce669.jpg",
|
||||||
"about": "I discover users you follow, but that have been inactive on Nostr",
|
"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,
|
"encryptionSupported": True,
|
||||||
"cashuAccepted": True,
|
"cashuAccepted": True,
|
||||||
"nip90Params": {
|
"nip90Params": {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
@@ -148,14 +149,14 @@ class DiscoverNonFollowers(DVMTaskInterface):
|
|||||||
# Spawn some threads to speed things up
|
# Spawn some threads to speed things up
|
||||||
while begin < len(followings) - step:
|
while begin < len(followings) - step:
|
||||||
args = [followings, ns, begin, 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)
|
threads.append(t)
|
||||||
begin = begin + step - 1
|
begin = begin + step - 1
|
||||||
|
|
||||||
# last to step size
|
# last to step size
|
||||||
missing_scans = (len(followings) - begin)
|
missing_scans = (len(followings) - begin)
|
||||||
args = [followings, ns, begin, missing_scans]
|
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)
|
threads.append(t)
|
||||||
|
|
||||||
# Start all threads
|
# Start all threads
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ async def input_data_file_duration(event, dvm_config, client, start=0, end=0):
|
|||||||
return len(input_value)
|
return len(input_value)
|
||||||
|
|
||||||
if input_type == "url":
|
if input_type == "url":
|
||||||
|
source_type = check_source_type(input_value)
|
||||||
duration = get_media_duration(input_value)
|
duration = get_media_duration(input_value)
|
||||||
if duration is None:
|
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)
|
filename, start, end, type = get_file_start_end_type(input_value, source_type, start, end, True)
|
||||||
if type != "audio" and type != "video":
|
if type != "audio" and type != "video":
|
||||||
return 1
|
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":
|
if type != "audio" and type != "video":
|
||||||
return filename
|
return filename
|
||||||
try:
|
try:
|
||||||
# file_reader = AudioReader(filename, ctx=cpu(0), mono=False)
|
source_type = check_source_type(input_value)
|
||||||
# duration = float(file_reader.duration())
|
duration = get_media_duration(input_value)
|
||||||
duration = ffmpegio.probe.format_basic(filename)['duration']
|
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:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|||||||
11
tests/bot.py
11
tests/bot.py
@@ -8,7 +8,7 @@ import dotenv
|
|||||||
from nostr_sdk import Keys
|
from nostr_sdk import Keys
|
||||||
|
|
||||||
from nostr_dvm.bot import Bot
|
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.admin_utils import AdminConfig
|
||||||
from nostr_dvm.utils.backend_utils import keep_alive
|
from nostr_dvm.utils.backend_utils import keep_alive
|
||||||
from nostr_dvm.utils.definitions import EventDefinitions
|
from nostr_dvm.utils.definitions import EventDefinitions
|
||||||
@@ -55,6 +55,15 @@ def playground():
|
|||||||
bot_config.SUPPORTED_DVMS.append(media_bringer)
|
bot_config.SUPPORTED_DVMS.append(media_bringer)
|
||||||
media_bringer.run()
|
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 = AdminConfig()
|
||||||
admin_config.REBROADCAST_NIP65_RELAY_LIST = True
|
admin_config.REBROADCAST_NIP65_RELAY_LIST = True
|
||||||
admin_config.UPDATE_PROFILE = True
|
admin_config.UPDATE_PROFILE = True
|
||||||
|
|||||||
Reference in New Issue
Block a user