Beispiel #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);
 }
        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");
            }
        }
Beispiel #3
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");
            }
        }
        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);
            }
        }
Beispiel #6
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();
                }
            }
        }
Beispiel #7
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");
            }
        }
        /*Cria uma nova licitacao e o lote se for necessário*/
        public static bool CreateLicitacao()
        {
            try
            {
                string entidadeExecutora   = web.FindElement(By.Id("ctl00_ContentPlaceHolder1_tbnmExecutor")).GetAttribute("value");
                string objeto              = web.FindElement(By.Id("ctl00_ContentPlaceHolder1_tbdsObjeto")).GetAttribute("value");
                string numLicitacao        = web.FindElement(By.Id("ctl00_ContentPlaceHolder1_tbnrProcessoEdital")).GetAttribute("value");
                string preco               = web.FindElement(By.Id("ctl00_ContentPlaceHolder1_tbvlReferencia")).GetAttribute("value");
                string dotacao             = web.FindElement(By.Id("ctl00_ContentPlaceHolder1_tbnrDotacaoOrcamentaria")).GetAttribute("value");
                string modalidade          = web.FindElement(By.Id("ctl00_ContentPlaceHolder1_tbdsModalidadeLicitacao")).GetAttribute("value");
                string numProcesso         = web.FindElement(By.Id("ctl00_ContentPlaceHolder1_tbnrEditalOrigem")).GetAttribute("value");
                string dataLancamento      = web.FindElement(By.Id("ctl00_ContentPlaceHolder1_tbdtLancamentoPublicacao")).GetAttribute("value");
                string precoMax            = web.FindElement(By.Id("ctl00_ContentPlaceHolder1_tbvlReferencia")).GetAttribute("value");
                string dataAberturaEntrega = "";
                if (CidadeAtual == "Diamante do Oeste")
                {
                    CidadeAtual = "Diamante d'Oeste";
                }

                if (Regex.IsMatch(web.PageSource, @"ctl00_ContentPlaceHolder1_tbdtAberturaLicitacao", RegexOptions.IgnoreCase))
                {
                    dataAberturaEntrega = web.FindElement(By.Id("ctl00_ContentPlaceHolder1_tbdtAberturaLicitacao")).GetAttribute("value");

                    //Caso a licitação tenha o campo NOVA Data Abertura preenchido
                    if (Regex.IsMatch(web.PageSource, @"ctl00_ContentPlaceHolder1_tbdtAberturaNova", RegexOptions.IgnoreCase))
                    {
                        string dataNovaAberturaEntrega = web.FindElement(By.Id("ctl00_ContentPlaceHolder1_tbdtAberturaNova")).GetAttribute("value");

                        if (!string.IsNullOrEmpty(dataNovaAberturaEntrega))
                        {
                            dataAberturaEntrega = dataNovaAberturaEntrega;
                        }
                    }

                    string cod  = GenerateCod(entidadeExecutora, dataLancamento, numProcesso, preco);
                    string scod = cod.ToString().Substring(0, 19);

                    long numLong = 0;
                    long numScod = long.TryParse(scod, out numLong) ? numLong : 0;

                    if (!string.IsNullOrEmpty(scod) && !LicitacaoController.Exists(scod))
                    {
                        if (!LicitacaoController.Exists(objeto, preco, "Dotação Orçamentária: " + dotacao, numLicitacao, numProcesso, Constants.TCEPR_HOST))
                        {
                            RService.Log("(CreateLicitacao) " + Name + ": Criando licitação num... " + scod + " at {0}", Path.GetTempPath() + Name + ".txt");

                            Licitacao licitacao = new Licitacao();
                            licitacao.Objeto                   = objeto;
                            licitacao.Processo                 = numProcesso;
                            licitacao.IdLicitacaoFonte         = numScod;
                            licitacao.IdFonte                  = 510;
                            licitacao.Excluido                 = 0;
                            licitacao.SegmentoAguardandoEdital = 0;
                            licitacao.DigitacaoUsuario         = 43; //Robo
                            licitacao.Lote = Lote;
                            //licitacao.DigitacaoData = null;
                            //licitacao.ProcessamentoData = null;

                            licitacao.Observacoes = "Dotação Orçamentária: " + dotacao + " / Data de lançamento do edital pela entidade executora: " + dataLancamento;
                            licitacao.LinkSite    = Constants.TCEPR_HOST;
                            licitacao.Cidade      = CidadeAtual;
                            licitacao.CidadeFonte = CidadeController.GetIdCidade(CidadeAtual, Constants.TCEPR_UF);
                            licitacao.EstadoFonte = Constants.TCEPR_UF;
                            licitacao.Estado      = Constants.TCEPR_ESTADO;
                            licitacao.Modalidade  = NameToModalidade.ContainsKey(StringHandle.RemoveAccent(modalidade).ToUpper()) ? NameToModalidade[StringHandle.RemoveAccent(modalidade).ToUpper()] : null;

                            licitacao.Num          = numLicitacao;
                            licitacao.AberturaData = DateHandle.Parse(dataAberturaEntrega, "dd/MM/yyyy");
                            licitacao.EntregaData  = DateHandle.Parse(dataAberturaEntrega, "dd/MM/yyyy");
                            licitacao.ValorMax     = precoMax;
                            licitacao.Orgao        = OrgaoController.GetOrgaoByNameAndUf(entidadeExecutora.Trim() + ":PR", NameToOrgao);

                            if (LicitacaoController.IsValid(licitacao, out mensagemErro))
                            {
                                Repo.Insert(licitacao);
                                //licitacoes.Add(licitacao);
                                RService.Log("Licitacao salva com sucesso at {0}", Path.GetTempPath() + Name + ".txt");
                                TotalLic++;
                            }
                            else
                            {
                                if (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º " + licitacao.Num + " não foi salva - Motivo(s): " + mensagemErro + " at {0}", Path.GetTempPath() + Name + ".txt");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                RService.Log("Exception (CreateLicitacao) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");
            }
            return(true);
        }
        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);
            }
        }
        /*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);
                }
            }
        }