Skip to content

Instantly share code, notes, and snippets.

@jeremyikwuje
Created July 22, 2023 14:29
Show Gist options
  • Save jeremyikwuje/0e391771dfc9600cda248e68923ce87a to your computer and use it in GitHub Desktop.
Save jeremyikwuje/0e391771dfc9600cda248e68923ce87a to your computer and use it in GitHub Desktop.
A twitter bot script to tweet the price of Bitcoin. You can find the full article to this code on.
from fastapi import FastAPI
import tweepy
import random
# credentials to access Twitter API
API_KEY="YOUR_API_KEY_HERE"
API_KEY_SECRET="YOUR_API_KEY_SECRET_HERE"
BEARER_TOKEN="YOUR_BEARER_TOKEN_HERE"
ACCESS_TOKEN="YOUR_ACCESS_TOKEN_HERE"
ACCESS_TOKEN_SECRET="YOUR_ACCESS_TOKEN_SECRET_HERE"
# create an OAuthHandler instance
client = tweepy.Client(
BEARER_TOKEN,
API_KEY,
API_KEY_SECRET,
ACCESS_TOKEN,
ACCESS_TOKEN_SECRET,
)
# tweet the price of Bitcoin
def tweet_bitcoin_price():
price = random.randint(28000, 35000)
tweet = f"1 Bitcoin is {price} USD"
client.create_tweet(text=tweet)
app = FastAPI()
# web server function
@app.get("/")
async def root():
tweet_bitcoin_price()
return {"message": "Tweeted the price of bitcoin."}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment