This GitHub repository hosts a Python script that enables automated daily tweeting on X (formely Twitter). The script uses the Tweepy library to access the Twitter API v2. It allows users to schedule daily (or any desired frequency) tweets, which you compiled before.
- Clone or download the repository.
- Add your Twitter API credentials and quotes to the script.
- Change the csv file to add your content
- Set up a scheduler (as below) to run the script at your desired time each day.
- Set
user_name
and change path variables atsystemctl_scripts/automate_tweet.service
accordingly. - Copy
automate_tweet.service
file andautomate_tweet.timer
file to/etc/systemd/system/
i.e run$ sudo cp systemctl_scripts/automate_tweet.* /etc/systemd/system/
- Reload the systemctl daemon
sudo systemctl daemon-reload
- Start the timer
sudo systemctl enable automate_tweet.timer --now
If you need to see the status, you can check it using sudo systemctl status automate_tweet.timer
or sudo systemctl status automate_tweet.service
In case you need to stop the service, use sudo systemctl stop automate_tweet.timer
If you need to see the logs, use journalctl -f -u automate_tweet.service --since '2024-02-14'
- Set up a
Python App
calledtweet_app
withpython3.8
. For URL also you can addtweet_app
, or any other appropriate name. Remember the path of the new app (usually it looks like/home/<user_name>/virtualenv/tweet_app/3.8/bin/python3
). - Add a
Cron Job
to run each day (or any other frequency you need) with/home/<user_name>/virtualenv/tweet_app/3.8/bin/python3 /home/<user_name>/tweet_app/send_tweet.py
as the command (the first part is the path to the Python app we created above and the second part is the path to our python script). For example, the final command will look like this0 0 * * * /home/<user_name>/virtualenv/tweet_app/3.8/bin/python3 /home/<user_name>/tweet_app/send_tweet.py
To understand more about Cron Jobs, read this.
For a live demo, please check my profile We Choose Joy.
Enjoy!