def test_get_menu_url(self): """ test that we return correct URLs with and without a date passed """ location = "markley" url = umdh.get_menu_url(location) self.assertEqual( url, "http://www.housing.umich.edu/files/helper_files/js/xml2print.php?location=MARKLEY%20DINING%20HALL&output=json&date=today", ) url = umdh.get_menu_url(location, datetime.date(2014, 3, 11)) self.assertEqual( url, "http://www.housing.umich.edu/files/helper_files/js/xml2print.php?location=MARKLEY%20DINING%20HALL&output=json&date=Tuesday,March 11", )
def get_menu(date=None): result = {} # fetch documents http_client = httpclient.AsyncHTTPClient() for key in umdh.dining_halls.iterkeys(): http_client.fetch(umdh.get_menu_url(key, date), callback=(yield gen.Callback(key))) keys = set(umdh.dining_halls.keys()) # parse for chicken broccoli bake while keys: key, r = yield yieldpoints.WaitAny(keys) meals = umdh.search_menu_for( escape.json_decode(r.body), 'Chicken Broccoli Bake') if meals: result[key] = meals keys.remove(key) raise gen.Return(result)