Exemplo n.º 1
0
        public ActionResult CreateJob(SearchViewModel postedModel)
        {
            var name = postedModel.Name;
            if(string.IsNullOrWhiteSpace(postedModel.Name))
            {
                name = postedModel.Terms + postedModel.Location + DateTime.Now;
            }

            var leadSearch = new LeadSearch()
                          {
                              Location = postedModel.Location,
                              Radius = postedModel.Radius,
                              Terms = postedModel.Terms,
                              UserId = CurrentUser.Id,
                              Name = name,
                              ListingsFound = postedModel.ListingsFound
                          };

            RavenSession.Store(leadSearch);
            RavenSession.SaveChanges();

            new QueueManager().AddListingSearch(leadSearch.Id);

            this.HighFive("Job created successfuly");

            return RedirectToAction("LeadSearch", new {id=leadSearch.Id});
        }
Exemplo n.º 2
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();
            }
        }
Exemplo n.º 3
0
        private void ScrapWebsitesForContactInformation(LeadSearch leadSearch)
        {
            foreach( var lead in leadSearch.Leads.Where( l => !l.WebsiteScraped ) )
            {
                if (lead.Websites != null)
                {

                    foreach (var website in lead.Websites)
                    {
                        var scrappedPage = new ScrappedPage(website);

                        lead.Emails.AddRange(scrappedPage.MailToTargets);
                        lead.ContactUsUris.AddRange(scrappedPage.ContactUsUris);

                        if (scrappedPage.MailToTargets.Any())
                        {
                            lead.FoundEmailsFromWebsite = true;
                        }

                    }
                }

                if (lead.ContactUsUris != null)
                {
                    foreach (var contactUsUri in lead.ContactUsUris)
                    {
                        var scrappedPage = new ScrappedPage(contactUsUri);

                        lead.Emails.AddRange(scrappedPage.MailToTargets);
                    }
                }

                lead.WebsiteScraped = true;
            }

            RavenSession.SaveChanges();
        }
Exemplo n.º 4
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();
        }