Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a base Flask api script for Twitter #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions b0bot/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from flask import Flask, request
import tweepy

app = Flask(__name__)

# Twitter API credentials
consumer_key = "your_consumer_key"
consumer_secret = "your_consumer_secret"
access_token = "your_access_token"
access_token_secret = "your_access_token_secret"

# Authenticate with Twitter API
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

# Define endpoint for bot
@app.route('/bot', methods=['POST'])
def twitter_bot():
# Get request data
data = request.get_json()

# Extract tweet text from data
tweet = data['tweet']

# Post tweet
api.update_status(tweet)

# Return success message
return {"message": "Tweet posted successfully!"}

if __name__ == '__main__':
app.run(debug=True)
17 changes: 17 additions & 0 deletions b0bot/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
certifi==2022.12.7
charset-normalizer==3.0.1
click==8.1.3
colorama==0.4.6
Flask==2.2.3
idna==3.4
importlib-metadata==6.0.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.2
oauthlib==3.2.2
requests==2.28.2
requests-oauthlib==1.3.1
tweepy==4.12.1
urllib3==1.26.14
Werkzeug==2.2.3
zipp==3.15.0
4 changes: 4 additions & 0 deletions b0bot/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

export FLASK_APP=app.py
flask run