Sign in

Adding expiration to TripCaster

One feature I wanted in TripCaster was the ability to save a trip’s forecast and return to it quickly, without having to enter in the entire trip’s itinerary again. This was why I decided to have the user’s input stored in a query string. So if you went on a 2 day trip to Rome, the querystring would contain “&cities=Rome&cities=Rome”. The idea was that the user could copy the entire URL of the results page then later come back to that same URL to get the same information.

This didn’t work in the initial release however, as the app would take the cities listed in the query string and create a brand new report based on today’s date.

An intuitive solution would be to just use a database and store all generated reports there, but I wanted to keep TripCaster ‘lightweight’.

First we should store the date the report was generated on. This was fairly easy to do with the standard libraries of Python and JavaScript. Get new Date() to get the time elapsed since epoch (Jan 1 1970) in milliseconds, and pass it onto the querystring for the results URL that you can save for later. Whenever someone tries to load the results page, the backend will check the current time using Python’s time.time() and compare it to the value in the querystring. We calculate the number of days difference (rounding down) and call this the days offset.

At first I tried to do the date adjustment on the front end. I figured that we would get a list of the reports, and for each day offset, we would remove a report from the front of the list. When I was nearly finished with the solution I realized that this wouldn’t work as the data in the reports would not be correct. Doing this would show future weather forecasts as closer to the present. I realized that I would have to fix things in the code that called the API, and tell it to change the days to look up according to the day offset.

On pythons end it saves the query string to a variable, calculates the day offset , and for each day offset it would remove a city from the front of the string variable. It would then send this modified string to the results page and give the user the proper weather.

I’m Lucas