This commit is contained in:
Tobias Baur
2025-08-13 20:50:49 +02:00
4 changed files with 149 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
import json
import os
from datetime import timedelta
from nostr_sdk import Timestamp, Tag, Keys, Options, SecretKey, NostrSigner, NostrDatabase, \
ClientBuilder, Filter, SyncOptions, SyncDirection, LogLevel, Kind, EventId
@@ -30,7 +31,7 @@ class DicoverContentOnThisDay(DVMTaskInterface):
last_schedule: int
db_since = 3600
db_name = "db/nostr_recent_notes.db"
min_reactions = 2
min_reactions = 0
personalized = False
result = ""
@@ -107,7 +108,7 @@ class DicoverContentOnThisDay(DVMTaskInterface):
database = NostrDatabase.lmdb(self.db_name)
timestamp_since = Timestamp.now().as_secs() - self.db_since
timestamp_until = Timestamp.now().as_secs() - (self.db_since - (60+60*24))
timestamp_until = Timestamp.now().as_secs() - (self.db_since - (60*60*24))
since = Timestamp.from_secs(timestamp_since)
until = Timestamp.from_secs(timestamp_until)
@@ -201,6 +202,7 @@ class DicoverContentOnThisDay(DVMTaskInterface):
self.db_since) + " seconds.. this might take a while..")
dbopts = SyncOptions().direction(SyncDirection.DOWN)
await cli.sync(filter1, dbopts)
await cli.fetch_events(filter1, timedelta(10))
await cli.database().delete(Filter().until(since)) # Clear old events so db doesn't get too full.
await cli.shutdown()
if self.dvm_config.LOGLEVEL.value >= LogLevel.DEBUG.value:

View File

