Skip to content

Commit

Permalink
bump, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
believethehype committed Jun 16, 2024
1 parent 76f3227 commit e2af2c8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 37 deletions.
26 changes: 10 additions & 16 deletions nostr_dvm/tasks/content_discovery_currently_popular.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async def process(self, request_form):
# if the dvm supports individual results, recalculate it every time for the request
if self.personalized:
return await self.calculate_result(request_form)
# else return the result that gets updated once every scheduled update. In this case on database update.
# else return the result that gets updated once every schenduled update. In this case on database update.
else:
return self.result

Expand All @@ -109,36 +109,27 @@ async def calculate_result(self, request_form):
ns = SimpleNamespace()

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)

database = await NostrDatabase.sqlite(self.db_name)
#cli = ClientBuilder().database(database).signer(signer).opts(opts).build()
#await cli.connect()

# Negentropy reconciliation
# Query events from database
timestamp_hour_ago = Timestamp.now().as_secs() - self.db_since
since = Timestamp.from_secs(timestamp_hour_ago)
timestamp_since = Timestamp.now().as_secs() - self.db_since
since = Timestamp.from_secs(timestamp_since)

filter1 = Filter().kind(definitions.EventDefinitions.KIND_NOTE).since(since)

events = await database.query([filter1])
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
print("[" + self.dvm_config.NIP89.NAME + "] Considering " + str(len(events)) + " Events")
ns.finallist = {}
for event in events:
if event.created_at().as_secs() > timestamp_hour_ago:
if event.created_at().as_secs() > timestamp_since:
filt = Filter().kinds([definitions.EventDefinitions.KIND_ZAP, definitions.EventDefinitions.KIND_REPOST,
definitions.EventDefinitions.KIND_REACTION,
definitions.EventDefinitions.KIND_NOTE]).event(event.id()).since(since)
reactions = await database.query([filt])

if len(reactions) >= self.min_reactions:
ns.finallist[event.id().to_hex()] = len(reactions)
if len(ns.finallist) == 0:
#await cli.shutdown()
return self.result

result_list = []
Expand All @@ -147,12 +138,13 @@ async def calculate_result(self, request_form):
# print(EventId.parse(entry[0]).to_bech32() + "/" + EventId.parse(entry[0]).to_hex() + ": " + str(entry[1]))
e_tag = Tag.parse(["e", entry[0]])
result_list.append(e_tag.as_vec())
#await cli.shutdown()
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:
print("[" + self.dvm_config.NIP89.NAME + "] Filtered " + str(
len(result_list)) + " fitting events.")
# await cli.shutdown()
return json.dumps(result_list)


def post_process(self, result, event):
"""Overwrite the interface function to return a social client readable format, if requested"""
for tag in event.tags():
Expand All @@ -174,6 +166,8 @@ async def schedule(self, dvm_config):
self.last_schedule = Timestamp.now().as_secs()
self.result = await self.calculate_result(self.request_form)
return 1
else:
return 0

async def sync_db(self):
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_LONG_TIMEOUT)))
Expand Down
12 changes: 0 additions & 12 deletions nostr_dvm/tasks/content_discovery_currently_popular_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,8 @@ async def calculate_result(self, request_form):
ns = SimpleNamespace()

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)

database = await NostrDatabase.sqlite(self.db_name)
#cli = ClientBuilder().database(database).signer(signer).opts(opts).build()

#await cli.connect()

# Negentropy reconciliation
# Query events from database
timestamp_since = Timestamp.now().as_secs() - self.db_since
since = Timestamp.from_secs(timestamp_since)

Expand All @@ -157,7 +146,6 @@ async def calculate_result(self, request_form):
if all(ele in event.content().lower() for ele in self.must_list):
if any(ele in event.content().lower() for ele in self.search_list):
if not any(ele in event.content().lower() for ele in self.avoid_list):

