Giter VIP home page Giter VIP logo

drainedbot's Introduction

Twitter Bot Using Python and AWS Lambda

This is a simple template you can use to build a twitter bot that tweets fake lyrics from your favorite musician using web scraping, Markov Chaining, Python and an AWS Lambda Function. I used it to create @dg_unreleased. This is adapted from Dylan Castillo's wonderful tutorial which you should check out here.

Pre-requisites

To build and use the bot, you'll need a few things:

  1. Register for a twitter developer account
  2. Get genius api keys
  3. Generate genius access token
  4. Have Docker installed
  5. Have Python 3.8 or higher installed
  6. Create a twitter app
  7. Make sure to give it Read and Write permissions.
  8. Set up an AWS account
  9. Create a Lambda Function for your bot
  10. Create a Lambda Layer to use additional libraries in your Lambda Function

-you can do 8 and 9 later DEFINITELY read thru Dylan's tutorial on his site it does an excellent breakdown of the steps for deployment

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. edit lyric_scrape.py adding your genius access token where it says YOUR-TOKEN-HERE
  2. modify lyric_scrape.py to get your fave musicians lyrics by changing the artist name and song count on the last line in the file
  3. run lyric_scrape.py to produce a txt file with all the scraped lyrics. You will want to get a lot of songs so you have diversity in the lyrics.
  4. once you have the lyrics copy and paste them into the src/lyrics.txt file replacing the lyrics already there.
  5. Test your changes locally by running python entrypoint.py from the root directory of your project

How to deploy

Once you are happy with your bot:

time to look at Dylan's walkthru deployment!

  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 this will take a while!
  3. Create a Lambda Layer by uploading the generated 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. Create a lambda function by uploading lambda_function.zip
  6. Add your twitter App keys as environment variables in the Lambda Function
  7. Add a scheduled trigger to your Lambda Function using EventBridge

Attributions

The createlambdalayer.sh script comes from this repository.

drainedbot's People

Contributors

syntaxshawty avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.