public static void Initialize() { if (!OnlineStorage.CheckFileExists(NAME_CATEGORY_INDEX)) { return; } string contents = OnlineStorage.GetFile(NAME_CATEGORY_INDEX); string[] indicies = contents.Split(new string[] { "\n" }, StringSplitOptions.None); foreach (string index in indicies) { if (index.Length > 0) { string[] parts = index.Split(':'); try { nameToCategories.Add(parts[0], parts[1]); } catch { } } } }
static void Main(string[] args) { Console.WriteLine("Test"); OnlineStorage.Initialize(); Scraper.Initialize(); //Scraper scraper = new Scraper(ScrapeSite.PizzaPizza); List <string> urls = new List <string>(); //urls.Add("https://order.bostonpizza.com/#/menu/9F5B31DD-44D0-4508-BA45-F428C7582E5F/ToGo/Pickup"); urls.Add("http://misterlaffa.com/menu.php#mix"); urls.Add("http://www.pizzapizza.ca/view-our-menu/"); List <MenuItem> menuItems = Scraper.FetchContents(urls); Console.WriteLine("Fetched menu items"); MenuItem[] menuItems_ = RonysSortingAlgorithm.SortByPrice(menuItems.ToArray(), 0, menuItems.Count - 1); foreach (MenuItem item in menuItems_) { item.Print(); } Console.WriteLine("done"); Console.ReadLine(); }
public static List <MenuItem> FetchContents(List <string> urls) { List <MenuItem> menuItems = new List <MenuItem>(); IWebDriver driver = new ChromeDriver(); foreach (string url in urls) { switch (url) { case "http://www.pizzapizza.ca/view-our-menu/": Gather_PizzaPizza(driver, menuItems, url); break; case "http://misterlaffa.com/menu.php#mix": Gather_MrLaffa(driver, menuItems, url); break; case "https://order.bostonpizza.com/#/menu/9F5B31DD-44D0-4508-BA45-F428C7582E5F/ToGo/Pickup": Gather_BostonPizza(driver, menuItems, url); break; } } List <string> dict_values = new List <string>(); foreach (KeyValuePair <string, string> entry in nameToCategories) { if (!dict_values.Contains(entry.Value)) { dict_values.Add(entry.Value); } } foreach (MenuItem item in menuItems) { if (!(nameToCategories.ContainsKey(item.Name))) { updateIndex = true; string category = PromptCategory(item.Name, dict_values); nameToCategories.Add(item.Name, category); item.SetCategory(category); } else { item.SetCategory(nameToCategories[item.Name]); } } if (updateIndex) { string contents = ""; foreach (MenuItem item in menuItems) { string text = ""; text += item.Name; text += ":"; text += item.Category; text += "\n"; contents += text; } OnlineStorage.Overwrite(NAME_CATEGORY_INDEX, contents); contents = ""; foreach (string value in dict_values) { string text = ""; text += value; text += "\n"; contents += text; } OnlineStorage.Overwrite(CATEGORIES, contents); } string[] categories = new string[dict_values.Count]; foreach (MenuItem item in menuItems) { string category = item.Category; int index = dict_values.IndexOf(category); string temp = categories[index]; string content = item.Franchise + ":" + item.Name + ":" + item.Price.ToString() + "\n"; temp += content; categories[index] = temp; } for (int a = 0; a < categories.Length; a++) { string filename = dict_values[a] + ".txt"; string contents = categories[a]; OnlineStorage.Overwrite(filename, contents); } foreach (MenuItem item in menuItems) { //item.Print(); } return(menuItems); }