filt = Filter().kinds(
[definitions.EventDefinitions.KIND_ZAP, definitions.EventDefinitions.KIND_REACTION,
definitions.EventDefinitions.KIND_REPOST,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

VERSION = '0.6.11'
VERSION = '0.6.12'
DESCRIPTION = 'A framework to build and run Nostr NIP90 Data Vending Machines'
LONG_DESCRIPTION = ('A framework to build and run Nostr NIP90 Data Vending Machines. See the github repository for more information')

Expand Down
18 changes: 10 additions & 8 deletions tests/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,28 @@
global_update_rate = 120 # set this high on first sync so db can fully sync before another process trys to.
use_logger = True

AVOID_PAID_OUTBOX_RELAY_LIST = ["wss://nostrelay.yeghro.site", "wss://nostr.wine", "wss://filter.nostr.wine",
"wss://nostr21.com", "wss://nostr.bitcoiner.social", "wss://nostr.orangepill.dev",
"wss://relay.lnpay.me", "wss://relay.snort.social", "wss://relay.minds.com/nostr/v1/ws",
AVOID_PAID_OUTBOX_RELAY_LIST = ["wss://nostrelay.yeghro.site", "wss://nostr.wine", "wss://filter.nostr.wine", "wss://relay.current.fyi",
"wss://nostr21.com", "wss://nostr.bitcoiner.social", "wss://nostr.orangepill.dev", "wss://brb.io",
"wss://relay.lnpay.me", "wss://relay.snort.social", "wss://relay.minds.com/nostr/v1/ws", "ws://elitedesk:4848",
"wss://nostr-pub.semisol.dev", "wss://mostr.mostr.pub", "wss://relay.mostr.pub", "wss://minds.com",
"wss://yabu.me", "wss://relay.yozora.world", "wss://filter.nostr.wine/?global=all", "wss://eden.nostr.land",
"wss://relay.orangepill.ovh", "wss://nostr.jcloud.es", "wss://af.purplerelay.com", "wss://za.purplerelay.com",
"wss://relay.nostrich.land", "wss://relay.nostrplebs.com", "wss://relay.nostrich.land",
"wss://relay.nostrich.land", "wss://relay.nostrplebs.com", "wss://relay.nostrich.land", "ws://elitedesk.local:4848",
"wss://rss.nos.social", "wss://atlas.nostr.land", "wss://puravida.nostr.land", "wss://nostr.inosta.cc",
"wss://relay.orangepill.dev", "wss://no.str.cr", "wss://nostr.milou.lol", "wss://relay.nostr.com.au",
"wss://puravida.nostr.land", "wss://atlas.nostr.land", "wss://nostr-pub.wellorder.net", "wss://eelay.current.fyi",
"wss://nostr.thesamecat.io", "wss://nostr.plebchain.org", "wss://relay.noswhere.com", "wss://nostr.uselessshit.co",
"wss://bitcoiner.social", "wss://relay.stoner.com", "wss://nostr.l00p.org", "wss://relay.nostr.ro", "wss://nostr.kollider.xyz",
"wss://relay.valera.co", "wss://relay.austrich.net", "wss://relay.nostrich.de", "wss://nostr.azte.co", "wss://nostr-relay.schnitzel.world",
"wss://relay.nostriches.org", "wss://happytavern.co", "wss://onlynotes.lol", "wss://offchain.pub", "wss://purplepag.es", "wss://relay.plebstr.com",
"wss://poster.place/relay", "wss://relayable.org", "wss://bbb.santos.lol", "wss://relay.bitheaven.social", "wss://theforest.nostr1.com",
"wss://relay.nostrati.com", "wss://purplerelay.com", "wss://hist.nostr.land", "wss://creatr.nostr.wine", "ws://localhost:4869",
"wss://poster.place/relay", "wss://relayable.org", "wss://bbb.santos.lol", "wss://relay.bitheaven.social", "wss://theforest.nostr1.com", "wss://at.nostrworks.com",
"wss://relay.nostrati.com", "wss://purplerelay.com", "wss://hist.nostr.land", "wss://creatr.nostr.wine", "ws://localhost:4869", "wss://pleb.cloud", "wss://nos.lol",
"wss://pyramid.fiatjaf.com", "wss://relay.nos.social", "wss://nostr.thank.eu", "wss://inbox.nostr.wine", "wss://relay.pleb.to", "wss://welcome.nostr.wine",
"wss://relay.nostrview.com", "wss://nostr.land", "wss://eu.purplerelay.com", "wss://xmr.usenostr.org", "wss://nostr-relay.app", "ws://umbrel:4848", "wss://umbrel:4848",
"wss://fiatjaf.com", "wss://nostr-relay.wlvs.space", "wss://relayer.fiatjaf.com",
"wss://nostr-01.bolt.observer", "wss://nostr1.tunnelsats.com", "wss://relay.nostr.ch", "wss://relay.nostr.io"
"wss://fiatjaf.com", "wss://nostr-relay.wlvs.space", "wss://relayer.fiatjaf.com", "wss://nostr.yuv.al", "wss://relay.nostr.band", "wss://nostr.massmux.com",
"wss://nostr-01.bolt.observer", "wss://nostr1.tunnelsats.com", "wss://relay.nostr.ch", "wss://relay.nostr.io", "wss://nostr.thank.eu", "wss://nostr.bitcoinplebs.de",
"wss://adult.18plus.social", "wss://bostr.online", "wss://relay.current.fyi", "wss://nosdrive.app/relay", "wss://studio314.nostr1.com", "wss://relay.nostrbr.online"


]

Expand Down

0 comments on commit e2af2c8

Please sign in to comment.