istheweatherweird/itww_bot

Double check that I'm handling time zones right

Closed this issue · 12 comments

@potash maybe you could help me make sure all my time zones are in line. The NWS uses UTC for its timestamps, right?

Other assumption: Defining a day as 6pm-6pm Chicago time means that I only need to pull the UTC sheet from the current day, as the timezone offset is 6 hours.

dang! good point!

time zones are truly the hardest problem in computer science

Sorry I now see your question about whether NWS uses UTC. The NWS uses timestamps in two places: the start and end params of URL of the request you make and in its response. The response timestamps look like this: 2020-02-21T17:51:00+00:00note the +00:00 this is the UTC offset, which is zero, so it is in UTC. If you use this format (whatever ISO it is, its probably the default string format for a pandas Timestamp?) for the start and end params the timezone is always explicit so there should be no issues.

So you do everything in UTC except when printing the date in the tweet (if you do this?). At that point you use the America/Chicagotimezone (which includes daylight savings when appropriate) in your date format call. This is how we do it on the website and it should be pretty error free.

Gotcha. I noticed and like this general principle of keeping everything in UTC times other than what's printed out to the user!

To that end, maybe it makes sense to think in these terms: instead of 6pm-6pm CT, this bot is simply looking at 12am-12am UCT each day. That means that we don't have to worry about daylights savings, and it syncs beautifully with the Heroku scheduler, which I'm using the time the tweets right now. It currently runs every day at 12am UTC and looks at the last 24 hours of data. It means that it will tweet at a different local time depending on whether or not it's daylight savings, but I'm not too bothered by that. Wdyt?

I've been thinking about how to best extend this for other cities too! It's set up to be easily extended for any place in the stations.csv file.

I think the best way to organize that will be a different Heroku app using this same repo for each bot. CITY can be defined in a Heroku environment variable instead of here, meaning that the process of setting up a new bot will be making the Twitter account, generating the necessary API keys (these things, which I believe need to be unique to each Twitter account), and setting up a new app in Heroku with the necessary scheduled job.

Which is all to say that I think your idea of checking every hour to see if it's 6pm local time makes a lot of sense. The tricky part for me is making sure I'm pulling in the historical data right, time zone wise, so let me give it a shot and then it'd be great if you could check my handling.

Are you imagining that the same Twitter account would handle multiple cities, or are we still talking about backend setup?