Feeding Students! | Free Food API

Free food on campus. Right now.
The simple HackMIT project revisited! This time with a more robust algorithm and better update rate, the Free Food API provides real-time data about availability of free food across the campus at MIT.

Back in September I’ve built a small “free food alert” device with some friends during the HackMIT hackathon. Since then, the idea to improve that system stuck around in my head, until it started to slowly be developed in the last two months. For the most part, I wanted to complete this project to get some experience with email parsing, databases, servers, and http requests. Overall it was a lot of fun to create a tool I can actually use now🎉

Let’s dive right in and take a look behind the scenes!
In general, the API provides users with a JSON object that looks like that:

{"data": [

{“food”: [], “room”: “4-315”, “time”: “2018-08-07 13:12:19”},

{“food”: [“bbq”], “room”: “kresge”, “time”: “2018-08-07 13:05:33”},

{“food”: [“chicken”, “potato”], “room”: “La Sala de Puerto Rico”, “time”: “2018-08-07 07:42:07”}]



(It can be accessed in this link)

This is what I wanted to achieve in the past few months, and now it’s here, yay! Each one of the entries in the list, which is the value of data in the JSON object, contains information about a certain “food event”. The information contained in each event includes the location of the food, its type, and a timestamp. The API only exposes the 3 most recent database entries, though the rest are safely stored in the dungeons of the internet, waiting to be used in some cool statistics project in the future, when they will become a big enough data set.
In the hardware device I made, only the single most recent “food event” is shown. All of the above are extracted/generated in this process:

Food API Workflow

As described, the data in this JSON object its entirety is fetched from the free food mailing list. Even though any member of the list can just check his email and know where the food is, I thought that coding some algorithms that would parse out room numbers from the emails would be lots of fun! And also, a centralized location in which a user could view all the information is also pretty convenient 🙂

After about 3 cycles of development, I ended up with the current solution, where I use RegEx to look up a commonly used room number structure in the emails. It ended up actually being pretty simple, and pretty reliable so far too! You may wonder what happens if the RegEx matching function fails to find any room number, and rightfully so! In that case, another function will iterate through a list of  “special rooms” that might have been included in their non-standardized form. A match between the email’s text suggests that this room name contains food.

The food-type parser works in a similar way. A long list of foods is being compared to the email’s body. Any match between a food type keyword and the message is being added to the “food” item in the API’s output.

And the timestamp, is, well, a timestamp. EXCITING. I know.

Even though it’s really interesting, I will not describe the program in more detail. I wanted to illustrate the general workflow, and the whole chunk of code can actually be found on my gitHub page!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s