Skip to main content

AI for lazy tweeters

Project description

TweetAI

TweetAI is a Python package that allows you to generate and post tweets using Groq-hosted models. It integrates with the Twitter API for seamless tweet generation and posting, as well as generating paper threads.

Features

  • Generate tweets using Groq-hosted models.
  • Post tweets directly to Twitter.
  • Generate and post paper threads to Twitter.
  • Easy setup with environment variables.

Installation

You can install the package directly from PyPI:

pip install tweetai

Setup

Before using the package, make sure to set up your environment variables for Twitter and Groq:

  1. Create a .env file in your project directory with the following contents:

    TWITTER_KEY=your_consumer_key
    TWITTER_SECRET=your_consumer_secret
    TWITTER_ACCESS_TOKEN=your_access_token
    TWITTER_ACCESS_TOKEN_SECRET=your_access_token_secret
    TWITTER_BEARER=your_bearer_token
    TWITTER_CLIENT_ID=your_client_id
    TWITTER_CLIENT_SECRET=your_client_secret
    GROQ_TOKEN=your_groq_token
    GROQ_MODEL=your_groq_model
    
  2. Install required dependencies (if not already installed):

    pip install tweepy python-dotenv
    

Usage

Here is an example of how to use the Tweetai class to generate tweets and paper threads:

from tweetai import Tweetai
import os
import dotenv

dotenv.load_dotenv()

# Load your Twitter API keys and Groq tokens from environment variables
consumer_key = os.getenv("TWITTER_KEY")
consumer_secret = os.getenv("TWITTER_SECRET")
access_token = os.getenv("TWITTER_ACCESS_TOKEN")
access_token_secret = os.getenv("TWITTER_ACCESS_TOKEN_SECRET")
bearer_token = os.getenv("TWITTER_BEARER")
client_id = os.getenv("TWITTER_CLIENT_ID")
client_secret = os.getenv("TWITTER_CLIENT_SECRET")
groq_token = os.getenv("GROQ_TOKEN")
groq_model = os.getenv("GROQ_MODEL")

# Initialize Tweetai with the required credentials
tweetai = Tweetai(
    bearer_token=bearer_token,
    consumer_key=consumer_key,
    consumer_secret=consumer_secret,
    access_token=access_token,
    access_token_secret=access_token_secret,
    groq_token=groq_token,
    groq_model=groq_model
)

# Generate a tweet and post it to Twitter
tweet = tweetai.generate_tweet()
tweetai.post_tweet(tweet)

# Generate a paper thread and post it to Twitter
thread = tweetai.generate_paper_thread()
tweetai.post_thread(thread)

Running the Script

To run the script, create a Python file (e.g., twitter.py) with the code above. You can execute it directly:

python twitter.py

Automating the Script with Cron

You can also automate running the script periodically using a cron job:

  1. Create a bash script (run_tweetai.sh) to run the Python script:

    #!/bin/bash
    
    # Log the start time
    echo "Cron job started at $(date)" >> /path/to/logfile.log 2>&1
    
    # Activate the virtual environment
    source /path/to/your/virtualenv/bin/activate
    
    # Run the Python script
    python /path/to/twitter.py >> /path/to/logfile.log 2>&1
    
  2. Open the cron job editor:

    crontab -e
    
  3. Add a line to run the script every hour (or any other desired interval):

    0 * * * * /path/to/run_tweetai.sh
    

License

This project is licensed under the terms of the Apache 2.0 License.


### Key Changes:
1. **Installation**: 
   - Users can install the package via `pip install tweetai` from PyPI.
   
2. **Setup**:
   - Guide on setting up the `.env` file for Twitter and Groq credentials.
   
3. **Usage**:
   - Example code on how to use the package for generating tweets and posting them.
   
4. **Running the Script**:
   - Instructions on running the Python script manually or setting it up with cron jobs for periodic execution.

5. **License**:
   - Mentions the Apache 2.0 License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tweetai-0.1.1.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tweetai-0.1.1-py2.py3-none-any.whl (10.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file tweetai-0.1.1.tar.gz.

File metadata

  • Download URL: tweetai-0.1.1.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for tweetai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7e65cc4d88d4e42b8a2c84ba3b76013177ca317b16df93ceb4af9dcb431a5030
MD5 a61d8c0970a6f901df4c63af09002c75
BLAKE2b-256 5bf60ad217a469ec7a25a65a91bdd17ece233d3d7d21370d8d2c03f45a3c0c1b

See more details on using hashes here.

File details

Details for the file tweetai-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: tweetai-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for tweetai-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f832c64228e83ac335c869ad454fad23ed0aec448a6b51cd9ce34e59d5b17fa4
MD5 f93acee671f93c468872eb51cd092a41
BLAKE2b-256 17afe7d6d448e5acaafa51e638289da39a16f54f4bf81c7b2b4c236e1b28caa8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page