private static List <RestaurantMenuItem> ParseMenuFromMenicka(HtmlNode todayMenu) { var result = new List <RestaurantMenuItem>(); var foodMenus = todayMenu.SelectNodes(".//tr") .Where(node => node.GetClasses().Contains("soup") || node.GetClasses().Contains("main")); foreach (var food in foodMenus) { var item = new RestaurantMenuItem(); if (food.GetClasses().Contains("soup")) { item.FoodType = FoodType.Soup; item.Description = Regex.Replace(food.SelectNodes(".//td").Single(x => x.GetClasses().Contains("food")).InnerText, "\\d+.?", string.Empty); item.Price = food.SelectNodes(".//td").Single(x => x.GetClasses().Contains("prize")).InnerText; } else { item.FoodType = FoodType.Main; item.Description = Regex.Replace(food.SelectNodes(".//td").Single(x => x.GetClasses().Contains("food")).InnerText, "\\d+.?", string.Empty); item.Price = food.SelectNodes(".//td").Single(x => x.GetClasses().Contains("prize")).InnerText; item.Index = food.SelectNodes(".//td").Single(x => x.GetClasses().Contains("no")).InnerText; } result.Add(item); } return(result); }
private List <RestaurantMenuItem> ParseMenuFromBistroteka(string data) { var result = new List <RestaurantMenuItem>(); var items = JArray.Parse(data); var todayItems = items.Where(x => DateTime.TryParse(x["dateFrom"].Value <string>(), out var value) == true && value == DateTime.Today); foreach (var todayItem in todayItems) { var item = new RestaurantMenuItem(); if (todayItem["type"].Value <string>() == "polevka") { item.FoodType = FoodType.Soup; item.Description = todayItem["name"].Value <string>(); item.Price = todayItem["price"].Value <string>(); } else { item.FoodType = FoodType.Main; item.Description = todayItem["name"].Value <string>(); item.Price = todayItem["price"].Value <string>(); } result.Add(item); } return(result); }
private static List <RestaurantMenuItem> ParseMenuFromMakalu(HtmlNode todayMenu) { var result = new List <RestaurantMenuItem>(); var todayString = GetTodayInCzech(); var todayNode = string.Join(" ", todayMenu.SelectNodes(".//div[contains(@class,TJStrana)]").Where(x => x.GetClasses().Contains("TJStrana")).Select(x => x.InnerHtml)); var start = todayNode.IndexOf(todayString) + 13; var end = todayNode.Substring(start, todayNode.Length - start).IndexOf("Mix denn"); var body = todayNode.Substring(start, end); var soupString = Regex.Match(body, "Polévky:<br>.+?(?=(1.))"); foreach (Match item in Regex.Matches(soupString.Value, "[r]>.+?(?=<[bs])")) { var newItem = new RestaurantMenuItem { FoodType = FoodType.Soup, Description = item.Value.Substring(2) }; result.Add(newItem); } var matches = Regex.Matches(body, "<b>.+?<\\/b>"); foreach (Match match in matches) { var item = new RestaurantMenuItem { FoodType = FoodType.Main, Price = Regex.Match(match.Value, "(?='>)(.*)(?=</span)").Value.Substring(2), Description = Regex.Match(match.Value, "(?=<b>)(.+?)(?=<span)").Value.Substring(3) + " " }; result.Add(item); } return(result); }