def get(): loc_id = request.vars.id if loc_id is not None: location = db(db.Location.id == loc_id).select(db.Location.ALL).first() mparser = MenuParser(db) menu_data_json = mparser.parse_menu_page_json(location.menu_url) db(db.Location.id == loc_id).update(menu_json=menu_data_json, time_last_update=request.now) return json.dumps(dict(loc=json.loads(menu_data_json), location_id=loc_id)) else: return "Error - must specify location id."
def home(request): context = RequestContext(request) context_dict = get_context_dict(request) menu_path = os.path.join(conf.settings.PROJECT_ROOT, 'menu.txt') menu = MenuParser(menu_path) menu = menu.parse_menu() preferences = context_dict['userprofile'].preferences preferences = Preferences.createFromString(preferences) matches = menu.match_with(preferences) html = "" for item in matches.get_items(): # TODO: make menu object iterable html += "<div style='margin-bottom: 4px; width: 400px; border-bottom: 1px solid #f0f0f0; float left;'>" html += "<strong>" + item.name + "</strong><br><font color='gray'>during " + item.meal + "</font><br><font color='gray'>at " + item.location + "</font>" html += "</div>" context_dict['matches'] = html return render_to_response("foodfinder/home.html", context_dict, context)
def home(request): context = RequestContext(request) context_dict = get_context_dict(request) menu_path = os.path.join(conf.settings.PROJECT_ROOT, 'menu.txt') menu = MenuParser(menu_path) menu = menu.parse_menu() preferences = context_dict['userprofile'].preferences preferences = Preferences.createFromString(preferences) matches = menu.match_with(preferences) html = "" for item in matches.get_items(): # TODO: make menu object iterable html += "<div style='margin-bottom: 4px; width: 400px; float left;'>" html += "<font style='text-decoration: underline;'>"+item.name+"</font><font color='black'> for "+item.meal+" @ "+item.location+"</font>" html += "</div>" context_dict['matches'] = html return render_to_response("foodfinder/home.html", context_dict, context)
def __load(self): """ Loads the object state from the cache or regenerate it if necessary @rtype: None @returns: Nothing """ data = None try: data = self.__cache.load() # cache must be created except ReloadException: # get all desktop files found desktop = DesktopParser() self.__desktop_files = desktop.getDesktopFiles() # get the menu list menu = MenuParser(MENU_FILE) menu_items = menu.getMenu() # retrieve only the siblings of the root node child self.__categories = menu.getSiblings(menu_items.getSubItem()) self.__mapItems() self.__save() return # load categories from cache data self.__categories = set(data[MENU_BASE_DIR].values()[0]) # load desktop files based on cache try : desktop = DesktopParser(data[DESKTOP_DIR].values()[0]) self.__desktop_files = desktop.getDesktopFiles() # data from cache is not ok, panic except RuntimeError, e: return
from menu_parser import MenuParser mp = MenuParser() mp.parse_menu_page('http://nutritionanalysis.dds.uconn.edu/shortmenu.asp?sName=UCONN+Dining+Services&locationNum=16&locationName=South+Campus+Marketplace&naFlag=1')
def test_get_date(self): self.assertEqual(date(2017, 10, 30), MenuParser.get_date(2017, 44, 1)) self.assertEqual(date(2018, 1, 1), MenuParser.get_date(2018, 1, 1)) self.assertEqual(date(2019, 1, 7), MenuParser.get_date(2019, 2, 1))
def update_all(): mparser = MenuParser(db) locations = db().select(db.Location.ALL) for loc in locations: mparser.update_location_menus(loc.id)