Beispiel #1
0
        AdvertDescribe ISimpleAdvert.GetSingleAdvertInfo(string url, int advertId)
        {
            HtmlNode content = RetrieveHtmlSingleAdvert(url);

            if (content != null)
            {
                HtmlNode           exposer = RetrieveHtmlExposer(url);
                HtmlNodeCollection details = content.SelectSingleNode(".//table[contains(@class, 'details fixed marginbott20 margintop5 full')]").SelectNodes(".//table[contains(@class, 'item')]");
                AdvertDescribe     advert;

                if (content != null)
                {
                    try
                    {
                        advert               = new AdvertDescribe();
                        advert.AdvertId      = advertId;
                        advert.AdvertDetails = GetAdvertDetails(details);
                        advert.Describe      = ParseHtmlSingleAdvertOlx.ParseDescribe(content);
                        advert.AdvertExposer = ParseHtmlSingleAdvertOlx.ParseAdvertExposer(exposer);
                        advert.Tel           = ParseHtmlSingleAdvertOlx.ParseTel(exposer);

                        return(advert);
                    }
                    catch
                    {
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
        AdvertDescribe ISimpleAdvert.GetSingleAdvertInfo(string url, int advertId)
        {
            HtmlNode content = RetrieveHtmlSingleAdvert(url);
            HtmlNode exposer = RetrieveHtmlExposer(url);

            if (exposer != null)
            {
                HtmlNodeCollection details = content.SelectSingleNode(".//section/div").SelectNodes(".//li");
                AdvertDescribe     advert;

                if (content != null)
                {
                    try
                    {
                        advert               = new AdvertDescribe();
                        advert.AdvertId      = advertId;
                        advert.AdvertDetails = GetAdvertDetails(details);
                        advert.Describe      = ParseHtmlSingleAdvertOtodom.ParseDescribe(content);
                        advert.AdvertExposer = ParseHtmlSingleAdvertOtodom.ParseAdvertExposer(exposer);
                        //advert.Tel = ParseHtmlSingleAdvertOtodom.ParseTel(exposer);

                        return(advert);
                    }
                    catch
                    {
                    }
                }
            }

            return(null);
        }
Beispiel #3
0
        private static void AddAdvertDetailsToDatabase(AdvertDescribe advert)
        {
            Log.WriteLog(SqlAdvert.InsertAdvertDescribe(advert));

            foreach (Details detail in advert.AdvertDetails)
            {
                SqlAdvert.InsertAdvertDetail(detail, advert.AdvertId);
            }
        }
        internal static string InsertAdvertDescribe(AdvertDescribe advert)
        {
            string query = @"insert into dbo.Describe(Des_AdwId, Des_Describe, Des_Exposer, Des_Tel)
values (@Id, @Describe, @Exposer,@Tel)
select top 1 'Poprawnie dodano informacje o ogloszeniu ' + Adw_ForeignId + ': ' + Adw_Name as Info 
from dbo.Describe inner join dbo.Advert on Des_AdwId = Adw_Id where Des_Id = SCOPE_IDENTITY()";

            DynamicParameters param = new DynamicParameters();

            param.Add("Id", advert.AdvertId);
            param.Add("Describe", advert.Describe);
            param.Add("Exposer", advert.AdvertExposer.Length <= 31 ? advert.AdvertExposer : advert.AdvertExposer.Substring(0, 31));
            param.Add("Tel", null);

            return(sqlConnection.ExecuteScalar <string>(query, param));
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            string type        = "";
            int    searchingId = 0;

            try
            {
#if (!DEBUG)
                type        = args[0];
                searchingId = Convert.ToInt32(args[1]);
#else
                type        = "detal";
                searchingId = 5;
#endif
            }
            catch
            {
                Writer.Write("Złe parametry");
                type = "";
            }

            string url;
            int    latestAdvId = 0;

            switch (type)
            {
            case "lista":
                //Writer.Write("Rozpoczęto pobieranie listy ogłoszeń");

                url = SqlAdvert.GetSearchingUrl(searchingId);
                List <Advert> adverts = GetAdverts(url);
                AddAdvertsToDatabase(adverts, searchingId);

                //Writer.Write("Zakończono pobieranie listy ogłoszeń");
                break;

            case "detal":
                //Writer.Write("Rozpoczęto pobieranie informacji o pojedynczych ogłoszeniach");

                latestAdvId = SqlAdvert.GetLatestAdvertId(searchingId);
#if (DEBUG)
                latestAdvId = 1106;
#endif
                if (latestAdvId > 0)
                {
                    url = SqlAdvert.GetAdvertUrlById(latestAdvId);
                    AdvertDescribe advert = GetSimpleAdvertInfo(latestAdvId, url);
                    if (advert != null)
                    {
                        AddAdvertDetailsToDatabase(advert);
                    }
                    else
                    {
                        DeleteAdvert(latestAdvId);
                    }
                }
                else
                {
                    //Writer.Write("Zakończono pobieranie inforacji o ogłoszeniu: brak nowych ogłoszeń");
                }
                //Writer.Write("Zakończono pobieranie informacji o pojedynczych ogłoszeniach");

                break;
            }
        }