To facilitate the management of a parody bell tower Twitter/X account I run, I developed a script and used a cron scheduler to streamline the processes.
The cron scheduler is straightforward. It runs a python file every hour that creates the post and uses Tweepy and the Twitter API to send the tweet. The entire project also utilized a sandbox Twitter account during development before deploying to live.
Tweet Creation Script
The script is more interesting since it has to create a tweet appropriate for the current time. For example, at 4pm, it might tweet “BONG BONG BONG BONG”. Scheduling this alone would be trivial. However, Twitter prevents duplicate posts. To work around this, different variants have to be created. These variants are mixed and matched to create unique tweet formats that change every 12 hours. Some examples of those variants include –
- Clock emojis for each time (ex – )
- Various symbol and emoji combinations related to bells (ex – )
- ASCII art clocks
- Different capitalizations of “BONG” or “DONG”
- Turning words into #hashtags
- Changing dividers from spaces to “…” or newlines
- Holiday-specific emojis (ex – for Christmas or for certain US holidays)
- Appending the date and time (I know this alone would make each tweet unique, but the other variations add character to the account)
The script also has to make decisions about the current date and time for certain tweets. For example, it can’t just use the current time alone because the server may be in a different time zone (or change time zones) and if it runs milliseconds before the top of the hour, the current hour will be incorrect for the tweet. Additionally, some US holidays like Thanksgiving and Memorial Day don’t fall on the same date each year. So, additional logic had to be added to customize tweets for those days.