@@ -18,6 +18,7 @@ from nostr_sdk import PublicKey, SecretKey, Event, EventBuilder, Tag, Keys, gene
from nostr_dvm.utils.nostr_utils import get_event_by_id, check_and_decrypt_own_tags, update_profile_lnaddress
# tor connection to lnbits
# proxies = {
# 'http': 'socks5h://127.0.0.1:9050',
@@ -134,12 +135,74 @@ def create_bolt11_lud16(lud16, amount):
return None
def create_lnbits_user(name, privkey):
# not working
if os.getenv("LNBITS_ADMIN_KEY") is None or os.getenv("LNBITS_ADMIN_KEY") == "":
print("No admin id set, no wallet created.")
return "", "", "", "", "failed"
publickey = Keys.parse(privkey).public_key().to_hex()
data = {
"id": name,
"email": "string",
"username": name,
"password": privkey,
"password_repeat": privkey,
"pubkey": publickey,
"extensions": [
"string"
],
"extra": {
"email_verified": False,
"first_name": "string",
"last_name": "string",
"display_name": "string",
"picture": "string",
"provider": "lnbits"
}
}
json_object = json.dumps(data)
url = os.getenv("LNBITS_HOST") + '/users/api/v1/user?usr=' + usr
print(url)
headers = {'X-API-Key': os.getenv("LNBITS_ADMIN_KEY"), 'Content-Type': 'application/json', 'charset': 'UTF-8'}
r = requests.post(url, data=json_object, headers=headers, proxies=proxies)
walletjson = json.loads(r.text)
print(walletjson)
def create_lnbits_wallet(name):
if os.getenv("LNBITS_ADMIN_KEY") is None or os.getenv("LNBITS_ADMIN_KEY") == "":
print("No admin id set, no wallet created.")
return "", "", "", "failed"
data = {
'name': name,
}
try:
url = os.getenv("LNBITS_HOST") + '/api/v1/wallet'
print(url)
headers = {'X-API-Key': os.getenv("LNBITS_ADMIN_KEY"), 'Content-Type': 'application/json', 'charset': 'UTF-8'}
r = requests.post(url, json=data, headers=headers, proxies=proxies)
print(r.text)
walletjson = json.loads(r.text)
print(walletjson)
return walletjson['inkey'], walletjson['adminkey'], walletjson['id'], "success"
except Exception as e:
print(e)
print("error creating wallet")
return "", "", "", "failed"
def create_lnbits_account(name):
if os.getenv("LNBITS_WALLET_ID") is None or os.getenv("LNBITS_WALLET_ID") == "":
if os.getenv("LNBITS_ADMIN_KEY") is None or os.getenv("LNBITS_ADMIN_KEY") == "":
print("No admin id set, no wallet created.")
return "", "", "", "", "failed"
data = {
'admin_id': os.getenv("LNBITS_WALLET_ID"),
'admin_id': os.getenv("LNBITS_ADMIN_KEY"),
'wallet_name': name,
'user_name': name,
}
@@ -433,10 +496,13 @@ def make_ln_address_nostdress_manual_lnbits(new_name, invoice_key, npub, nostdre
def check_and_set_ln_bits_keys(identifier, npub):
if not os.getenv("LNBITS_INVOICE_KEY_" + identifier.upper()):
invoicekey, adminkey, walletid, userid, success = create_lnbits_account(identifier)
#invoicekey, adminkey, walletid, walletid, success = create_lnbits_account(identifier)
invoicekey, adminkey, walletid, success = create_lnbits_wallet(identifier)
add_key_to_env_file("LNBITS_INVOICE_KEY_" + identifier.upper(), invoicekey)
add_key_to_env_file("LNBITS_ADMIN_KEY_" + identifier.upper(), adminkey)
add_key_to_env_file("LNBITS_WALLET_ID_" + identifier.upper(), userid)
add_key_to_env_file("LNBITS_WALLET_ID_" + identifier.upper(), walletid)
lnaddress = ""
pin = ""

View File

@@ -40,7 +40,10 @@ RELAY_LIST = ["wss://relay.nostrdvm.com",
SYNC_DB_RELAY_LIST = ["wss://relay.damus.io",
"wss://relay.primal.net",
"wss://nostr.oxtr.dev"
"wss://nostr.oxtr.dev",
"wss://relay.nostrplebs.com",
"wss://relay.nostr.band",
]
SYNC_DB_RELAY_LIST_OLAS = ["wss://relay.damus.io",

View File

@@ -0,0 +1,71 @@
import os
from pathlib import Path
import dotenv
from nostr_dvm.utils.zap_utils import make_ln_address_nostdress, create_lnbits_wallet, add_key_to_env_file
def playground():
# change the idenftier to the dvm you want to update.
# This will create a new lnbits wallet and update the lnaddress to it
# This is for existing dvms
identifier = "discovery_content_gm"
check_and_set_ln_bits_keys_force_new(identifier, os.getenv("DVM_PRIVATE_KEY_BOT_" + identifier.upper()))
def check_and_set_ln_bits_keys(identifier, npub):
if not os.getenv("LNBITS_INVOICE_KEY_" + identifier.upper()):
invoicekey, adminkey, walletid, success = create_lnbits_wallet(identifier)
add_key_to_env_file("LNBITS_INVOICE_KEY_" + identifier.upper(), invoicekey)
add_key_to_env_file("LNBITS_ADMIN_KEY_" + identifier.upper(), adminkey)
add_key_to_env_file("LNBITS_WALLET_ID_" + identifier.upper(), walletid)
lnaddress = ""
pin = ""
if os.getenv("NOSTDRESS_DOMAIN") and success != "failed":
print(os.getenv("NOSTDRESS_DOMAIN"))
lnaddress, pin = make_ln_address_nostdress(identifier, npub, " ", os.getenv("NOSTDRESS_DOMAIN"), identifier)
add_key_to_env_file("LNADDRESS_" + identifier.upper(), lnaddress)
add_key_to_env_file("LNADDRESS_PIN_" + identifier.upper(), pin)
return invoicekey, adminkey, walletid, lnaddress
else:
return (os.getenv("LNBITS_INVOICE_KEY_" + identifier.upper()),
os.getenv("LNBITS_ADMIN_KEY_" + identifier.upper()),
os.getenv("LNBITS_WALLET_ID_" + identifier.upper()),
os.getenv("LNADDRESS_" + identifier.upper()))
def check_and_set_ln_bits_keys_force_new(identifier, npub):
#FORCE UPDATE THE CONFIG; INSTALL NEW WALLET
invoicekey, adminkey, walletid, success = create_lnbits_wallet(identifier)
add_key_to_env_file("LNBITS_INVOICE_KEY_" + identifier.upper(), invoicekey)
add_key_to_env_file("LNBITS_ADMIN_KEY_" + identifier.upper(), adminkey)
add_key_to_env_file("LNBITS_WALLET_ID_" + identifier.upper(), walletid)
lnaddress = ""
if os.getenv("NOSTDRESS_DOMAIN") and success != "failed":
print(os.getenv("NOSTDRESS_DOMAIN"))
lnaddress, pin = make_ln_address_nostdress(identifier, npub, os.getenv("LNADDRESS_PIN_" + identifier.upper()), os.getenv("NOSTDRESS_DOMAIN"), identifier)
add_key_to_env_file("LNADDRESS_" + identifier.upper(), lnaddress)
add_key_to_env_file("LNADDRESS_PIN_" + identifier.upper(), pin)
return invoicekey, adminkey, walletid, lnaddress
if __name__ == '__main__':
env_path = Path('.env')
if not env_path.is_file():
with open('.env', 'w') as f:
print("Writing new .env file")
f.write('')
if env_path.is_file():
print(f'loading environment from {env_path.resolve()}')
dotenv.load_dotenv(env_path, verbose=True, override=True)
else:
raise FileNotFoundError(f'.env file not found at {env_path} ')
playground()