From ad1147eebaab10a203fda848add1b504a1e45dee Mon Sep 17 00:00:00 2001 From: dbth <1097224+believethehype@users.noreply.github.com> Date: Wed, 30 Apr 2025 16:40:33 +0200 Subject: [PATCH 1/7] update on this day --- tests/discovery_on_this_day_and_olas.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/discovery_on_this_day_and_olas.py b/tests/discovery_on_this_day_and_olas.py index 85ca207..3ed4173 100644 --- a/tests/discovery_on_this_day_and_olas.py +++ b/tests/discovery_on_this_day_and_olas.py @@ -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", @@ -149,10 +152,9 @@ def playground(): database = asyncio.run(init_db(main_db, wipe=True, limit=main_db_limit, print_filesize=True)) last_year = datetime.date.today().year - 1 - if last_year % 4 == 0 and (last_year % 100 != 0 or last_year % 400 == 0) and datetime.date.today().month < 3: - days = 366 - else: - days = 365 + + days = 365 + # Popular Tweets admin_config = AdminConfig() From 85c362eb1aa1008fddecc12f0e5a6a268d57e911 Mon Sep 17 00:00:00 2001 From: dbth <1097224+believethehype@users.noreply.github.com> Date: Wed, 30 Apr 2025 16:40:55 +0200 Subject: [PATCH 2/7] update on this day --- nostr_dvm/tasks/content_discovery_on_this_day.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nostr_dvm/tasks/content_discovery_on_this_day.py b/nostr_dvm/tasks/content_discovery_on_this_day.py index 117c95d..af9242f 100644 --- a/nostr_dvm/tasks/content_discovery_on_this_day.py +++ b/nostr_dvm/tasks/content_discovery_on_this_day.py @@ -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: From f793b498e47e0ce9e9944d4d54e215b8c88d40f7 Mon Sep 17 00:00:00 2001 From: dbth <1097224+believethehype@users.noreply.github.com> Date: Wed, 30 Apr 2025 16:41:59 +0200 Subject: [PATCH 3/7] update on this day --- tests/discovery_on_this_day_and_olas.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/discovery_on_this_day_and_olas.py b/tests/discovery_on_this_day_and_olas.py index 3ed4173..549cf4f 100644 --- a/tests/discovery_on_this_day_and_olas.py +++ b/tests/discovery_on_this_day_and_olas.py @@ -152,9 +152,10 @@ def playground(): database = asyncio.run(init_db(main_db, wipe=True, limit=main_db_limit, print_filesize=True)) last_year = datetime.date.today().year - 1 - - days = 365 - + if last_year % 4 == 0 and (last_year % 100 != 0 or last_year % 400 == 0) and datetime.date.today().month < 3: + days = 366 + else: + days = 365 # Popular Tweets admin_config = AdminConfig() From a83d6a384ba6d72b21e32e996b88c72af767f9a2 Mon Sep 17 00:00:00 2001 From: dbth <1097224+believethehype@users.noreply.github.com> Date: Sat, 3 May 2025 20:51:46 +0200 Subject: [PATCH 4/7] update zap utils to work with lnbits 1.0.0 This will create wallets on the main account instead of creating a new account per dvm (due to change in user management) --- nostr_dvm/utils/zap_utils.py | 73 +++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/nostr_dvm/utils/zap_utils.py b/nostr_dvm/utils/zap_utils.py index 4ef3a85..5dd4bf4 100644 --- a/nostr_dvm/utils/zap_utils.py +++ b/nostr_dvm/utils/zap_utils.py @@ -4,6 +4,7 @@ import os import random import string import urllib.parse +import uuid from hashlib import sha256 from pathlib import Path @@ -18,6 +19,8 @@ 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 +from bs4 import BeautifulSoup + # tor connection to lnbits # proxies = { # 'http': 'socks5h://127.0.0.1:9050', @@ -134,6 +137,69 @@ def create_bolt11_lud16(lud16, amount): return None + +def create_lnbits_user(name, privkey): + if os.getenv("LNBITS_WALLET_ID") is None or os.getenv("LNBITS_WALLET_ID") == "": + print("No admin id set, no wallet created.") + return "", "", "", "", "failed" + + + publickey = Keys.parse(privkey).public_key().to_hex() + usr = str(uuid.uuid4()) + data = { + "id": usr, + "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_WALLET_ID") == "": + print("No admin id set, no wallet created.") + return "", "", "", "failed" + data = { + 'name': name, + } + try: + json_object = json.dumps(data) + 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") == "": print("No admin id set, no wallet created.") @@ -433,10 +499,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 = "" From aa3b3a1ddea909e6a2b78e94c88598a91ed21dba Mon Sep 17 00:00:00 2001 From: dbth <1097224+believethehype@users.noreply.github.com> Date: Sat, 3 May 2025 20:52:34 +0200 Subject: [PATCH 5/7] Update zap_utils.py --- nostr_dvm/utils/zap_utils.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/nostr_dvm/utils/zap_utils.py b/nostr_dvm/utils/zap_utils.py index 5dd4bf4..79fa2a9 100644 --- a/nostr_dvm/utils/zap_utils.py +++ b/nostr_dvm/utils/zap_utils.py @@ -4,7 +4,6 @@ import os import random import string import urllib.parse -import uuid from hashlib import sha256 from pathlib import Path @@ -19,8 +18,6 @@ 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 -from bs4 import BeautifulSoup - # tor connection to lnbits # proxies = { # 'http': 'socks5h://127.0.0.1:9050', From ad55996601bbf18b2ef41804a07eb92053197981 Mon Sep 17 00:00:00 2001 From: dbth <1097224+believethehype@users.noreply.github.com> Date: Sat, 3 May 2025 20:56:58 +0200 Subject: [PATCH 6/7] Add function to update a dvms lnaddress overwrite a nostdress lnbits backend by just giving the identifier of an existing dvm. this will create a new wallet and guide the lnaddress to that new wallet. --- tests/fix_lnbits_lnaddress.py | 71 +++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/fix_lnbits_lnaddress.py diff --git a/tests/fix_lnbits_lnaddress.py b/tests/fix_lnbits_lnaddress.py new file mode 100644 index 0000000..145bda3 --- /dev/null +++ b/tests/fix_lnbits_lnaddress.py @@ -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() From 80314c16683b64155db66144dfd93f4e3179e0aa Mon Sep 17 00:00:00 2001 From: dbth <1097224+believethehype@users.noreply.github.com> Date: Sat, 3 May 2025 20:58:06 +0200 Subject: [PATCH 7/7] cleanup --- nostr_dvm/utils/zap_utils.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/nostr_dvm/utils/zap_utils.py b/nostr_dvm/utils/zap_utils.py index 79fa2a9..456ab6b 100644 --- a/nostr_dvm/utils/zap_utils.py +++ b/nostr_dvm/utils/zap_utils.py @@ -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', @@ -136,15 +137,15 @@ def create_bolt11_lud16(lud16, amount): def create_lnbits_user(name, privkey): - if os.getenv("LNBITS_WALLET_ID") is None or os.getenv("LNBITS_WALLET_ID") == "": + # 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() - usr = str(uuid.uuid4()) data = { - "id": usr, + "id": name, "email": "string", "username": name, "password": privkey, @@ -173,14 +174,13 @@ def create_lnbits_user(name, privkey): def create_lnbits_wallet(name): - if 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 = { 'name': name, } try: - json_object = json.dumps(data) 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'} @@ -198,11 +198,11 @@ def create_lnbits_wallet(name): 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, }