pull down to refresh
0 sats \ 2 replies \ @onthedeklein 7 Sep \ on: NWC & Twitter (X) integration - Cont'd theoretical proposal bitdevs
I'm glad you're trying to iterate on this, but I'd encourage you to try to understand the code here to see what's incorrect. Have you tried running this yourself? Here are some points that I can tell aren't correct at first glance:
- Your parsing of lightning addresses and lnurls are incorrect. Those regexes don't do what you're trying to do.
- The nostr code here doesn't really make sense. You're not actually sending any payments to an npub by sending an event like that. Are you trying to do a zap to that npub or something? If so, check out the NIP-57 spec.
- I don't think there's a python alby sdk like what is code is trying to use. You'll need to either use pyalby or use some other library to send the payment.
I hope you continue your learning journey on this one. It's a fun project! You just need to scratch a bit deeper below the surface.
Thanks a lot and I appreciate the feedback
I noticed and got ready to post part 3 later on. But since I like your reply, how about you help critique it here before I post it
import tweepy import nostr_client import requests # Twitter API credentials twitter_api_key = "YOUR_API_KEY" twitter_api_secret_key = "YOUR_API_SECRET_KEY" twitter_access_token = "YOUR_ACCESS_TOKEN" twitter_access_token_secret = "YOUR_ACCESS_TOKEN_SECRET" # Nostr Wallet credentials nwc_public_key = "YOUR_NWC_PUBLIC_KEY" nwc_private_key = "YOUR_NWC_PRIVATE_KEY" # Alby credentials alby_url = "(link unavailable)" alby_access_token = "YOUR_ALBY_ACCESS_TOKEN" # Set up Tweepy auth = tweepy.OAuthHandler(twitter_api_key, twitter_api_secret_key) auth.set_access_token(twitter_access_token, twitter_access_token_secret) api = tweepy.API(auth) # Set up Nostr Client nwc_client = nostr_client.Client() nwc_client.connect(nwc_public_key, nwc_private_key) # Set up Alby alby = Alby(alby_url, alby_access_token) def extract_payment_destinations(twitter_username): user = api.get_user(twitter_username) bio = user.description payment_destinations = [] # Extract npub npub_regex = r".*npub[0-9A-Za-z]+" npub_match = re.search(npub_regex, bio) if npub_match: payment_destinations.append(("npub", npub_match.group())) # Extract Alby address alby_regex = r".*[a-zA-Z0-9]{64}" alby_match = re.search(alby_regex, bio) if alby_match: payment_destinations.append(("alby", alby_match.group())) # Extract LNURL lnurl_regex = r".*https://[0-9A-Za-z]+\.lnurl\.io/" lnurl_match = re.search(lnurl_regex, bio) if lnurl_match: payment_destinations.append(("lnurl", lnurl_match.group())) # Extract BOLT12 static address bolt12_regex = r".*lnbc[0-9A-Za-z]+" bolt12_match = re.search(bolt12_regex, bio) if bolt12_match: payment_destinations.append(("bolt12", bolt12_match.group())) return payment_destinations def send_payment(payment_destination): try: if payment_destination[0] == "npub": # Send payment to npub using NWC event = nwc_client.create_event(21, payment_destination[1]) nwc_client.send_event(event) elif payment_destination[0] == "alby": # Send payment to Alby address using Alby API url = f"(link unavailable)" headers = {"Authorization": f"Bearer {alby_access_token}"} data = {"amount": 21, "destination": payment_destination[1]} response = requests.post(url, headers=headers, json=data) if response.status_code != 200: raise Exception(f"Alby API error: {response.text}") elif payment_destination[0] == "lnurl": # Send payment to LNURL using NWC nwc_client.send_payment(payment_destination[1], 21) elif payment_destination[0] == "bolt12": # Send payment to BOLT12 static address using NWC nwc_client.send_payment(payment_destination[1], 21) except Exception as e: print(f"Error sending payment: {e}") def main(): twitter_username = "twitter_username" payment_destinations = extract_payment_destinations(twitter_username) for destination in payment_destinations: send_payment(destination) if __name__ == "__main__": main()
reply
Unfortunately, I think this is actually maybe slightly further from correct.
- The nostr code is still not real or functional.
- The alby code definitely still won't work (and there's no such thing as an "alby address")
- Your parsing of lnurls still doesn't have a valid regex
- Bolt 12 parsing and payments are incorrect here too.
In general, none of these payment methods will work as coded and most of the address extraction doesn't look right. I'm not confident that AI tools will give you functional code for this problem tbh. You may want to put in the extra effort to build this manually if you want something working.
reply