Foodler Delivery Reminder Google Apps Script
If you order food online using Foodler.com, you know that you need to check your email for the delivery estimate of when your food is expected to arrive (sent shortly after placing an order).
If you use Foodler frequently enough, you'll realize that the predictions aren't that great; they usually compensate to ensure that my expectations are set to 15 minute longer than it would usually take. Regardless of the estimations, though, wouldn't it be nice to have a calendar reminder for when your order is supposed to arrive (so that you effectively don't have to go fish into your email for the order info)?
I decided to whip together a little Apps Script to help with this. The script itself looks at your Gmail emails, look for those that are from [email protected], parses out the relevant information for the order, i.e. total price, tip paid, restaurant, phone number, date the order was placed, to whom it was placed, and of course, when the delivery should have arrived, and creates reminders in your Google Calendar.
The script performs two cron operations (via 'triggers'). The first checks gmail to see if a new email has come through from foodler. If orders have come in, then we must flag them as needing 'notifications to be created' for that order. The second, looks to see if any orders have been flagged, and if so, two calendar events are created:
The order from when it was placed to when it will arrive, spanning the entire duration, without an alert
An alert for the time that Foodler estimated arrival
The script as it is today, is essentially the first part of what I think could be a valuable tool. Ideally, I'd be able to follow up with the script and provide information about when the food actually arrived, allowing me to perform some math to predict the arrival of future deliveries. If everyone was using said script, imagine the analysis that one can perform to more accurately determine when your food will arrive. Moreover, you can tie in traffic information based on your location vs. the restaurant, making the system pretty interesting.
Anyhow, Apps Script is an extremely interesting platform, and I came away with my 8 hours hacking on it with some tips/feedback:
One can parse HTML as XML and essentially extract particular nodes using a pseudo-xpath expression and performing an eval on the XMLDoc. i had to visually traverse the tree to ensure i was extracting the right nodes.
Triggers are constantly running, so make sure that while you're in dev mode you don't have them set too frequently (otherwise your logs may get clobbered eventually leaving you confused with why there's hardly anything in your logs)
HTML output is not standard html output - the HTML is preprocessed by Google Caja, so don't expect to be able to import just any library.. so i had to go to a more rudimentary solution for building the html for the webapp view
When performing a query on ScriptDb, you can perform a sort and pass in the sortStrategy, which if you're dealing with numeric data in string form, allows you to specify db.NUMERIC as the strategy. awesome.
If you're in the process of executing a script, and you perform any operation like saving the document, the notification allowing you to cancel or dismiss a running function is lost
Debugging large objects in the AppsScript console is a bit painful for the time being. Use the logger or write out to a google doc.
if you're debugging triggers, set the notifications to be sent immediately. this allows you to sort of debug any issues that may be occurring in those cron jobs
I gave a lightening talk presentation at the Boston Google Developers Group after +Arun Nagarajan gave an awesome presentation on the platform. Here's a link to the presentation: http://ntikku.appspot.com/p/GAS_Foodler_Delivery_Reminder/
I also posted the project on GitHub, so feel free to check it out. https://github.com/nirvanatikku/foodler_delivery_reminder
Moreover, if you use Foodler, install the script! Available in the Chrome Web Store.












