public HealthCareProviderRepository()
        {
            if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["Factual.oAuthKey"]) ||
                string.IsNullOrEmpty(ConfigurationManager.AppSettings["Factual.oAuthSecret"]))
                throw new ConfigurationErrorsException("Missing Factual API keys in your web.config.");

            _factual = new Factual(ConfigurationManager.AppSettings["Factual.oAuthKey"], ConfigurationManager.AppSettings["Factual.oAuthSecret"]);
        }
Ejemplo n.º 2
0
        public static String fetchFromFactual(string lat, string lon)
        {
            Factual factual = new Factual(MY_KEY, MY_SECRET);

            // Set the request timeouts back to default 100000 and 300000 respectively
            factual.ConnectionTimeout = null;
            factual.ReadTimeout = null;

            double dLat = double.Parse(lat);
            double dLon = double.Parse(lon);

            string factualJson = factual.Fetch("places", new Query().WithIn(new Circle(dLat, dLon, 2000)).Limit(50));

            return factualJson;
        }
Ejemplo n.º 3
0
        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();
        }
 public FactualPlacesRepository()
 {
     _factual = new Factual(HttpContext.Current.Application["factkey"] as string,(HttpContext.Current.Application["factsec"] as string));
 }
Ejemplo n.º 5
0
        public PlaceService()
        {
            _factual = new Factual(ConfigurationManager.AppSettings["attractions.factual.key"], ConfigurationManager.AppSettings["attractions.factual.secret"]);

            _couchbaseHelper = new CouchBaseHelper();
        }