NWC & Twitter (X) integration - A theoretical proposal
While tinkering about NWC and twitter I decided to hack a python script that might perhaps begin something good
Here’s a high-level overview of how you could connect your Twitter account to a Nostr Wallet using NWC and automate a 21 satoshi payment for every like:
Prerequisites:
- Twitter Developer Account
- Nostr Wallet with NWC support (e.g., Alby, Nostrify)
- Twitter API credentials (API key, API secret key, Access token, Access token secret)
- Python script with Tweepy (Twitter API library) and nostr-client (Nostr library)
Create a Twitter Developer account and obtain API credentials
Install Tweepy using pip: pip install tweepy
Step 2: Connect Nostr Wallet using NWC
Choose a Nostr Wallet with NWC support (e.g., Alby, Nostrify)
Set up the wallet and obtain the NWC credentials (e.g., public key, private key)
Step 3: Create a Python script
Import Tweepy and nostr-client libraries
Authenticate with Twitter API using Tweepy
Connect to Nostr Wallet using NWC credentials
Define a function to send 21 satoshis for every like
Use Tweepy to stream likes and trigger the payment function
Python
script:
import tweepy
from nostr_client import Client
# 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 NWC credentials
nwc_public_key = "YOUR_NWC_PUBLIC_KEY"
nwc_private_key = "YOUR_NWC_PRIVATE_KEY"
# 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 = Client()
nwc_client.connect(nwc_public_key, nwc_private_key)
# Define payment function
def send_satoshis():
# Create a new Nostr event with 21 satoshis
event = nwc_client.create_event(21)
# Send the event to the Nostr network
nwc_client.send_event(event)
# Stream likes and trigger payment function
class LikeStream(tweepy.StreamListener):
def on_like(self, like):
send_satoshis()
stream = tweepy.Stream(auth, LikeStream())
stream.filter(track=["likes"])
Please note that this is a simplified example and may require additional error handling, security measures, and modifications to work as intended.
originally posted at https://stacker.news/items/673795
Published at
2024-09-05 20:26:50Event JSON
{
"id": "d8a07b10c874e0117542553da748a69d3d3ac8e72b92a0db3cb390457870eea6",
"pubkey": "acc925afdc7964b230915b48fd0b785ab2c85a94502a4ce8b17c7b80db9fb0bb",
"created_at": 1725568010,
"kind": 30023,
"tags": [
[
"d",
"673795"
],
[
"title",
"NWC \u0026 Twitter (X) integration - A theoretical proposal"
],
[
"published_at",
"1725568010"
]
],
"content": "While tinkering about NWC and twitter I decided to hack a python script that might perhaps begin something good\n\n\n\n\n**Here's a high-level overview of how you could connect your Twitter account to a Nostr Wallet using NWC and automate a 21 satoshi payment for every like:**\n\n\n# Prerequisites:\n\n1. Twitter Developer Account\n2. Nostr Wallet with NWC support (e.g., Alby, Nostrify)\n3. Twitter API credentials (API key, API secret key, Access token, Access token secret)\n4. Python script with Tweepy (Twitter API library) and nostr-client (Nostr library)\n\n### Step 1: Set up Twitter API credentials\n\u003e Create a Twitter Developer account and obtain API credentials\n\u003e Install Tweepy using pip: pip install tweepy\n\n\n### Step 2: Connect Nostr Wallet using NWC\n\n\u003e Choose a Nostr Wallet with NWC support (e.g., Alby, Nostrify)\n\u003e Set up the wallet and obtain the NWC credentials (e.g., public key, private key)\n\n### Step 3: Create a Python script\n\n\u003e Import Tweepy and nostr-client libraries\n\u003e Authenticate with Twitter API using Tweepy\n\u003e Connect to Nostr Wallet using NWC credentials\n\u003e Define a function to send 21 satoshis for every like\n\u003e Use Tweepy to stream likes and trigger the payment function\n\n\n`Python` script:\n\n```\nimport tweepy\nfrom nostr_client import Client\n\n# Twitter API credentials\ntwitter_api_key = \"YOUR_API_KEY\"\ntwitter_api_secret_key = \"YOUR_API_SECRET_KEY\"\ntwitter_access_token = \"YOUR_ACCESS_TOKEN\"\ntwitter_access_token_secret = \"YOUR_ACCESS_TOKEN_SECRET\"\n\n# Nostr Wallet NWC credentials\nnwc_public_key = \"YOUR_NWC_PUBLIC_KEY\"\nnwc_private_key = \"YOUR_NWC_PRIVATE_KEY\"\n\n# Set up Tweepy\nauth = tweepy.OAuthHandler(twitter_api_key, twitter_api_secret_key)\nauth.set_access_token(twitter_access_token, twitter_access_token_secret)\napi = tweepy.API(auth)\n\n# Set up Nostr Client\nnwc_client = Client()\nnwc_client.connect(nwc_public_key, nwc_private_key)\n\n# Define payment function\ndef send_satoshis():\n # Create a new Nostr event with 21 satoshis\n event = nwc_client.create_event(21)\n # Send the event to the Nostr network\n nwc_client.send_event(event)\n\n# Stream likes and trigger payment function\nclass LikeStream(tweepy.StreamListener):\n def on_like(self, like):\n send_satoshis()\n\nstream = tweepy.Stream(auth, LikeStream())\nstream.filter(track=[\"likes\"])\n\n\n```\n\n\n##### _Please note that this is a simplified example and may require additional error handling, security measures, and modifications to work as intended._\n\noriginally posted at https://stacker.news/items/673795",
"sig": "79b85b3c0499b1a5e0fbe24bcaee58a406a9f38ae75c4bbf71f6411bc9882d590e6e474d9535b827ce1385134f3a302b77635507e4729ccbe3adcea6e0fba6da"
}