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."}