pull down to refresh

Having gathered attention from the previous post (#673795), there's been genuine critics and I've gone back to the drawing board(Meta's AI) to re-tinker and it provides a probable way of getting a lightning destination
import tweepy import nostr_client from alby import Alby # 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_destination(twitter_username): """ Extracts payment destination (npub, lightning address, or lnurl) from user's Twitter bio """ user = api.get_user(twitter_username) bio = user.description payment_destinations = [] # Check for 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())) # Check for lightning address lightning_regex = r"lnbc[0-9A-Za-z]+" lightning_match = re.search(lightning_regex, bio) if lightning_match: payment_destinations.append(("lightning", lightning_match.group())) # Check for 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())) return payment_destinations def send_payment(payment_destination): """ Sends payment to extracted destination """ if payment_destination[0] == "npub": # Create Nostr event with npub event = nwc_client.create_event(21, payment_destination[1]) nwc_client.send_event(event) elif payment_destination[0] == "lightning": # Use Alby to send Lightning payment alby.send_payment(payment_destination[1], 21) elif payment_destination[0] == "lnurl": # Handle LNURL payment (not implemented) pass def main(): # Replace with your desired Twitter username twitter_username = "twitter_username" payment_destinations = extract_payment_destination(twitter_username) for destination in payment_destinations: send_payment(destination) if __name__ == "__main__": main()
Please replace the YOUR_API_KEY, YOUR_API_SECRET_KEY, YOUR_ACCESS_TOKEN, YOUR_ACCESS_TOKEN_SECRET, YOUR_NWC_PUBLIC_KEY, YOUR_NWC_PRIVATE_KEY, and YOUR_ALBY_ACCESS_TOKEN placeholders with your actual credentials.
Also critics are welcome💓💓
420 sats \ 22 replies \ @k00b 7 Sep
extract_payment_destination was mostly what was missing before. Glad you figured that out!
reply
Thank you @k0ob
How far from the realm of reality do you think this is?
reply
80% away from reality: you have some non-operational code that looks conceptually okay.
reply
Have you used unleased.chat to import github repos
That's the problem I was trying to solve before going down this rabbit hole
reply
I don't use much AI outside of Github Copilot, but I've been wanting to try Cursor. We have some people in Pleb Lab that have managed to do a lot with it.
reply
There's also twinny for vs code.
This is a great idea. I'm looking forward to seeing this evolve.
reply
You find it 😮
reply
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.
reply
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