{"id":50741399,"url":"https://github.com/akshayxml/autotweet","last_synced_at":"2026-06-10T17:03:36.584Z","repository":{"id":349078498,"uuid":"992670702","full_name":"akshayxml/autotweet","owner":"akshayxml","description":"Let AI automatically generate and post tweets to X for you, with an optional ntfy-based mobile confirmation step.","archived":false,"fork":false,"pushed_at":"2026-04-20T03:14:45.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-20T05:18:28.102Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akshayxml.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-05-29T14:26:09.000Z","updated_at":"2026-04-20T03:14:49.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/akshayxml/autotweet","commit_stats":null,"previous_names":["akshayxml/autotweet"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/akshayxml/autotweet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akshayxml%2Fautotweet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akshayxml%2Fautotweet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akshayxml%2Fautotweet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akshayxml%2Fautotweet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akshayxml","download_url":"https://codeload.github.com/akshayxml/autotweet/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akshayxml%2Fautotweet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34161284,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-10T17:03:35.765Z","updated_at":"2026-06-10T17:03:36.575Z","avatar_url":"https://github.com/akshayxml.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AutoTweet\n\nAutoTweet is a Python application that leverages the Llama 3 language model to generate technical tweets on various topics. It integrates with `ntfy.sh` for a push notification-based confirmation workflow before posting to X (formerly Twitter). \n\n## Table of Contents\n\n- [Features](#features)\n- [How it Works](#how-it-works)\n- [Setup](#setup)\n- [Usage](#usage)\n- [Configuration](#configuration)\n- [Dependencies](#dependencies)\n- [Running as a Systemd Service (Linux)](#running-as-a-systemd-service-linux)\n- [Contributing](#contributing)\n\n## Features\n\n*   **Automated Tweet Generation:** Uses the `meta-llama/Meta-Llama-3-8B-Instruct` model to create concise technical tweets.\n*   **X Integration:** Posts approved tweets directly to your X account.\n*   **Notification-based Confirmation:**\n    *   Sends a push notification via a self-hosted or public `ntfy.sh` server to your device.\n    *   Allows you to \"Approve ✅\" or \"Discard ❌\" the tweet directly from the notification.\n*   **Direct Posting Option:** A command-line argument (`--force-post`) allows bypassing the confirmation step for direct posting\n*   **Configurable Topics:** Easily customize the list of topics for tweet generation.\n*   **Quantization Support:** Supports 4-bit quantization using `bitsandbytes` to reduce memory usage on both CPU and GPU.\n\n## How it Works\n\n1.  **Model Loading:** The Llama 3 model and tokenizer are loaded from Hugging Face.\n2.  **Topic Selection:** A random topic is chosen from a predefined list.\n3.  **Tweet Generation:** A prompt is constructed, and the Llama 3 model generates a short technical tweet (under 280 characters) about the selected topic.\n4.  **Confirmation Request:** Unless `--force-post` is used, a notification with action buttons is sent to your configured `ntfy.sh` topic. The script then listens on the response topic for your decision. If `ntfy.sh` environment variables are not correctly set, the script will raise an error.\n5.  **Action Based on Confirmation:**\n    *   **Approve:** The tweet is posted to X.\n    *   **Discard:** The tweet is not posted.\n6.  **Termination:** After sending the notification and receiving a response (or timing out), the script exits. It does not loop internally.\n\n## Setup\n\n1.  **Clone the Repository:**\n    ```bash\n    git clone https://github.com/akshayxml/autotweet.git\n    cd autotweet\n    ```\n\n2.  **Install Dependencies:**\n    Make sure you have Python 3.x installed.\n    It's highly recommended to create and activate a virtual environment first:\n    ```bash\n    python3 -m venv venv\n    source venv/bin/activate  # On Windows use `venv\\Scripts\\activate`\n    ```\n    Then, install the required packages:\n    ```bash\n    pip install -r requirements.txt\n    # For CUDA support with PyTorch, ensure your PyTorch installation matches your CUDA version.\n    # See: https://pytorch.org/get-started/locally/\n    ```\n\n3.  **Hugging Face Login/Token:**\n    To download and use the Llama 3 model, you need to:\n    *   Accept the Llama 3 license on its Hugging Face model card.\n    *   Log in via the Hugging Face CLI:\n        ```bash\n        huggingface-cli login\n        ```\n    *   Alternatively, you can set the `HF_TOKEN` environment variable with your Hugging Face access token.\n\n4.  **Environment Variables:**\n    Create a `.env` file in the project root by copying the provided `.env.example` file (`cp .env.example .env`) and then fill in your actual values. Alternatively, you can set these environment variables directly in your system.\n\n\n    *   **X API Credentials (Required):**\n        ```\n        X_CONSUMER_KEY=\"your_consumer_key\"\n        X_CONSUMER_SECRET=\"your_consumer_secret\"\n        X_ACCESS_TOKEN=\"your_access_token\"\n        X_ACCESS_TOKEN_SECRET=\"your_access_token_secret\"\n        X_BEARER_TOKEN=\"your_bearer_token\"\n        ```\n\n    *   **ntfy.sh Configuration (Required, unless using `--force-post`):**\n        ```\n        NTFY_SERVER=\"https://ntfy.sh\" # Optional, defaults to public ntfy.sh. Use your own if self-hosting.\n        NTFY_CONFIRM_TOPIC=\"your_unique_confirm_topic_name\" # e.g., autotweet_confirm_myuser\n        NTFY_RESPONSE_TOPIC=\"your_unique_response_topic_name\" # e.g., autotweet_response_myuser\n        ```\n        *Note: Ensure `NTFY_CONFIRM_TOPIC` and `NTFY_RESPONSE_TOPIC` are unique and private to you if using the public `ntfy.sh` server.*\n\n    *   **Hugging Face Token (Optional, if not using `huggingface-cli login`):**\n        ```\n        HF_TOKEN=\"your_hugging_face_read_token\"\n        ```\n\n## Usage\n\n1.  Ensure all prerequisites and environment variables are set up.\n2.  Run the main script: \n    * **With ntfy.sh confirmation (default):**\n        Make sure your `ntfy.sh` environment variables are set.\n        ```bash\n        python main.py\n        ```\n    *   **To skip confirmation and post directly:**\n        ```bash\n        python main.py --force-post\n        ```\n3.  The script will start generating tweets.\n4.  If not using `--force-post`, subscribe to your `NTFY_CONFIRM_TOPIC` on your phone/device using the ntfy app or web client. You will receive notifications to approve, reject, or regenerate tweets.\n\n## Configuration\n\nYou can modify the following in `main.py`:\n\n*   `LLAMA3_MODEL_NAME`: Change the Llama 3 model variant if needed (ensure compatibility).\n*   `topics`: Add or remove topics for tweet generation.\n    ```python\n    topics = [\n        \"kubernetes\", \"docker\", \"c++\", \"golang\", \"java\", \"nodejs\", \"redis\",\n        \"python\", \"system design\", \"data structures and algorithms\",\n        \"operating system\", \"computer networking\", \"databases\", \"kafka\", \"javascript\"\n    ]\n    ```\n\n## Dependencies\n\nAll Python dependencies are listed in `requirements.txt`. The main dependencies include:\n*   `transformers`: For interacting with Hugging Face models.\n*   `torch`: The deep learning framework used by the model.\n*   `tweepy`: For interacting with the X API.\n*   `requests`: For making HTTP requests (e.g., to ntfy.sh).\n*   `python-dotenv`: For managing environment variables from a `.env` file.\n\n## Running with Systemd (Linux)\n\nTo run AutoTweet automatically every day, you can set it up with a systemd service and timer.\n\n1.  **Create the Service and Timer files:**\n\n    Create `autotweet.service` and `autotweet.timer` files (templates are provided in the repository) and copy them to `/etc/systemd/system/`.\n\n    **autotweet.service**\n    Make sure to adjust `User`, `WorkingDirectory`, and `ExecStart` paths to match your setup.\n    ```ini\n    [Unit]\n    Description=Run AutoTweet once\n    After=network.target\n\n    [Service]\n    Type=oneshot\n    User=your_username\n    WorkingDirectory=/path/to/your/autotweet_project\n    ExecStart=/path/to/your/autotweet_project/venv/bin/python3 /path/to/your/autotweet_project/main.py\n    ```\n\n    **autotweet.timer**\n    This configures the script to run daily at 10:00 AM.\n    ```ini\n    [Unit]\n    Description=Run AutoTweet daily\n\n    [Timer]\n    OnCalendar=*-*-* 10:00:00\n    Persistent=true\n\n    [Install]\n    WantedBy=timers.target\n    ```\n\n2.  **Enable and start the timer:**\n\n    ```bash\n    sudo systemctl daemon-reload\n    sudo systemctl enable --now autotweet.timer\n    ```\n\n3.  **Check the status:**\n\n    You can check the status of the timer using:\n\n    ```bash\n    sudo systemctl status autotweet.timer\n    ```\n\n    And check when it was last run and when it will run next:\n    ```bash\n    systemctl list-timers --all | grep autotweet\n    ```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a pull request or open an issue.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakshayxml%2Fautotweet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakshayxml%2Fautotweet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakshayxml%2Fautotweet/lists"}