This is a simple CLI tool to post tweets with optional media attachments using the Twitter API. The tool supports splitting long tweets into multiple parts if necessary and logs the process for better visibility.
- Use the
-a
or--automate
to quickly tweet without having to answer user inputs. Usage:tweet "heres my automated tweet" -a
- pipe
tweet
withat
to schedule tweets for later (only works with tweet automation-a
):Note that this requires installingtweet "Hi from 1 minute to the future" -a | at now + 1 minute
at
: usesudo apt-get install at
- 📷 Post a tweet with text and optional media (with automated use-last-screenshot option).
- ✂️ Automatically split long tweets into multiple parts.
- #️⃣ prompt the user to add hashtags, if forgotten.
- 📝 Log detailed information about the tweet and its comments.
- 🌐 Optionally open the posted tweet in a web browser.
(Tested on Ubuntu 24.04)
- clone the repo
git clone https://github.com/Hadar933/TweetCLI.git
cd tweetcli
- install requirements
pip install -r requirements
- enter X Developer Dashboard , ramp up an App, and create a Consumer Keys, Bearer Token, and Access Token and Secret (under PRojects & Apps -> your app project -> keys and tokens)
- Create a
.env
in the top scope and add the relevant keys:
BEARER_TOKEN=...
ACCESS_TOKEN=...
ACCESS_TOKEN_SECRET=...
CONSUMER_KEY=...
CONSUMER_SECRET=...
- Set an alias: Add the following line to your .bashrc or .bash_profile (using
nano ~/.bashrc
for example to open it):then reload withalias tweet="source /path/to/.venv/bin/activate; python /path/to/tweetcli/tweet.py"
source ~/.bashrc
To use the CLI tool, run the following command: tweet "Your tweet text here" -m path/to/media1 ... path/to/mediaN -u username
(run tweet -h
to see)
positional arguments:
tweet Text content of the tweet
options:
- -h, --help show this help message and exit
- -m path [path ...], --media path [path ...] Path(s) to media file(s) to attach to the tweet
- -v, --verbose Print verbose logging information
- -u USERNAME, --username USERNAME Username of the account to post the tweet to.
- -s SCREENSHOT_PATH, --screenshot_path SCREENSHOT_PATH Path to the screenshots directory, from which the latest image will be fetched when posting (if desired).
- -a, --automatic Automatically post the tweet without asking for confirmation/other inputs.
hadar@laptop:~$ tweet "TweetCLI helps me post 3 times a day without issues. 🎉"
No hashtags found in tweet. Add? [y/n]: y
Enter hashtags separated by commas: python, cli
2024-07-12 19:10:07 | INFO | Tweet Length: 76
2024-07-12 19:10:07 | INFO | Splitting to 1 parts[1 Tweet + 0 Comment(s)].
Tweet:
------
TweetCLI helps me post 3 times a day without issues. 🎉 #python #cli
==================================================
Fetch latest screenshot? [y/n]: y
2024-07-12 19:10:16 | INFO | Latest screenshot file: /example/img.jpg
Post tweet? [y/n]: y
Open tweet in browser? [y/n]: y
This project is licensed under the MIT License - see the LICENSE file for details.