/// <summary> /// Return a list of places by proximity /// </summary> public PlaceDto ReturnPlacesByProximity(double longitude, double latitude, int radius, string type, int offset, int limit) { var q = new Query(); if (string.Compare(type, "all", true) != 0) { q.Search(type); } q.WithIn(new Circle(longitude, latitude, radius)); return JsonSerializer.DeserializeFromString<PlaceDto>(ProcessQuery(q, limit, offset)); }
/// <summary> /// Constructor for a boost. /// </summary> /// <param name="factualId">factualId this boost is performed on.</param> /// <param name="query">factualId this boost is performed on.</param> /// <param name="user">factualId this boost is performed on.</param> public Boost(string factualId, Query query, Metadata user) : this(factualId) { string[] querySearchArray = query.ToUrlQuery().Split('=', '&'); for (int i = 0; i < querySearchArray.Length; i++) if (querySearchArray[i] == Constants.SEARCH && i + 1 < querySearchArray.Length && !string.IsNullOrWhiteSpace(querySearchArray[i + 1])) Search(querySearchArray[i + 1]); string[] queryUserArray = user.ToUrlQuery().Split('=', '&'); for (int i = 0; i < queryUserArray.Length; i++) if (queryUserArray[i] == Constants.USER && i + 1 < queryUserArray.Length && !string.IsNullOrWhiteSpace(queryUserArray[i + 1])) User(queryUserArray[i + 1]); }
/// <summary> /// Return a list of places by town and country /// </summary> public PlaceDto ReturnPlacesByTownAndCountry(string town, string country, string type, int limit, int offset) { var q = new Query(); if (string.Compare(type, "all", true) != 0) { q.Search(type); } q.And(q.Field("locality").Equal(town)); q.And(q.Field("country").Equal(country)); return JsonSerializer.DeserializeFromString<PlaceDto>(ProcessQuery(q, limit, offset)); }
public string GetHealthCareProviderAutocomplete(string searchTerm) { var query = new Query(); try { query.Only("category"); return _factual.Fetch("health-care-providers-us", query); } catch (Exception) { throw; } }
public string GetHealthCareProviderData(ProviderFilter filter) { try { var query = new Query(); if (filter.Latitude != 0 && filter.Longitude != 0) { query.WithIn(new Circle(filter.Latitude, filter.Longitude, filter.Meters)); } if (!string.IsNullOrWhiteSpace(filter.Category)) { query.Field("category").Search(filter.Category); } if (!string.IsNullOrWhiteSpace(filter.Npi)) { query.Field("npi_id").Search(filter.Npi); } if (!string.IsNullOrWhiteSpace(filter.Insurances)) { query.Field("insurances").Search(filter.Insurances); } if (!string.IsNullOrWhiteSpace(filter.Locality)) { query.Field("locality").Search(filter.Locality); } if (!string.IsNullOrWhiteSpace(filter.Region)) { query.Field("region").Search(filter.Region); } query.Field("offset").Equals(0); return _factual.Fetch("health-care-providers-us", query); } catch (Exception ex) { throw; } }
public string GetRestaurantsJsonData(LocationQueryFilter filter) { var query = new Query(); if (filter.Latitude != 0 && filter.Longitude != 0) { query.WithIn(new Circle(filter.Latitude, filter.Longitude, filter.Distance==0?1000:filter.Distance)); } if (!string.IsNullOrWhiteSpace(filter.Location)) { query.Field("locality").Search(filter.Location); } if (!string.IsNullOrWhiteSpace(filter.SearchValue)) { query.Field("name").Search(filter.SearchValue); } //Only return small subset of data that we need query.Only("name", "cuisine", "rating", "address", "website"); return _factual.Fetch("restaurants", query); }
private void buttonSearch_Click(object sender, EventArgs e) { /* initiate duplicate checker with excel file */ if (xlWorkbook == null) { xlApp = new Excel.Application(); OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Excel Documents (*.xlsx)|*.xlsx"; ofd.ShowDialog(); xlWorkbook = xlApp.Workbooks.Open(ofd.FileName, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorksheet = (Excel._Worksheet)xlWorkbook.Sheets[1]; } /* Save settings */ SaveSettings(); checkListCategories.Items.Clear(); statusBotStrip.Text = "Status: Searching"; string[] countriesArray = new string[]{"United States", "Singapore", "Australia", "New Zealand"}; if (searchCity.Lines.Length == 0) searchCity.Text = countriesArray[searchCountry.SelectedIndex]; for (int locationline = 0; locationline < searchCity.Lines.Length; locationline++) { for (int categoryline = 0; categoryline < searchCategory.Lines.Length; categoryline++) { if (searchGoogle.Checked) { /* Conduct first page search */ string searchCritera = generateSearchQuery(categoryline, locationline); statusBotStrip.Text = "Status: Searching " + searchCritera + " on Google"; searchCritera = searchCritera.Replace(" ", "+"); string json = getMapList(searchCritera); var jarray = JsonConvert.DeserializeObject<RootObjectPlaces>(json); if (jarray.status == "OK") { /* Populate the company list */ populateGoogleCompanies(jarray, xlWorksheet); /* Conduct next page search until reached end of search */ string nextPageToken = jarray.next_page_token; while (nextPageToken != null) { json = getMapList(searchCritera + "&pagetoken=" + nextPageToken); jarray = JsonConvert.DeserializeObject<RootObjectPlaces>(json); /* Populate again */ populateGoogleCompanies(jarray, xlWorksheet); nextPageToken = jarray.next_page_token; } } else if (jarray.status == "ZERO_RESULTS") textDebugger.AppendText("Google found no results searching:" + searchCritera + Environment.NewLine); else textDebugger.AppendText("Google Search Error: " + jarray.error_message + " when searching: " + searchCritera + Environment.NewLine); } saveDataSet(); if (searchYelp.Checked) { string searchCriteria = searchCategory.Lines[categoryline]; string search_Country = searchCountry.Text; string searchArea = ""; searchArea = generateSearchQueryArea(locationline); statusBotStrip.Text = "Status: Searching " + searchArea + " " + searchCriteria + " on Yelp"; var yelp = new Yelp(Config.Options); var searchOpt = new SearchOptions(); searchOpt.GeneralOptions = new GeneralOptions() { term = searchCriteria, radius_filter = 50000, category_filter = "homeservices", sort = 1 }; searchOpt.LocationOptions = new LocationOptions() { location = searchArea }; searchOpt.LocaleOptions = new LocaleOptions() { cc = search_Country }; var task = yelp.Search(searchOpt); int pages = (int)Math.Ceiling(task.Result.total / 20.0); for (int p = 1; p <= pages; p++) { for (int i = 0; i <= 19; i++) { try { Business business = task.Result.businesses[i]; string companyName = business.name; string companyAddress = String.Join(" ", business.location.address); string companyCity = business.location.city == null ? "" : business.location.city; string companyState = business.location.state_code == null ? "" : business.location.state_code; string companyZip = business.location.postal_code == null ? "" : business.location.postal_code; string companyCountry = business.location.country_code == null ? "" : business.location.country_code; string companyPhone = business.phone == null ? "" : fixPhoneNumberFormat(business.phone); if (!checkIfExistInCurrentList(companyName, companyPhone, "No website yet", "No email on 1st check")) { string companyWebsite = findYelpCompanyWebsite(task.Result.businesses[i].url); bool companyHasPicturesOrPersonalWebsite = true; if (companyWebsite == "No company website") { companyHasPicturesOrPersonalWebsite = doesYelpCompanyHavePictures(); companyWebsite = task.Result.businesses[i].url; } if (companyHasPicturesOrPersonalWebsite) { List<string> companyCategories = new List<string>(); foreach (string[] category in task.Result.businesses[i].categories) companyCategories.Add(category[0]); string companyHouzzSearch = generateHouzzSearchLink(replaceCompanyNamePTE(companyName), searchArea.Remove(0, searchArea.LastIndexOfAny(new char[] { ',', ' ' }) + 1).Replace(" ", ""), true); AddtoList(companyName, companyAddress, companyCity, companyState, companyZip, companyCountry, companyPhone, "No email", "", companyWebsite, companyHouzzSearch, companyCategories); } } } catch { } } var searchOptions = new SearchOptions(); searchOptions.GeneralOptions = new GeneralOptions() { term = searchCriteria, offset = (p * 20), radius_filter = 50000, category_filter = "homeservices", sort = 1 //distance }; searchOptions.LocationOptions = new LocationOptions() { location = searchArea }; searchOptions.LocaleOptions = new LocaleOptions() { cc = search_Country }; task = yelp.Search(searchOptions); } } saveDataSet(); if (searchFacebook.Checked) { string searchCriteria = searchCategory.Lines[categoryline]; string searchArea = generateSearchQueryArea(locationline); statusBotStrip.Text = "Status: Searching " + searchArea + " " + searchCriteria + " on Facebook"; string[] jsonFacebookSearchResults = new string[5]; jsonFacebookSearchResults[1] = getFacebookSearchList(searchCriteria, searchArea, "page", false); jsonFacebookSearchResults[2] = getFacebookSearchList(searchCriteria, searchArea, "page", true); jsonFacebookSearchResults[3] = getFacebookSearchList(searchCriteria, searchArea, "place", false); jsonFacebookSearchResults[4] = getFacebookSearchList(searchCriteria, searchArea, "place", true); for (int i = 1; i <= 4; i++) { var jarray = JsonConvert.DeserializeObject<RootObjectFacebook>(jsonFacebookSearchResults[i]); if( jarray.data != null & jarray.data.Count > 0 ) populateFacebookCompanies(jarray); else if( jarray.error != null) textDebugger.AppendText("Facebook search error: " + jarray.error.message + Environment.NewLine); } } saveDataSet(); if (searchYellowPages.Checked) { /* Conduct first page search */ string searchCriteria = searchCategory.Lines[categoryline].Replace(" ", "+"); string search_Country = searchCountry.Text; string searchArea = generateSearchQueryArea(locationline); statusBotStrip.Text = "Status: Searching " + searchArea + " " + searchCriteria + " on YellowPages"; for (int i = 1; i <= 30; i++) /* 30 pages even if they do not reach 30 */ { string json = getYPList(searchCriteria, searchArea, i); var jarray = JsonConvert.DeserializeObject<RootObjectYP>(json); if (jarray.searchResult.metaProperties.errorCode == "") { // Populate the company list if (jarray.searchResult.metaProperties.listingCount > 0) { populateYPCompanies(jarray, xlWorksheet); } else { textDebugger.AppendText("Error on YP page " + i.ToString() + ": No results found searching: " + searchArea + " " + searchCriteria + Environment.NewLine); break; } } else textDebugger.AppendText("Error on YP page " + i.ToString() + ": " + jarray.searchResult.metaProperties.message + Environment.NewLine); } } saveDataSet(); if( searchFactual.Checked ) { string searchCriteria = searchCategory.Lines[categoryline]; string search_Country = searchCountry.Text; string search_City = "", search_State = ""; Factual factual = new Factual(apiFactualKey, apiFactualSecret); Query q = new Query().SearchExact(searchCriteria); if (search_Country != "US") { q.And(q.Field("country").Equal(search_Country), q.Limit(50)); statusBotStrip.Text = "Status: Searching" + search_Country + " " + searchCriteria + " on Factual"; } if (search_Country == "US") { q.And(q.Field("country").Equal(search_Country), q.Field("region").Equal(search_State), q.Field("locality").Equal(search_City), q.Limit(50)); search_City = searchCity.Lines[locationline]; search_State = searchState.Text; statusBotStrip.Text = "Status: Searching " + search_Country + " " + search_City + " " + searchCriteria + " on Factual"; } /* if (searchCategoryFilters != "") q.Field("category_labels").Includes(searchCategoryFilters); */ int page = 1; try { var json = factual.Fetch("places", q); var jarray = JsonConvert.DeserializeObject<RootObjectFactual>(json); while (jarray.status == "ok" & jarray.response.data.Count > 0) { /* Populate the company list */ foreach (Datum item in jarray.response.data) { string companyName = item.name; string companyAddress = item.address == null ? "" : item.address; string companyCity = item.locality == null ? "" : item.locality; string companyState = item.region == null ? "" : item.region; string companyCountry = item.country == null ? "" : item.country; string companyZip = item.postcode == null ? "" : item.postcode; string companyPhone = item.tel == null ? "" : fixPhoneNumberFormat(item.tel); string companyEmail = item.email == null ? "no email" : item.email; string companyWebsite = item.website; string companyHouzzSearch = generateHouzzSearchLink(replaceCompanyNamePTE(companyName), companyState, true); List<string> companyCategories = item.category_labels == null ? new List<string>() : item.category_labels[0]; //textDebugger.AppendText(companyName + Environment.NewLine); AddtoList(companyName, companyAddress, companyCity, companyState, companyZip, companyCountry, companyPhone, companyEmail, "", companyWebsite, companyHouzzSearch, companyCategories); } page++; int pageOffset = (page - 1) * 50; Query qnew = new Query().SearchExact(searchCriteria); if ( searchCountry.Text == "US" || searchCountry.Text == "AU") { json = factual.Fetch("places", new Query() .SearchExact(searchCriteria) .Field("country").Equal(search_Country) .Field("region").Equal(search_State) .Field("locality").Equal(search_City) .Limit(50) .Offset(pageOffset)); } else if (searchCountry.Text != "US" & searchCountry.Text != "AU") { json = factual.Fetch("places", new Query() .SearchExact(searchCriteria) .Field("country").Equal(search_Country) .Limit(50) .Offset(pageOffset)); } jarray = JsonConvert.DeserializeObject<RootObjectFactual>(json); } } catch (FactualApiException ex) { textDebugger.AppendText("Factual Requested URL: " + ex.Url + Environment.NewLine); textDebugger.AppendText("Factual Error Status Code: " + ex.StatusCode + Environment.NewLine); ; textDebugger.AppendText("Factual Error Response Message: " + ex.Response + Environment.NewLine); ; if (ex.StatusCode.ToString().Contains("RequestedRangeNotSatisfiable")) textDebugger.AppendText("Factual reached end of results on page " + (page - 1).ToString() + Environment.NewLine); } } saveDataSet(); if( searchSensis.Checked ) { var searcher = new SsapiSearcher(searchEndPoint, apiSensisKey); // Perform a search and check the response var searchResponse = searcher.SearchFor(searchCategory.Text, searchCity.Text, searchState.Text, 1); /* page 1 */ if (searchResponse.code < 200 || searchResponse.code > 299) textDebugger.AppendText("Search failed - Error " + searchResponse.code + ": " + searchResponse.message + Environment.NewLine); else { textDebugger.AppendText("Total results found: " + searchResponse.totalResults.ToString() + Environment.NewLine); textDebugger.AppendText("Total pages: " + searchResponse.totalPages.ToString() + Environment.NewLine); for (int page = 1; page < searchResponse.totalPages; page++) { // Display the results foreach (var result in searchResponse.results) { string companyWebsite = getSensisContactComponents(result.primaryContacts, "URL"); if (companyWebsite != "") { string companyName = result.name; string companyAddress = "", companyCity = "", companyState = "", companyZip = ""; if (result.primaryAddress != null) { companyAddress = result.primaryAddress.addressLine == null ? "" : result.primaryAddress.addressLine; companyCity = result.primaryAddress.suburb == null ? "" : result.primaryAddress.suburb; companyState = result.primaryAddress.state == null ? "" : result.primaryAddress.state; companyZip = result.primaryAddress.postcode == null ? "" : result.primaryAddress.postcode; } string companyCountry = "AU"; string companyEmail = getSensisContactComponents(result.primaryContacts, "EMAIL"); string companyPhone = fixPhoneNumberFormat(getSensisContactComponents(result.primaryContacts, "PHONE")); if (companyPhone == "") companyPhone = fixPhoneNumberFormat(getSensisContactComponents(result.primaryContacts, "MOBILE")); string companyContactUs = companyEmail.Contains("@") ? "" : getSensisExternalLinksComponents(result.externalLinks, "Contact Us"); string companyHouzzSearch = generateHouzzSearchLink(replaceCompanyNamePTE(companyName), companyState, true); List<string> companyCategories = result.categories == null ? new List<string>() : new List<string>(new string[] { result.categories[0].name }); //textDebugger.AppendText(companyName + companyAddress + companyCity + companyState + companyZip + companyEmail + companyPhone + companyWebsite + Environment.NewLine); AddtoList(companyName, companyAddress, companyCity, companyState, companyZip, companyCountry, companyPhone, companyEmail, companyContactUs, companyWebsite, companyHouzzSearch, companyCategories); } } searchResponse = searcher.SearchFor(searchCategory.Text, searchCity.Text, searchState.Text, page); } } } /* At the end of each category, we save the data found into an xml file*/ saveDataSet(); } } statusBotStrip.Text = "Status: Done"; /* Save settings */ SaveSettings(); }
/// <summary> /// Queue a monetize query for inclusing in the next multi request. /// </summary> /// <param name="query"></param> public void QueueFetchMonetize(Query query) { MultiQuery.AddQuery(UrlForMonetize(), query.ToUrlQuery()); }
/// <summary> /// Queue a read request for inclusion in the next multi request. /// </summary> /// <param name="table">the name of the table you wish to query (e.g., "places")</param> /// <param name="query">the read query to run against table.</param> public void QueueFetch(string table, Query query) { MultiQuery.AddQuery(UrlForFetch(table), query.ToUrlQuery()); }
/// <summary> /// Runs a monetize query against the specified Factual table. /// </summary> /// <param name="query">the query to run against monetize.</param> /// <returns>the response of running query against Factual API.</returns> public string Monetize(Query query) { return RawQuery(UrlForMonetize(), query.ToUrlQuery()); }
/// <summary> /// Runs a read query against the specified Factual table. /// </summary> /// <param name="tableName">the name of the table you wish to query (e.g., "places")</param> /// <param name="query">the read query to run against table.</param> /// <returns>the response of running query against Factual.</returns> public string Fetch(string tableName, Query query) { return RawQuery(UrlForFetch(tableName),query.ToUrlQuery()); }
/// <summary> /// Process Query /// </summary> private string ProcessQuery(Query q, int limit, int offset) { if (limit > 0) { q.Limit(limit).Offset(offset); } return _factual.Fetch("places", q); }
/// <summary> /// Runs a boost post request of existing attributes on a Factual entity. /// </summary> /// <param name="tableName">the name of the table in which to boost attributes for an entity (e.g., "places").</param> /// <param name="factualId">the factual id on which the boost is run.</param> /// <param name="query">the row query to run against table.</param> /// <param name="user">the metadata which executes the boost.</param> /// <returns>the response of running boost post request on a Factual entity.</returns> public string Boost(string tableName, string factualId, Query query, Metadata user) { return Boost(tableName, new Boost(factualId, query, user)); }
public ActionResult DownloadInfo(BusinessCategoryViewModel item) { var userId = User.Identity.GetUserId(); if (item != null) { if (item.IsChoose && (item.TotalDownloaded < item.Availble || (item.Availble == 0 && item.TotalDownloaded == 0))) { var query = new Query(); query.And( query.Field("locality").Equal(item.City), query.Field("region").Equal(item.State), query.Field("postcode").Equal(item.Zipcode), query.Field("category_ids").Includes(item.CategoryInclude), query.IncludeRowCount(true) ); try { string re = Factual.Fetch("restaurants-us", query); if (!String.IsNullOrEmpty(re)) { Category_ZipCode cate = category_ZipCodeService.Get().FirstOrDefault(t => t.ZipcodeName.Equals(item.Zipcode)); if (cate != null) { dynamic jsonResponse = JsonConvert.DeserializeObject(re); //import to business and update Downloaded if (jsonResponse.response != null && jsonResponse.status == "ok") { dynamic data = jsonResponse.response.data; dynamic total_row_count = jsonResponse.response.total_row_count; dynamic included_rows = jsonResponse.response.included_rows; if (data != null) { JArray listData = data as JArray; if (listData != null) { for (int i = 0; i < listData.Count; i++) { dynamic biz = listData[i]; //insert to business Business bus = new Business() { Id = Guid.NewGuid(), Address = biz.address, Phone = biz.tel, Latitude = biz.latitude ?? 0, Longtitude = biz.longitude ?? 0, Locality = biz.locality, Active = true, BusinessCategoryId = cate.BusinessCategoryId, Country = biz.country, CreateBy = HttpContext.User.Identity.Name, CreateDate = DateTime.Now, Name = biz.name, Region = biz.region, Status = Infrastructure.Domain.Status.Approved, //reference UserId = userId, Zipcode = item.Zipcode }; businessService.Create(bus); } } } cate.TotalRecord = total_row_count == null ? 0 : total_row_count; cate.Downloaded += cate.TotalRecord; category_ZipCodeService.Update(cate); item.TotalDownloaded = cate.Downloaded; item.Availble = cate.TotalRecord; } } } } catch (FactualApiException ce) { } } } return Json(item, JsonRequestBehavior.AllowGet); }
public void Download(string city, string state, string zipcode, string categories, out int total, out int downloaded) { int totalDownload = 0; int totalDownloaded = 0; var query = new Query(); query.And( query.Field("locality").Equal(city), query.Field("region").Equal(state), query.Field("postcode").Equal(zipcode), query.Field("category_ids").Includes(categories), query.IncludeRowCount(true) ); try { string re = Factual.Fetch("restaurants-us", query); if (!String.IsNullOrEmpty(re)) { Category_ZipCode cate = category_ZipCodeService.Get().FirstOrDefault(t => t.ZipcodeName.Equals(zipcode)); if (cate != null) { dynamic jsonResponse = JsonConvert.DeserializeObject(re); //import to business and update Downloaded if (jsonResponse.response != null && jsonResponse.status == "ok") { dynamic data = jsonResponse.response.data; dynamic total_row_count = jsonResponse.response.total_row_count; dynamic included_rows = jsonResponse.response.included_rows; if (data != null) { JArray listData = data as JArray; if (listData != null) { for (int i = 0; i < listData.Count; i++) { dynamic biz = listData[i]; //insert to business Business bus = new Business() { Id = Guid.NewGuid(), Address = biz.address, Phone = biz.tel, Latitude = biz.latitude ?? 0, Longtitude = biz.longitude ?? 0, Locality = biz.locality, Active = true, BusinessCategoryId = cate.BusinessCategoryId, Country = biz.country, CreateBy = "Download Tool", CreateDate = DateTime.Now, Name = biz.name, Region = biz.region, Status = Infrastructure.Domain.Status.Approved, //reference UserId = userId, Zipcode = zipcode }; businessService.Create(bus); } } } totalDownload = cate.TotalRecord = total_row_count == null ? 0 : total_row_count; cate.Downloaded += cate.TotalRecord; totalDownloaded = cate.Downloaded; category_ZipCodeService.Update(cate); } } } } catch (FactualApiException ce) { } total = totalDownload; downloaded = totalDownloaded; }