private static void Run(Options opts) { if (opts.InputWebsites != null) { foreach (string website in opts.InputWebsites) { // Verificar se estamos perante um website Uri uriResult; bool result = Uri.TryCreate(website, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (result == true && website.Contains("kuantokusta")) { WebsiteDetails websiteDetails = new WebsiteDetails(); websiteDetails.WebsiteUrl = website; websiteDetails.Category = website.Substring(website.LastIndexOf('/') + 1); AcessDataBase.InsertWebsiteDetailsIntoDataBase(websiteDetails); } } } if (File.Exists(opts.filename)) { ReadWebsiteDetailsFromFile(opts.filename); } }
private void InsertWebsiteToTrack() { // Variáveis locais string ch; int x; string link = string.Empty; //do //{ //try //{ x = Program.V_View.AskUserChar(); ch = Char.ToString(Convert.ToChar(x)); if (ch.ToLower() == "Y".ToLower()) { // Inserir na base de dados do { // Criar detalhes do website para guardar na base de dados WebsiteDetails websiteDetails = new WebsiteDetails(); Program.V_View.DisplayMessage("INFO", "Insira aqui o link(Pressiona ESC para cancelar): "); websiteDetails.WebsiteUrl = Program.V_View.ReadLineWithCancel(); Colorful.Console.WriteLine(); Program.V_View.DisplayMessage("INFO", "Insira o nome da Categoria associado ao link colocado acima: "); websiteDetails.Category = Program.V_View.ReadLineWithCancel(); if (link != null) { AcessDataBase.InsertWebsiteDetailsIntoDataBase(websiteDetails); Program.V_View.DisplayMessage("INFO", "Link Foi adicionado com sucesso à base de dados"); } } while (link != null); if (link == null && ((Scrapper.dt = AcessDataBase.GetAllUrl()) == null) && Scrapper.dt.Rows.Count == 0) { Program.V_View.DisplayMessage("CRITICAL", "Nenhum link foi adicionado para fazer a verificação"); Program.V_View.DisplayMessage("INFO", "O programa vai encerrar"); Thread.Sleep(1000); return; } else { PrintLinksToBeParsed(); } } else if (ch.ToLower() == "N".ToLower()) { Program.V_View.DisplayMessage("INFO", "O program vai encerrar"); Thread.Sleep(1000); return; } }
private static void ReadWebsiteDetailsFromFile(string filePath) { string[] lines = System.IO.File.ReadAllLines(filePath); int contador = 0; foreach (string line in lines) { // Use a tab to indent each line of the file. String[] parts = line.Split(';'); //Console.WriteLine(line); WebsiteDetails websiteDetails = new WebsiteDetails(); websiteDetails.WebsiteUrl = parts[0]; websiteDetails.Category = parts[1]; if ((AcessDataBase.InsertWebsiteDetailsIntoDataBase(websiteDetails) == true)) { contador++; } } Program.V_View.DisplayMessage("INFO", $"Foram adicionados {contador} links a pesquisar à base de dados"); }
private static void ReadWebsiteDetailsFromFile(string filePath) { string[] lines = System.IO.File.ReadAllLines(filePath); int contador = 0; foreach (string line in lines) { // Use a tab to indent each line of the file. String[] parts = line.Split(';'); //Console.WriteLine(line); WebsiteDetails websiteDetails = new WebsiteDetails(); websiteDetails.WebsiteUrl = parts[0]; websiteDetails.Category = parts[1]; if ((AcessDataBase.InsertWebsiteDetailsIntoDataBase(websiteDetails) == true)) { contador++; } } //Colorful.Console.WriteLineStyled($"[{DateTime.Now:HH:mm:ss}] [INFO] Foram adicionados {contador} links a pesquisar à base de dados", Program.M_Options.StyleConsole); }
private static async Task RunAsync() { Colorful.Console.WriteAscii("KuantoKusta Scrapper", Color.FromArgb(244, 212, 255)); Colorful.Console.WriteLineStyled($"[{DateTime.Now:HH:mm:ss}] [INFO] Bem vindo ao Programa", M_Options.StyleConsole); //} WebScrappingPage scrappingPage = new WebScrappingPage(); Colorful.Console.WriteLineStyled($"[{DateTime.Now:HH:mm:ss}] [INFO] Vamos proceder ao ínicio da operação de obter os produtos e os respetivos preços", M_Options.StyleConsole); DataTable dt = AcessDataBase.GetAllUrl(); if (dt != null) { if (dt.Rows.Count == 0) { Colorful.Console.WriteLineStyled($"[{DateTime.Now:HH:mm:ss}] [WARNING] Não foi possível obter nenhum link", M_Options.StyleConsole); Colorful.Console.WriteStyled($"[{DateTime.Now:HH:mm:ss}] Pretende adicionar algum link através da consola? (Y/N): ", M_Options.StyleConsole); // Variáveis locais string ch; int x; string link = string.Empty; //do //{ x = Colorful.Console.Read(); //try //{ ch = Char.ToString(Convert.ToChar(x)); if (ch.ToLower() == "Y".ToLower()) { // Inserir na base de dados do { // Criar detalhes do website para guardar na base de dados WebsiteDetails websiteDetails = new WebsiteDetails(); Colorful.Console.WriteStyled($"[{DateTime.Now:HH:mm:ss}] Insira aqui o link (Pressiona ESC para cancelar): ", M_Options.StyleConsole); websiteDetails.WebsiteUrl = ReadLineWithCancel(); Colorful.Console.WriteLine(); Colorful.Console.WriteStyled($"[{DateTime.Now:HH:mm:ss}] Insira o nome da Categoria associado ao link colocado acima: ", M_Options.StyleConsole); websiteDetails.Category = Colorful.Console.ReadLine(); if (link != null) { AcessDataBase.InsertWebsiteDetailsIntoDataBase(websiteDetails); Colorful.Console.WriteLineStyled($"[{DateTime.Now:HH:mm:ss}] [INFO] Link Foi adicionado com sucesso à base de dados", M_Options.StyleConsole); } } while (link != null); if (link == null && ((dt = AcessDataBase.GetAllUrl()) == null) && dt.Rows.Count == 0) { Colorful.Console.WriteLineStyled($"[{DateTime.Now:HH:mm:ss}] [CRITICAL] Nenhum link foi adicionado para fazer a verificação", M_Options.StyleConsole); Colorful.Console.WriteLineStyled($"[{DateTime.Now:HH:mm:ss}] [INFO] O programa vai encerrar", M_Options.StyleConsole); Thread.Sleep(1000); return; } else { PrintLinksToBeParsed(M_Options.StyleConsole, dt); } } else if (ch.ToLower() == "N".ToLower()) { Colorful.Console.WriteLineStyled($"[{DateTime.Now:HH:mm:ss}] [INFO] O programa vai encerrar", M_Options.StyleConsole); Thread.Sleep(1000); return; } //} //catch (OverflowException e) //{ // Colorful.Console.WriteLine("{0} Value read = {1}.", e.Message, x); // ch = Char.MinValue; // Colorful.Console.WriteLine(m1); //} //} while (ch != '+'); } else { PrintLinksToBeParsed(M_Options.StyleConsole, dt); } }