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💓💓
extract_payment_destination
was mostly what was missing before. Glad you figured that out!