예제 #1
0
 private static void InitializeUtils()
 {
     Orgaos           = OrgaoRepository.FindByUF(Constants.CRJ_ESTADO_FONTE);
     NameToModalidade = ModalidadeController.GetNameToModalidade();
     Cidades          = CidadeController.GetNameToCidade(Constants.CRJ_ESTADO_FONTE);
     repo             = new LicitacaoRepository();
     Lote             = LoteController.CreateLote(43, Constants.CRJ_ID_FONTE);
     //AlreadyInserted = LicitacaoController.GetAlreadyInserted(Constants.CRJ_HOST);
 }
예제 #2
0
        /*Inica o processamento do robot*/
        public static void Init()
        {
            RService.Log("(Init) " + Name + ": Começando o processamento... " + "at {0}", Path.GetTempPath() + Name + ".txt");

            try
            {
                AllLinks    = new List <string>();
                Orgao       = OrgaoController.FindById(27);
                Modalidades = new List <Modalidade>();
                Lote        = LoteController.CreateLote(43, 506);
                Repo        = new LicitacaoRepository();

                Modalidades.Add(ModalidadeController.FindById(24));
                Modalidades.Add(ModalidadeController.FindById(22));

                CurrentPage = 1;
                /*Pega o html da primeira página*/
                HtmlDocument pagehtml = WebHandle.GetHtmlHandleCaptcha(Constants.CMG_SITE + Constants.CMG_LINK_PAGINATION, Encoding.GetEncoding("ISO-8859-1"), "textoConfirmacao", Constants.CMG_CAPTCHA, GetParametersPagination(string.Format(Constants.CMG_PARAMETERS_PAGINATION, CurrentPage, DateTime.Now.Year)));

                /*Numero de paginas encontradas*/
                int numberPages = pagehtml.DocumentNode.Descendants("a").Where(x => x.Attributes.Contains("id") && x.Attributes["id"].Value.Contains("tabConsultaPregoes_pagina")).ToList().Count;
                /*Caso existam poucas licitações, ao ponto de só haver uma página, o robô estava retornando numberPages = 0. Com a limitação abaixo, ele sempre vai pegar as licitações independente do pouco número de licitações*/
                if (numberPages == 0)
                {
                    numberPages = 1;
                }

                /*Percorre todas as paginas*/
                while (pagehtml != null && CurrentPage <= numberPages)
                {
                    /*Pega todas os pregões de cada página*/
                    GetPregoes(pagehtml);
                    /*Numero da próxima pagina*/
                    CurrentPage++;
                    /*Pega o html da próxima página*/
                    pagehtml = WebHandle.GetHtmlHandleCaptcha(Constants.CMG_SITE + Constants.CMG_LINK_PAGINATION, Encoding.GetEncoding("ISO-8859-1"), "textoConfirmacao", Constants.CMG_CAPTCHA, GetParametersPagination(string.Format(Constants.CMG_PARAMETERS_PAGINATION, CurrentPage, DateTime.Now.ToString("yyyy"))));
                    NumCaptcha++;
                }

                if (Directory.Exists(PathEditais))
                {
                    Directory.Delete(PathEditais, true);
                }
            }
            catch (Exception e)
            {
                RService.Log("Exception (Init)" + Name + ":" + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");
            }
            finally
            {
                if (NumLicitacoes <= 0)
                {
                    LoteController.Delete(Lote);
                }
            }
        }
예제 #3
0
        internal static void Init()
        {
            RService.Log("(Init) " + Name + ": Começando o processamento.. at {0}", Path.GetTempPath() + Name + ".txt");

            try
            {
                //Inicializa as listas e variáveis que serão usadas pelo robô
                CurrentPage      = 1;
                Lote             = LoteController.CreateLote(43, 1249);
                repo             = new LicitacaoRepository();
                Cidades          = CidadeController.GetNameToCidade(Constants.TCMCE_UF);
                NameToOrgao      = OrgaoController.GetNomeUfToOrgao();
                NameToModalidade = ModalidadeController.GetNameToModalidade();

                HtmlDocument htmlDoc = WebHandle.GetHtmlDocOfPage(string.Format(Constants.TCMCE_PAGE, CurrentPage, DateTime.Today.ToString("dd-MM-yyyy"), DateTime.Today.AddYears(1).ToString("dd-MM-yyyy")), Encoding.GetEncoding("UTF-8"));

                //O GetLastPage pega o código Html e o vasculha para encontrar o valor da última página
                int lastPage = GetLastPage(htmlDoc);

                while (CurrentPage != lastPage)
                {
                    RService.Log("(Init) " + Name + ": Percorrendo os links da página.. " + CurrentPage + " at {0}", Path.GetTempPath() + Name + ".txt");

                    HtmlNode licList = htmlDoc.DocumentNode.Descendants("table").SingleOrDefault(x => x.Id.Equals("table"));

                    foreach (var lic in licList.Descendants("tr"))
                    {
                        if (!lic.InnerHtml.Contains("Licitação"))
                        {
                            HandleCreate(lic);
                        }
                    }

                    CurrentPage++;
                    htmlDoc = WebHandle.GetHtmlDocOfPage(string.Format(Constants.TCMCE_PAGE, CurrentPage, DateTime.Today.ToString("dd-MM-yyyy"), DateTime.Today.AddYears(1).ToString("dd-MM-yyyy")), Encoding.GetEncoding("ISO-8859-1"));
                }
            }
            catch (Exception e)
            {
                RService.Log("Exception (Init) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");
            }
        }
예제 #4
0
        private static void Init()
        {
            RService.Log(name + ": Começando o processamento... at {0}", logPath);

            try
            {
                //Inicializa as listas e variáveis que serão usadas pelo robô
                currentPage      = 1;
                lote             = LoteController.CreateLote(43, 1442);
                Cidades          = CidadeController.GetNameToCidade(Constants.TCEPI_UF);
                NameToOrgao      = OrgaoController.GetNomeUfToOrgao();
                NameToModalidade = ModalidadeController.GetNameToModalidade();
                alreadyInserted  = LicitacaoController.GetAlreadyInserted(1442, DateTime.Today.AddMonths(-3));

                GetLicitacoes();
            }
            catch (Exception e)
            {
                RService.Log("Exception (Init) " + name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", logPath);
            }
        }
        private static void Init()
        {
            RService.Log("(Init) " + Name + ": Começando o processamento... " + "at {0}", Path.GetTempPath() + Name + ".txt");

            try
            {
                nameToModalidade         = ModalidadeController.GetNameToModalidade();
                nameToOrgao              = OrgaoController.GetNomeUfToOrgao();
                ufToCapital              = CityUtil.GetUfToCapital();
                ufToNomeCidadeToIdCidade = CidadeController.GetUfToNameCidadeToIdCidade();
                lote = LoteController.CreateLote(43, 508);
                repo = new LicitacaoRepository();

                HtmlDocument htmlDoc = WebHandle.GetHtmlDocOfPage(Constants.CN_COTACOES, Encoding.GetEncoding("ISO-8859-1"));

                RService.Log("(Init) " + Name + ": Percorrendo as cotações do dia " + DateTime.Today.ToShortDateString() + " at {0}", Path.GetTempPath() + Name + ".txt");

                foreach (var row in htmlDoc.DocumentNode.Descendants("tr").Where(x => x.Attributes.Contains("class") && x.Attributes["class"].Value.Contains("estiloLinhaTabela")).ToList())
                {
                    if (row.ChildNodes[5].InnerText == "Sim")
                    {
                        icms = true;
                    }
                    else
                    {
                        icms = false;
                    }

                    HandleCreate(htmlDoc, row);
                }
            }
            catch (Exception e)
            {
                RService.Log("Exception (Init) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");
            }
        }
예제 #6
0
        private static void Init()
        {
            RService.Log("(Init) " + name + ": Começando o processamento.. at {0}", logPath);

            try
            {
                Lote             = LoteController.CreateLote(43, 1250);
                Cidades          = CidadeController.GetNameToCidade(Constants.TCESE_UF);
                NameToOrgao      = OrgaoController.GetNomeUfToOrgao();
                NameToModalidade = ModalidadeController.GetNameToModalidade();

                for (int i = 0; i < Constants.TCESE_MUN_CODE.Count; i++)
                {
                    HandleLicitacoes(i);
                }

                //repo = new LicitacaoRepository();
                //repo.Insert(licitacoes);
            }
            catch (Exception e)
            {
                RService.Log("Exception (Init) " + name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", logPath);
            }
        }
예제 #7
0
        /*Inicia o processamento do robot*/
        private static void Init()
        {
            RService.Log("(Init) " + Name + ": Começando o processamento.. " + "at {0}", Path.GetTempPath() + Name + ".txt");
            try
            {
                ModalidadeCount = 0;

                Modalidades = new List <Modalidade>();
                Modalidades.Add(ModalidadeController.FindById(1));
                Modalidades.Add(ModalidadeController.FindById(14));
                Orgao = OrgaoController.FindById(388);
                Lote  = LoteController.CreateLote(43, 507);

                /*Lista das licitacoes que já existem para bec.sp.gov*/
                //AlreadyInserted = LicitacaoController.GetAlreadyInserted(Constants.BEC_SITE);

                /*Lista das cidades para o estado*/
                Cidades = CidadeController.GetNameToCidade(Constants.BEC_UF);

                //Define os pontos de partida
                List <string> urls = new List <string>();

                urls.Add(Constants.BEC_LINK_MODALIDADE_2);
                urls.Add(Constants.BEC_LINK_MODALIDADE_5);

                /*Percorre cada modalidade. Como o portal BEC usa javascript para gerar as licitações, foi preciso
                 * criar dois caminhos, uma para cada modalidade: para Carta Convite, usa-se o HtmlAgilityPack e
                 * para Dispensa de Licitação, usa-se o Selenium (PhantomJS), que consegue lidar com javascript*/
                foreach (string uri in urls)
                {
                    if (!uri.Contains("Dispensa"))
                    {
                        GetConvites(uri);
                    }
                    else
                    {
                        GetDispensas(uri);
                    }
                }

                if (Directory.Exists(PathEdital))
                {
                    Directory.Delete(PathEdital, true);
                }
            }
            catch (Exception e)
            {
                RService.Log("Exception (Init)" + Name + ":" + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");
            }
            finally
            {
                if (NumLicitacoes <= 0)
                {
                    LoteController.Delete(Lote);
                }

                if (web != null)
                {
                    web.Close();
                }
            }
        }
예제 #8
0
        /*Metodo que inicia o processamento de dados*/
        private static void Init()
        {
            RService.Log("(Init) " + Name + ": Começando o processamento... " + "at {0}", Path.GetTempPath() + Name + ".txt");
            try
            {
                Repo = new LicitacaoRepository();

                /*Realiza a atualização das situações das licitações já inseridas*/
                //UpdateLicitacoes();

                /*Inicia listas e dictionary's com informações necessárias*/
                NameToOrgao              = OrgaoController.GetNomeUfToOrgao();
                NameToModalidade         = ModalidadeController.GetNameToModalidade();
                UfToCapital              = CityUtil.GetUfToCapital();
                UfToNomeCidadeToIdCidade = CidadeController.GetUfToNameCidadeToIdCidade();
                Lote = LoteController.CreateLote(43, IdFonte);

                TryReload = true;
                if (DoSearch())
                {
                    /*Percorre cada licitação encontrada*/
                    foreach (var numUf in numUFs)
                    {
                        /*Acessa a página da licitação*/
                        try
                        {
                            if (!LicitacaoController.Exists(numUf.Split(':')[0]))
                            {
                                /*Cria o objeto licitação com as informações da página*/
                                Licitacao licitacao = CreateLicitacao(numUf);

                                if (licitacao != null)
                                {
                                    Repo.Insert(licitacao);
                                    NumLicitacoes++;
                                    RService.Log("(Init) " + Name + ": Licitação inserida com sucesso at {0}", Path.GetTempPath() + Name + ".txt");

                                    /*Segmenta a licitação recém criada*/
                                    //SegmentarLicitacao(licitacao);
                                    DownloadEdAndCreatLicArq(licitacao);
                                }
                                else
                                {
                                    if (licitacao != null && licitacao.Orgao != null)
                                    {
                                        RService.Log("Exception (CreateLicitacao) " + Name + ": A licitação de nº " + licitacao.Num + " e órgão " + licitacao.Orgao.Nome + " - " + licitacao.Orgao.Estado + " não foi salva - Motivo(s): " + mensagemErro + " at {0}", Path.GetTempPath() + Name + ".txt");
                                    }
                                    else
                                    {
                                        RService.Log("Exception (CreateLicitacao) " + Name + ": A licitação de nº " + numUf.Split(':')[0] + " não foi salva - Motivo(s): " + mensagemErro + " at {0}", Path.GetTempPath() + Name + ".txt");
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            RService.Log("Exception (Init - CreateLicitacao) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                RService.Log("Exception (Init) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");
            }
        }
예제 #9
0
        /*Inicia a busca*/
        private static void Init()
        {
            RService.Log("(Init) " + Name + ": Começando o processamento.." + " at {0}", Path.GetTempPath() + Name + ".txt");
            try
            {
                /*Inicia navegador fantasma*/
                LoadDriver();

                /*Acessa o site do TCE*/
                web.Navigate().GoToUrl(Constants.TCEPR_SITE);

                /*Busca os itens do filtro por cidades*/
                GetCidades();

                /*Configura os parametros da busca e inicia demais componentes necessários*/
                if (config.PreTypedDate != null)
                {
                    CurrentDay          = config.PreTypedDate.Value.AddDays(-2);
                    FinalDay            = config.PreTypedDate.Value;
                    config.PreTypedDate = null;
                    ConfigRobotController.Update(config);
                }
                else
                {
                    CurrentDay = DateTime.Now.AddDays(-2);
                    FinalDay   = DateTime.Now;
                }

                NameToModalidade = ModalidadeController.GetNameToModalidade();
                NameToOrgao      = OrgaoController.GetNomeUfToOrgao();
                Lote             = LoteController.CreateLote(43, 510);
                Repo             = new LicitacaoRepository();

                CurrentPg = 1;
                TotalLic  = 0;

                /*Procura licitacoes por cidade pra ointervalo de dias indicado*/
                foreach (var cidade in dicCidades)
                {
                    CidadeAtualKey = cidade.Key;
                    CidadeAtual    = cidade.Value;
                    /*Pesquisa licitações com base nos parametros (ano; dtAbertura)*/
                    if (DoSearch(CurrentDay, FinalDay))
                    {
                        /*Pra cada pag que a pesquisa retornar*/
                        do
                        {
                            /*Percorre licitações de uma pag*/
                            if (!GetLicitacoes())
                            {
                                //Segunda e ultima tentativa, se não conseguir continua com a pesquisa para a proxima cidade
                                DoSearch(CurrentDay, FinalDay);
                                GetLicitacoes();
                            }
                        } while (HasNextPage());
                    }

                    Tens = new List <int>()
                    {
                        11
                    };
                    CurrentPg = 1;
                }

                //Repo.Insert(licitacoes);
            }
            catch (Exception e)
            {
                RService.Log("Exception (Init) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");
            }
            finally
            {
                if (TotalLic <= 0)
                {
                    LoteController.Delete(Lote);
                }
                if (web != null)
                {
                    web.Close();
                }
            }
        }
예제 #10
0
        private static void Init()
        {
            RService.Log("(Init) " + Name + ": Iniciando busca... at {0}", LogPath);

            try
            {
                repo             = new LicitacaoRepository();
                Orgaos           = OrgaoRepository.FindByUF(Constants.TCERS_ESTADO_FONTE);
                NameToModalidade = ModalidadeController.GetNameToModalidade();
                Cidades          = CidadeController.GetNameToCidade(Constants.TCERS_ESTADO_FONTE);
                Lote             = LoteController.CreateLote(43, Constants.TCERS_ID_FONTE);

                if (web != null)
                {
                    web.Quit();
                }

                var driver = ChromeDriverService.CreateDefaultService();
                driver.HideCommandPromptWindow = true;
                var op = new ChromeOptions();
                op.AddUserProfilePreference("download.default_directory", PathEditais);
                web = new ChromeDriver(driver, new ChromeOptions(), TimeSpan.FromSeconds(300));
                web.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(300);
                wait = new WebDriverWait(web, TimeSpan.FromSeconds(300));

                web.Navigate().GoToUrl(Constants.TCERS_HOST);
                web.FindElement(By.XPath("//*[@id=\"t_TreeNav_1\"]/div[2]/a")).Click();

                web.FindElement(By.XPath("//*[@id=\"R4830475339138649_actions_button\"]")).Click();
                web.FindElement(By.XPath("//*[@id=\"R4830475339138649_actions_menu_3i\"]")).Click();

                try
                {
                    Actions actions = new Actions(web);
                    actions.MoveToElement(web.FindElement(By.XPath("//*[@id=\"R4830475339138649_actions_menu_3i\"]"))).Perform();
                    actions.MoveToElement(web.FindElement(By.XPath("//*[@id=\"R4830475339138649_actions_menu_3_0_c9\"]"))).Perform();
                    web.FindElement(By.XPath("//*[@id=\"R4830475339138649_actions_menu_3_0_c9\"]")).Click();
                }
                catch (Exception e)
                {
                    RService.Log("(Exception) " + Name + ": Elemento 3 at {0}", LogPath);
                }

                Thread.Sleep(10000);

                var html = web.PageSource;

                var licits = new List <string>();

                Regex licitRx = new Regex("f\\?p=(.*?)\">");
                if (licitRx.IsMatch(html))
                {
                    var matches = licitRx.Matches(html);

                    foreach (var mt in matches)
                    {
                        if (mt.ToString().Contains("ID_LICITACAO"))
                        {
                            var treatedLink = mt.ToString().Replace("\">", "").Replace("amp;", "");
                            licits.Add(Constants.TCERS_BASEURL + treatedLink);
                        }
                    }
                }

                GetLicitacoes(licits);
            }
            catch (Exception e)
            {
                RService.Log("Exception (Init) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", LogPath);
            }
        }
예제 #11
0
        /*Inicia o processamento do robot*/
        private static void Init()
        {
            RService.Log("(Init) " + Name + ": Começando o processamento.. " + "at {0}", Path.GetTempPath() + Name + ".txt");
            try
            {
                AlreadyColected = new HashSet <long>();

                /*Lista das licitacoes que já existem para bec.sp.gov*/
                //AlreadyInserted = LicitacaoController.GetAlreadyInserted(Constants.BEC_SITE);

                /*Lista das cidades para o estado*/
                Cidades = CidadeController.GetNameToCidade(Constants.BEC_UF);

                Modalidade = ModalidadeController.FindById(24);
                Orgao      = OrgaoController.FindById(388);
                Lote       = LoteController.CreateLote(43, 507);
                Repo       = new LicitacaoRepository();

                //Define os pontos de partida, uri e argumentos do post
                List <string> urls = new List <string>();

                urls.Add(Constants.BEC_LINK_MODALIDADE_71);
                urls.Add(Constants.BEC_LINK_MODALIDADE_72);

                /*Percorre cada modalidade*/
                foreach (string uri in urls)
                {
                    /*Lista dos parametros do post*/
                    NameValueCollection post = new NameValueCollection();

                    /*Percorre as naturezas de cada modalidade*/
                    foreach (var attr in WebHandle.GetHtmlDocOfPage(uri, post).DocumentNode.Descendants("span").Where(x => x.Attributes.Contains("id") &&
                                                                                                                      x.Attributes["id"].Value.ToString().Contains(Constants.BEC_ID_NATUREZA)))
                    {
                        string urin = attr.SelectSingleNode("a").Attributes["href"].Value.ToString();

                        int page = 2, count = 20;

                        /*Percorre as páginas para cada uma das naturezas (ex: 1;2;3)*/
                        HtmlDocument pagehtml = WebHandle.GetHtmlDocOfPage(urin, post);
                        while (pagehtml != null && count == 20)
                        {
                            RService.Log("(GetOC) " + Name + ": Percorrendo os links da página.. " + (page - 1) + " at {0}", Path.GetTempPath() + Name + ".txt");

                            //Pega as licitações de cada página (OC's)
                            count = GetOC(pagehtml);
                            //Pega o html da próxima página
                            pagehtml = WebHandle.GetHtmlDocOfPage(urin, GetFormParameters(pagehtml, page));
                            //Numero da proxima página
                            page++;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                RService.Log("Exception (Init) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");
            }
            finally
            {
                if (NumLicitacoes <= 0)
                {
                    LoteController.Delete(Lote);
                }
            }
        }