Skip to content

This is a Twitter bot using the Tweepy API that pulls data science tweets through hashtags 1x per day and displayed live through Heroku.

License

Notifications You must be signed in to change notification settings

CVanchieri/TwitterBot

Repository files navigation

Twitter Bot Pulling Data Science Tweets Using Python and AWS Lambda Function

Python License contributions welcome

A simple template you can use to build a twitter bot using Python and an AWS Lambda Function.

Pre-requisites

To build and use the bot, you'll need to:

  1. Register for a twitter developer account
  2. Create a twitter app. Make sure to give it Read and Write permissions.
  3. Set up an AWS account
  4. Create a Lambda Function for your bot
  5. Create a Lambda Layer to use additional libraries in your Lambda Function

How to use

To make your own bot follow these steps:

  1. Clone this repository on your local machine
  2. Create a virtual environment in your project's root directory: python3 -m venv venv && source venv/bin/activate
  3. Install the required libraries using pip: pip install -r requirements.txt
  4. Create a file called .env in the root directory of your project. Put your twitter App keys there:
ACCESS_TOKEN=<YOUR_ACCESS_TOKEN_HERE>
ACCESS_TOKEN_SECRET=<YOUR_ACCESS_TOKEN_SECRET_HERE>
CONSUMER_KEY=<YOUR_CONSUMER_KEY_HERE>
CONSUMER_SECRET=<YOUR_CONSUMER_SECRET_HERE>
  1. Make changes in the logic of the bot by modyifing src/lambda_function.py
  2. Test your changes locally by running python runbot.py from the root directory of your project

How to deploy

Once you are happy with your bot:

  1. Add any additional packages you used to requirements.txt
  2. Run sh createlambdalayer.sh from the root directory of your project. It'll generate a zip file with your libraries called layer.zip
  3. Update your Lambda Layer using layer.zip
  4. Run sh buildpackage.sh from the root directory of your project. It'll make a zip file with the code for your Lambda Function called lambda_function.zip
  5. Upload lambda_function.zip to your Lambda Function
  6. Add your twitter App keys as environment variables in the Lambda Function
  7. Add a scheduled trigger to your Lambda Function using EventBridge

Limitations

Read this before using the bot:

  • This is free unless you go crazy with it or use custom events for triggering the Lambda Function. Check the AWS Free Tier if you have any questions. Use it at your own risk!
  • Current logic is very simple. This bot will search the hashtags set and store them in an AWS RDS database, this is also connected to a flask app for live deployment of the data. live link

Attributions

I personally followed this tutorial here

About

This is a Twitter bot using the Tweepy API that pulls data science tweets through hashtags 1x per day and displayed live through Heroku.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •