Esempio n. 1
0
        public async Task <FormInsertAnuncio> Retrieve(string url)
        {
            // Get Anuncio
            string htmlAnuncio = await Requests.GetAsync(url);

            FormInsertAnuncio formInsert = ParseFormReadUrl(htmlAnuncio);

            return(formInsert);
        }
Esempio n. 2
0
        public async Task <ReinsertResult> ReInsert(Anuncio anuncio, string Key2Captcha, string email)
        {
            ReinsertResult    result;
            CaptchaAnswer     captchaResponse;
            FormInsertAnuncio formInsertAnuncio;
            FormDeleteAnuncio formDeleteAnuncio;

            try
            {
                // Get Anuncio

                string htmlAnuncio = await Requests.GetAsync(anuncio.Url);

                GetException(htmlAnuncio, anuncio.Url, false);

                // Parse All Data
                FormUpdateAnuncio formAnuncio = ParseFormAnuncio(htmlAnuncio);
                formAnuncio.variables.email = email;
                anuncio.FormUpdateAnuncio   = JsonConvert.SerializeObject(formAnuncio);

                //Solve Captcha
                captchaResponse = await ResolveCaptcha(Key2Captcha, Requests.RevolicoInserrUrl, htmlAnuncio);

                formAnuncio.variables.captchaResponse = captchaResponse.Answerv2;
                //formAnuncio.variables.botScore = captchaResponse.Answerv3;

                // Parse Insert and Delete Forms
                formInsertAnuncio = new FormInsertAnuncio(formAnuncio);
                formDeleteAnuncio = new FormDeleteAnuncio(formAnuncio);

                // Insert new Announce
                string answer = await InsertAnuncio(formInsertAnuncio);

                // Verify Insertion
                GetException(answer, anuncio.Url, true, captchaResponse);

                // Update new Anuncio URL
                InsertResult insertResult = ParseInsertResult(answer);
                anuncio.Url = $"{Requests.RevolicoModifyUrl}?key={insertResult.FullId}";
                _log.LogWarning($"ReplaceInsert {anuncio.Id} {insertResult.FullId}");

                // Delete from Revolico
                await DeleteFromRevolico(formDeleteAnuncio);

                result = new ReinsertResult(anuncio);
            }
            catch (Exception ex)
            {
                result = new ReinsertResult(anuncio, ex);
            }

            return(result);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            AnuncioService anuncioService = new AnuncioService(null, null, null, null);
            string         folder         = "C:\\Users\\Rafael Fernanadez\\Documents\\Trabajos\\RT\\Recuperacion de Anuncios\\Alain";

            //try
            //{
            //    using (StreamReader reader = new StreamReader("C:\\Users\\Rafael Fernanadez\\source\\repos\\RepublishCore\\RestoreAnuncios\\source.txt"))
            //    using (StreamWriter writer = new StreamWriter("C:\\Users\\Rafael Fernanadez\\source\\repos\\RepublishCore\\RestoreAnuncios\\target.txt"))
            //    {
            //        string url;
            //        int cnt = 1;
            //        while (!reader.EndOfStream && (url = reader.ReadLine()).Length > 0)
            //        {
            //            Console.WriteLine(cnt);
            //            try
            //            {
            //                FormInsertAnuncio formInsertAnuncio = anuncioService.Retrieve(url).GetAwaiter().GetResult();
            //                string jsonForm = $"{JsonConvert.SerializeObject(formInsertAnuncio)}";

            //                writer.WriteLine(jsonForm);
            //            }
            //            catch (Exception)
            //            {
            //                writer.WriteLine(" no " + url);
            //            }
            //            cnt++;
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine(ex.Message);
            //}

            using (StreamReader reader = new StreamReader(folder + "\\target.txt"))
                using (StreamWriter writer = new StreamWriter(folder + "\\links-modificar.txt"))
                {
                    string line;
                    int    cnt = 1;
                    while (!reader.EndOfStream && (line = reader.ReadLine()).Length > 0)
                    {
                        Console.WriteLine(cnt);
                        try
                        {
                            FormInsertAnuncio formInsertAnuncio = JsonConvert.DeserializeObject <FormInsertAnuncio>(line);
                            //Captcha
                            string        html          = "DS\", \"RECAPTCHA_V2_SITE_KEY\":\"6LfyRCIUAAAAAP5zhuXfbwh63Sx4zqfPmh3Jnjy7\",\"RECAPTCHA_V3_SITE_KEY\":\"6Lfw";
                            CaptchaAnswer captchaAnswer = anuncioService.ResolveCaptcha("91092bd5c3c38f309e077e595d94226c", "https://www.revolico.com/insertar-anuncio.html", html).GetAwaiter().GetResult();
                            formInsertAnuncio.variables.captchaResponse = captchaAnswer.Answerv2;
                            //formInsertAnuncio.variables.botScore = captchaAnswer.Answerv3;

                            string       answer       = anuncioService.InsertAnuncio(formInsertAnuncio).GetAwaiter().GetResult();
                            InsertResult insertResult = anuncioService.ParseInsertResult(answer);
                            writer.WriteLine("https://www.revolico.com/modificar-anuncio.html?key=" + insertResult.FullId);
                        }
                        catch (Exception ex)
                        {
                            writer.WriteLine(" no " + cnt);
                            Console.WriteLine(ex.Message);
                        }
                        cnt++;
                    }
                }
        }
