Data Standards, Restaurant Scores, SMS and 50 Lines of Code

We can all agree that we are at the early stages of governments publishing open data in accordance with data standard specifications.  The value of data standards are well documented and this is not a post that is intended highlight these.  The fact is that currently only a small number of governments are participating in data standard adoption to date – one explanation for this is that the potential benefits of doing so are not always clear.

Accela is a big supporter of open data standards and we are continually engaging our customers in opportunities to learn about, discuss and publish their open data to the CivicData.com platform.  A recent customers we worked with to publish open data is the City of Evanston, IL.  One of the processes Evanston leverages the Accela Civic Platform to manage is licensing and inspections of food establishments.  Once Evanston learned of the LIVES data standard, an open data standard which allows municipalities to publish restaurant inspection information to Yelp or any other website, they immediately recognized its value and subsequently reached out to the Developer Evangelist team at Accela to help them get started.

Their goal was to make their restaurant inspection data available within Yelp.  In doing so citizens and visitors will be able to see restaurant scores, dates of food inspections and listings of any violations for any food establishment within the city right from the business detail page in Yelp! We worked with the city to publish their restaurant inspection data in accordance with the specification, take a look at the City of Evanston LIVES datasets on CivicData.com.

So why stop at there?  There are all kinds of useful and creative apps that could be developed with this rich set of data!  And think about it any apps created have the potential to be easily supported by any municipalities that publish their open data following the same data specification.

This post will take a look at building a simple app to allow a citizen to text the name of a restaurant in Evanston, IL to a specified number and receive details back about that restaurant including the full name, address, date of last inspection and most recent health score.  Here is a quick video demo of the text message app in action.

You can access source code for the Evanston Restaurant Scores SMS app on GitHub.

Here is how the app works:

  • A user sends a text message with the name of a restaurant to (847) 892-4858, this is a local Evanston, IL number that I purchased from Twilio for a fee of $1/month.
  • Twilio then allows me to specify a URL that can be notified when a text message is received
  • The text message app receives the request with the details of the text message, including the phone number of the requestor and the body of the text.
  • The app then handles the following:
    • Gets the restaurant name from the body of the text message
    • Uses the CivicData.com API to query the Evanston LIVES Businesses dataset with the restaurant name:
      • We are converting the restaurant name and business name from the dataset to upper case
      • We are also using a LIKE search to provide a “starts with” search of the businesses
      • If no business is found a reply is sent to the user indicating that no business was found with the requested name
    • If the restaurant is found successfully then the Evanston LIVES Inspection dataset is queried using the CivicData.com API:
      • The Inspections dataset has a foreign key relationship with the Businesses dataset based on the business_id
      • This query may return multiple rows of data, the inspection history for this business, and for the purposes of this app we will want to identify the latest inspection that has occurred.
      • A reply is sent to the user with the restaurant name, address, latest inspection date and health score.

The exciting thing about building an app like this is that with the powerful tools available the above description contains far more text than it actually took to write the app itself.  The code that contains the logic above is just over 50 lines of code!

Here is a summary of the tools used to build this application:

  • Sinatra – a light weight web framework for building applications with Ruby
  • Twilio – a cloud service to help you build communications applications using voice and SMS
  • HTTParty – a RubyGem that makes consuming restful web services very easy
  • CivicData.com API – if you know SQL then you already know how to use this API

We’re not quite done yet either, after reading through this you might have some questions like, “what if there are more than one restaurants that ‘starts with'”, or “what if there are multiple locations for the same restaurant?”

These are great questions!  The next step with this app is to enable an SMS communication between the user and the app allowing the app to ask the user additional questions like, “which business or which address are you referring to?”  Twilio offers some great tools to track conversations that I will be learning more about and implementing soon.  Stay tuned for more updates!

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s