Last month I wrote a telegram bot: Choke(@getAqiBot. I need to create a datetime object from a string of hour and minute, then add time zone information to it and finally convert it to UTC time zone.
strftime() function converts datetime object to string. On the contrary, striptime() converts a string to a datetime object1. Note that we need to add today’s year, month and day, otherwise Python will use January 1, 1900. And that will give us an inaccurate result when we convert time zones later.
We can use pytz’s localize() function to localize datetime object.
Using astimezone() function to convert Paris time zone to UTC. Because I hosted the bot on Heroku, and Heroku uses UTC.
Finally, using time() function to get time object.
I didn’t notice that free Heroku dynos sleep after thrity minutes of inactivity2, so most daily notifications will never send. You can upgrade to Hobby or try Kaffeine.