This script is designed to automate the process of tweeting images with a specific hashtag, counting the days since a particular date, and providing a precise duration in years, months, weeks, and days. It's particularly tailored for campaigns or movements that aim to raise awareness over time through social media, specifically Twitter.
- Automated Tweeting: Automatically tweets images from a specified directory with a custom message that includes the total number of days and a formatted duration since a specific start date.
- Image Management: After tweeting an image, it moves the image to a "published" directory to avoid re-posting. If the source directory is empty, it moves all images back from the "published" directory to be tweeted again.
- Precise Duration Calculation: Calculates the exact duration since a specified date in years, months, weeks, and days.
- Twitter API Integration: Uses the Tweepy library for Twitter API integration, allowing for media uploads and tweet posting.
- Python 3.x
- Tweepy library (
pip install tweepy
)
- Twitter Developer Account: You need a Twitter Developer account and a project/app created within it to get your API keys and tokens.
- Install Dependencies: Run
pip install tweepy
to install the necessary Python library. - Configure API Keys: Replace the placeholder values for
consumer_key
,consumer_secret
,access_token
, andaccess_token_secret
in the script with your actual Twitter API credentials.
- Set the Start Date: Modify the
precise_duration_since("07 October 2023")
call in thetweet_image
function to your campaign's start date. - Specify Image Directories: Update the
image_dir
andpublished_dir
variables with the paths to your source and published image directories, respectively. - Run the Script: Execute the script with Python. It will continuously run, tweeting an image every hour. Adjust the
time.sleep(3600)
call at the end of the script if you wish to change the frequency.
- Security: Do not share your API keys and tokens publicly. Keep them secure and private.
- Rate Limits: Be aware of Twitter's rate limits for API usage to avoid getting your account suspended.
- Image Formats: The script currently supports
.png
,.jpg
, and.jpeg
image formats. Ensure your images are in these formats.
This project is open-source and available under the MIT License. Feel free to fork, modify, and use it in your campaigns or projects.
This script is provided as is, without warranty of any kind. Use it at your own risk. The author is not responsible for any consequences arising from its use.
You need to add the proper credentials and folder path in the config.json
{
"consumerKey" : "",
"consumerSecret" : "",
"accessTokenKey" : "",
"accessTokenSecret" : "",
"directory" : "<PATH>>",
"directory_pub" : "PATH",
"sleepTime" : 3600,
"tweetContent" : "#BringThemBackNow"
}