Esempio n. 4
0
        public FormInsertAnuncio ParseFormReadUrl(string htmlAnuncio)
        {
            try
            {
                FormInsertAnuncio formAnuncio = new FormInsertAnuncio();
                HtmlDocument      doc         = new HtmlDocument();

                // Load the html from a string
                doc.LoadHtml(htmlAnuncio);
                HtmlNode tmp;
                try
                {
                    tmp = doc.DocumentNode.SelectSingleNode("//*[@data-cy='adPrice']");

                    int price;
                    _ = int.TryParse(tmp.InnerText, out price);
                    formAnuncio.variables.price = price;
                }
                catch (Exception) { }

                tmp = doc.DocumentNode.SelectSingleNode("//*[@data-cy='adTitle']");
                formAnuncio.variables.title = HttpUtility.HtmlDecode(tmp.InnerText);

                tmp = doc.DocumentNode.SelectSingleNode("//*[@data-cy='adDescription']");
                int p1 = htmlAnuncio.LastIndexOf("description\":\"") + "description\":\"".Length;
                int p2 = htmlAnuncio.IndexOf("\",\"price", p1);
                // Decode the encoded string.
                formAnuncio.variables.description = HttpUtility.HtmlDecode(htmlAnuncio).Substring(p1, p2 - p1);

                formAnuncio.variables.images = new string[0];
                List <string> imagesId = new List <string>();
                int           lastPos = 0, posIni = 0, posEnd;
                posIni = htmlAnuncio.IndexOf("gcsKey", lastPos);
                while (posIni != -1)
                {
                    while (posIni != -1)
                    {
                        posEnd  = htmlAnuncio.IndexOf("urls", posIni);
                        posIni += 9;
                        posEnd -= 3;
                        string id = htmlAnuncio.Substring(posIni, posEnd - posIni);
                        imagesId.Add(id);
                        lastPos = posEnd;
                        posIni  = htmlAnuncio.IndexOf("gcsKey", lastPos);
                    }
                }
                formAnuncio.variables.images = imagesId.ToArray();

                try
                {
                    tmp = doc.DocumentNode.SelectSingleNode("//*[@data-cy='adEmail']");
                    formAnuncio.variables.email = tmp.InnerText;
                }
                catch (Exception) { }

                try
                {
                    tmp = doc.DocumentNode.SelectSingleNode("//*[@data-cy='adName']");
                    formAnuncio.variables.name = tmp.InnerText;
                }
                catch (Exception) { }

                try
                {
                    tmp = doc.DocumentNode.SelectSingleNode("//*[@data-cy='adPhone']");
                    formAnuncio.variables.phone = tmp.InnerText;
                }
                catch (Exception) { }

                //int p2 = htmlAnuncio.LastIndexOf("\",\"typename\":\"CategoryType\"");
                //int p1 = p2;
                //for (int i = 1; i <= 3; i++)
                //{
                //    if (htmlAnuncio.ElementAt(p2 - i) == ':')
                //    {
                //        p1 = p2 - i + 1;
                //        break;
                //    }
                //}
                string cat = GetCategoria(htmlAnuncio);
                formAnuncio.variables.subcategory = Cat[cat];

                formAnuncio.variables.contactInfo = "EMAIL_PHONE";
                formAnuncio.variables.botScore    = "";

                Console.WriteLine(cat);

                return(formAnuncio);
            }
            catch (Exception ex)
            {
                throw new GeneralException(ex.Message + "\n" + ex.StackTrace, "");
            }
        }
Esempio n. 5
0
        public async Task <string> InsertAnuncio(FormInsertAnuncio formInsertAnuncio)
        {
            string jsonForm = $"[{JsonConvert.SerializeObject(formInsertAnuncio)}]";

            return(await Requests.PostAsync(Requests.apiRevolico, jsonForm));
        }