Esempio n. 1
0
        private void FindListings(LeadSearch leadSearch)
        {
            var ypApi = new YellowPagesApi();

            var yellowPagesSearchListingsJsonResult = ypApi.SearchListings(leadSearch.Location, leadSearch.Terms, leadSearch.Radius, leadSearch.YpPagesScraped);

            while (leadSearch.Leads.Count < Convert.ToInt32(yellowPagesSearchListingsJsonResult.SearchResult.MetaProperties.totalAvailable))
            {
                if (yellowPagesSearchListingsJsonResult.SearchResult.SearchListings != null)
                {
                    var leads = new List<Lead>();
                    foreach (var listing in yellowPagesSearchListingsJsonResult.SearchResult.SearchListings.SearchListing)
                    {
                        var lead = new Lead()
                                       {
                                           BusinessName = listing.BusinessName,
                                           BaseClickUrl = listing.BaseClickUrl,
                                           MoreInfoUrl = listing.MoreInfoUrl,
                                           Phone = listing.Phone,
                                           PrimaryCategory = listing.PrimaryCategory,
                                           YpListingId = listing.ListingId
                                       };

                        leads.Add(lead);
                    }

                    leadSearch.Leads.AddRange(leads);
                    leadSearch.YpPagesScraped++;

                    yellowPagesSearchListingsJsonResult = ypApi.SearchListings(leadSearch.Location, leadSearch.Terms,leadSearch.Radius, leadSearch.YpPagesScraped);
                }
            }

            //jobs done?
            if (leadSearch.Leads.Count == Convert.ToInt32(yellowPagesSearchListingsJsonResult.SearchResult.MetaProperties.totalAvailable))
            {
                RavenSession.SaveChanges();
            }
        }
        public ActionResult PreviewResults(string terms, string location, int radius )
        {
            var searchResult = new YellowPagesApi().SearchListings(location, terms, radius, 1);

            var leads = new List<Lead>();
            foreach (var listing in searchResult.SearchResult.SearchListings.SearchListing)
            {
                var lead = new Lead()
                {
                    BusinessName = listing.BusinessName,
                    BaseClickUrl = listing.BaseClickUrl,
                    MoreInfoUrl = listing.MoreInfoUrl,
                    Phone = listing.Phone,
                    PrimaryCategory = listing.PrimaryCategory,
                    YpListingId = listing.ListingId,
                    Street = listing.Street,
                    State = listing.State,
                    City = listing.City,
                    Zip = listing.Zip

                };

                leads.Add(lead);
            }

            var viewModel = new SearchViewModel();

            viewModel.Terms = terms;
            viewModel.Location = location;
            viewModel.Radius = radius;

            if (leads.Any())
            {
                viewModel.Leads = leads;
                viewModel.ListingsFound = Convert.ToInt32(searchResult.SearchResult.MetaProperties.totalAvailable);
            }

            return View(viewModel);
        }
Esempio n. 3
0
        private void FindListingDetails(LeadSearch leadSearch)
        {
            var yp = new YellowPagesApi();
            foreach( var lead in leadSearch.Leads.Where(l=>!l.DetailsScrapped) )
            {
                var details = yp.GetDetails(lead.YpListingId);
                lead.DetailsScrapped = true;

                if( details != null )
                {
                    lead.Websites = details.ListingsDetailsResult.ListingsDetails.ListingDetail[0].ExtraWebsiteUrls.CleanedUrls();
                    lead.Emails = details.ListingsDetailsResult.ListingsDetails.ListingDetail[0].ExtraEmails.ExtraEmail;
                }

            }

            RavenSession.SaveChanges();
        }