private static void InsertGoogleHunterDataToDB(BusinessResponse business, GoogleStoreModel googleStore, List <EmailDetails> emails, string status, Database db) { foreach (var email in emails) { AddRecordToDb(new yelp.Details { YelpUrl = null, Domain = googleStore.Website, Email = email.Email, FirstName = email.FirstName, LastName = email.LastName, Position = email.Position, LinkedIn = googleStore.Linkedin, Twitter = googleStore.Twitter, Seniority = email.Seniority, City = business.Location.City, State = business.Location.State, Category = string.Join(", ", business.Categories.Select(c => c.Title).ToList <string>()), StoreName = googleStore.Name, Phone = googleStore.Phone, Facebook = googleStore.Facebook, Rating = -1, Reviewers = -1, Instagram = googleStore.Instagram, Departmnt = email.Departmnt, RetailsType = (emails?.Count ?? 0) >= _numOfEmailsForChain ? StringConstants.CATEGORY_CHAIN : StringConstants.CATEGORY_STORE, Address1 = business.Location.Address1, Address2 = business.Location.Address2, ZipCode = business.Location.ZipCode, InfoQuality = status }, db); } }
public GoogleStoreModel GetGoogleStoreByPlaceId(string placeId) { GoogleStoreModel ret = new GoogleStoreModel(); string url = $"https://maps.googleapis.com/maps/api/place/details/json?place_id={placeId}&key=AIzaSyD6Fi3_OAslSsgOQzdJxmQS0TrP2hpdtBw"; string responseBody = ""; using (var httpClient = new HttpClient()) { var res = httpClient.GetAsync(url).GetAwaiter().GetResult(); if (!res.IsSuccessStatusCode) { _logger.Error(" url: " + url); _logger.Error($" Bad response from google api : {res.StatusCode} | {res.Content}"); return(null); } else { using (var sr = new StreamReader(res.Content.ReadAsStreamAsync().GetAwaiter().GetResult())) { responseBody = sr.ReadToEnd(); } } } JObject o = JObject.Parse(responseBody); ret.Name = o["result"]["name"].ToString(); ret.Types = new List <string>(); for (var i = 0; i < o["result"]["types"].Count(); i++) { ret.Types.Add(o["result"]["types"][i].ToString()); } ret.Phone = o["result"]["international_phone_number"]?.ToString() ?? ""; ret.Website = o["result"]["website"]?.ToString() ?? ""; return(ret); }
public List <DomainCompany> GetAllWebSites(string businessName, string phone, string searchTerm) { Dictionary <string, string> domainsDict = new Dictionary <string, string>(); try { // searchTerm = "Alicia's Jewelers Bayside NY"; List <string> placeIds = GetPlaceIdsBySearchTerm(searchTerm); List <string> domains = new List <string>(); _logger.Info($" Found {placeIds.Count} placesIds from google maps api for {searchTerm}"); foreach (var placeId in placeIds) { Thread.Sleep(200); GoogleStoreModel store = GetGoogleStoreByPlaceId(placeId); bool isGoodCall = true; if (store == null) { isGoodCall = false; } string name = store.Name; if (!isGoodCall) { continue; } bool isStore = false; if (store.Types.Contains("establishment") || store.Types.Contains("store")) { isStore = true; } if (isStore) { var googlePhone = store.Phone; if (!string.IsNullOrEmpty(googlePhone) && !string.IsNullOrEmpty(phone)) { googlePhone = googlePhone.Replace("+", "").Replace("-", "").Replace("(", "").Replace(")", "").Replace(" ", "").Trim(); phone = phone.Replace("+", "").Replace("-", "").Replace("(", "").Replace(")", "").Replace(" ", "").Trim(); if (googlePhone != phone) { continue; } } var website = store.Website; if (!string.IsNullOrEmpty(website?.ToString())) { try { using (var client = new HttpClient()) { var res = client.GetAsync(website.ToString()).GetAwaiter().GetResult(); if (res.IsSuccessStatusCode) { string dom = GetDomainFromUrl(website.ToString()); string company = store.Name.ToString(); if (!domainsDict.ContainsKey(dom)) { domainsDict.Add(dom, company); } } } } catch (Exception ex) { _logger.Error(ex, ""); } } } } List <DomainCompany> ret = new List <DomainCompany>(); foreach (var p in domainsDict) { ret.Add(new DomainCompany { Domain = p.Key, Company = p.Value }); } return(ret); } catch (Exception x) { _logger.Error(x, ""); return(new List <DomainCompany>()); } }
private static void InsertYelpGoogleAndHunterDataToDB(BusinessResponse business, GoogleStoreModel googleStore, List <EmailDetails> emails, string category, string status, Database db) { foreach (var email in emails) { AddRecordToDb(new yelp.Details { YelpUrl = business.Url, Domain = googleStore.Website, Email = email.Email, FirstName = email.FirstName, LastName = email.LastName, Position = email.Position, LinkedIn = googleStore.Linkedin, Twitter = googleStore.Twitter, Seniority = email.Seniority, City = business.Location.City, State = business.Location.State, Category = string.Join(", ", business.Categories.Select(c => c.Title).ToList <string>()), StoreName = business.Name, Phone = business.Phone, Facebook = googleStore.Facebook, Rating = business.Rating, Reviewers = business.ReviewCount, Instagram = googleStore.Instagram, Departmnt = email.Departmnt, RetailsType = category, Address1 = business.Location.Address1, Address2 = business.Location.Address2, ZipCode = business.Location.ZipCode, InfoQuality = status }, db); } }