Countle

Contact

API

Blog

About

How does the time zone bot work?

Before I tell you how it works, let me tell you a recap what the timezone bot is. /u/timezone_bot is a Reddit bot that parses new posts and comments looking for times with timezones. The bot then tries to make sure that the found time is for today and not for some other date. After that it calculates the difference between the found time and current time. Posts a comment with the time difference and a link to this website where people can see the active countdown.


Using the Reddit API goes through new posts and comments

The timezone bot works by utilizing the Reddit API. The bot goes through every new post and comment that is posted to Reddit, or it tries to. Obviously, the Reddit API has some rate limits so it's not possible to go through every post and comment.


Looks for time and timezone.

The Bot goes through the post title and body looking first for a time and timezone, for this purpose it uses regex. It looks for the most common time formats for example 9 PM CEST. If the bot founds something it tries to parse the time and timezone to verify it really is time. For this it utilizes Python module dateutil and parser. If it returns datetime object everything is good, if not it stops and continues to next post/comment. Also before this, it has made sure that the subreddit is not in the "don't post" list, all subreddits don't want bots and we have to respect that.


Tries to make sure the time is right and happens in the future

Now the time is verified to be a real. Now it's time to make sure the time was meant as event start time or something that could benefit from time zone bot posting a comment. Also, we want that the time happens in the future, it's no use to tell when yesterday happens. For this it for example uses regex to find dates to get a better view when exactly it happens and also looks for some keyword like yesterday.


If everything has passed, it sends the comment

At this point, the found time has passed all the tests and the bot is confident that the time happens in the future and that it would be helpful to tell everyone how long till this time happens. Then it calls the Countle.com API and creates a new countdown. Now everything is ready and it composes the message and finally posts the comment.


You can find more blog posts like this one from here: Blog If you would like to discuss this topic further or want to contact me, you can do so here: info@countle.com