Skip to content

A Twitter bot that posts a random quote from a text file during peak hours, using Python and GitHub Actions.

Notifications You must be signed in to change notification settings

taylorsudo/twitter-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Twitter Bot

A Twitter bot that posts a random quote from a text file during peak hours, using Python and GitHub Actions.

Setup

  1. Create a Twitter/X account for your bot.
  2. Go to Settings and privacy > Account information > Automation, and follow the instructions.
  3. Go to https://developer.twitter.com/ and fill out the form to access the Twitter API.
  4. In the Developer Portal, find your project app under Default project and click App settings.
  5. In the User authentication settings area, click on Set up. Set App permissions to Write and Read, Type of App to Web App and for App info insert your bot’s Twitter profile as the callback URL and website link.
  6. Copy your project's API Key, API Key Secret, Access Token, and Access Token Secret, and store them somewhere safe.
  7. Fork this repository, click on Settings, and on the sidebar go to Secrets and variables > Actions.
  8. Add four repository secrets and paste their respective values:
  • CONSUMER_KEY: Your API Key
  • CONSUMER_SECRET: Your API Key Secret
  • ACCESS_TOKEN: Your Access Token
  • ACCESS_TOKEN_SECRET: Your Access Token Secret
  1. In your GitHub repository, create a .github/workflows directory.
  2. Inside your workflows directory, create a file called action.yml with the following:
name: Schedule Tweet

on:
  schedule:
    - cron: '0 14,2 * * *' # Runs at 9:00 AM and 9:00 PM EST
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Check Out Repository
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: 3.12

      - name: Install Dependencies
        run: pip install -r requirements.txt

      - name: Run Python Script
        env:
            ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
            ACCESS_TOKEN_SECRET: ${{ secrets.ACCESS_TOKEN_SECRET }}
            CONSUMER_KEY: ${{ secrets.CONSUMER_KEY }}
            CONSUMER_SECRET: ${{ secrets.CONSUMER_SECRET }}
        run: python main.py

Finally, create a file in your repository called tweets.txt with a list of tweets you'd like to randomly schedule, separated by lines breaks. You can test your bot by going to Actions > Schedule Tweet > Run workflow.

About

A Twitter bot that posts a random quote from a text file during peak hours, using Python and GitHub Actions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages