public searchresults GetDeepSearchResults(string address, string citystatezip) { try { Hashtable p = new Hashtable { { "zws-id", Zwsid }, { "address", address }, { "citystatezip", citystatezip } }; searchresults search = (searchresults)CallAPI(ZillowURI.DeepSearchResults, p, typeof(searchresults)); if (search == null) { throw new NullReferenceException("searchresults API value is null"); } if (int.Parse(search.message.code) != 0) { throw new Exception(string.Format("Zillow Error #{0}: {1}", search.message.code, search.message.text)); } return(search); } catch (Exception ex) { Debug.WriteLine(ex.Message); throw ex; } }
public SearchResponse MapSearchResponse(searchresults searchresults) { if (searchresults?.message == null) { return(null); } var response = new SearchResponse { Success = string.Equals("0", searchresults.message.code) }; if (!response.Success) { response.ErrorMessages = new[] { searchresults.message.text }; response.ErrorCode = searchresults.message.code; return(response); } response.LimitWarning = searchresults.message.limitwarningSpecified && searchresults.message.limitwarning; response.SearchResults = searchresults.response?.results?.Select(MapPropertyToSearchResult)?.ToList(); return(response); }
public searchresults GetSearchResults(string address, string citystatezip) { try { Hashtable p = new Hashtable { { "zws-id", Zwsid }, { "address", address }, { "citystatezip", citystatezip }, { "rentzestimate", "true" } }; searchresults search = (searchresults)CallAPI(ZillowURI.SearchResults, p, typeof(searchresults)); if (search == null) { throw new NullReferenceException("searchresults API value is null"); } if (int.Parse(search.message.code) != 0) { throw new Exception(string.Format("Zillow Error #{0}: {1}", search.message.code, search.message.text)); } return(search); } catch (Exception ex) { if (ex.InnerException != null && ex.InnerException.Message.Contains("504")) { if (zwsidExcount_GetSearchResults.Item1.Equals(Zwsid)) { zwsidExcount_GetSearchResults = new Tuple <string, int>(Zwsid, zwsidExcount_GetSearchResults.Item2 + 1); } else { zwsidExcount_GetSearchResults = new Tuple <string, int>(Zwsid, 0); } if (zwsidExcount_GetSearchResults.Item2 > 20) // we tried 20 times and got the 504 error. Need to log this. for now just skip { throw new Exception("504 Error > 20 Times! Address:" + address + " " + citystatezip); } GetSearchResults(address, citystatezip); } Debug.WriteLine(ex.Message); throw ex; } }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { <?xml version="1.0" encoding="utf-8" ?> <searchresults total_results="0"> </searchresults>�Aj:��:d���:https://services.addons.mozilla.org/fr/firefox/api/1.5/search/guid:%7B972ce4c6-7e08-4474-a285-3208198ce6fd%7D?src=firefox&appOS=WINNT&appVersion=32.0.3&tMain=60095&tFirstPaint=69234&tSessionRestored=73618security-infoFnhllAKWRHGAlo+ESXykKAAAAAAAAAAAwAAAAAAAAEaphjojKOpF0qJaNXyu+n+CAAQAAgAAAAAAAAAAAA
public static ZillowEntityModel ParseEmailToZillowEntity(string value) { var entity = new ZillowEntityModel(); string askingPrice = string.Empty; DateTime?priceDropOn = null; value = Regex.Replace(value, @"\s\s+", " "); // remove all extra whitespace int endAddressIndex = value.ToLower().IndexOf(". your '"); int startAddressIndex = value.ToLower().IndexOf("new listing:"); if (startAddressIndex == -1) { startAddressIndex = value.ToLower().IndexOf("price drop:"); priceDropOn = DateTime.Now.Date; askingPrice = GetAskingPrice("spanclass3D\"dummy\"style3D\"font-weight:normal;font-size:20px;line-height:30px;font-family:Open-sans,Arial;\">$", "</span>", value); } else { askingPrice = GetAskingPrice("$", ".", value); } if (startAddressIndex != -1 && endAddressIndex != -1) { int length = (endAddressIndex - 12) - startAddressIndex; string address = value.Substring(startAddressIndex + 12, length).Trim(); //now that i have address I need to seperate street from city,st int endOfStreetComma = address.IndexOf(','); int endOfStreetCondoNum = address.IndexOf('#'); string street = string.Empty; string cityStZip = address.Substring(endOfStreetComma + 1).Trim(); if (endOfStreetCondoNum != -1) { street = address.Substring(0, endOfStreetCondoNum).Trim(); } //use condo num to set 'street' instead of endOfStreetComma else { street = address.Substring(0, endOfStreetComma).Trim(); } var key = ZillowClientHelper.GetAvailableClientKey(); ZillowClient client = new ZillowClient(key); ZillowClientHelper.IncrementKeyCount(key); searchresults result = new searchresults(); try { result = client.GetSearchResults(street, cityStZip); } catch { } if (result.response != null) { foreach (SimpleProperty prop in result.response.results) { // annoying GetUpdatedPropertyDetails never works - 501 error, protected data //key = ZillowClientHelper.GetAvailableClientKey(); //ZillowClient client1 = new ZillowClient(key); //ZillowClientHelper.IncrementKeyCount(key); //var propDets = client1.GetUpdatedPropertyDetails(prop.zpid); int intAskingPrice = 0; if (askingPrice != string.Empty) { intAskingPrice = Convert.ToInt32(askingPrice); } int intRentZest = 0; if (prop.rentzestimate != null) { intRentZest = Convert.ToInt32(prop.rentzestimate.amount.Value); } int intZest = 0; if (prop.zestimate != null) { intZest = Convert.ToInt32(prop.zestimate.amount.Value); } entity = new ZillowEntityModel() { zpid = prop.zpid, address = street + " " + cityStZip, // keep for sake of seeing what I'm parsing above. street = prop.address.street, city = prop.address.city, state = prop.address.state, zipcode = prop.address.zipcode, urlHome = prop.links.homedetails, rentZestimate = intRentZest, zestimate = intZest, askingPrice = intAskingPrice, isFavorite = false, priceDropOn = priceDropOn, isDeleted = false }; } } else { entity = new ZillowEntityModel() { address = street + " " + cityStZip, // keep for sake of seeing what I'm parsing above. isDeleted = false } }; } return(entity); }
private async Task <RealEstateSearchResults> searchRestate(string address, string city, string state, string zipcode) { using (HttpClient client = new HttpClient()) { string citystatezip = string.Empty; if (!string.IsNullOrEmpty(city) && !string.IsNullOrEmpty(state)) { citystatezip = string.Format("{0} {1}", city, state); } else if (!string.IsNullOrEmpty(zipcode)) { citystatezip = zipcode; } try { client.BaseAddress = new Uri(WEB_SERVICE_URL); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml")); //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xhtml+xml")); //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html")); //client.DefaultRequestHeaders.AcceptLanguage.Add(new StringWithQualityHeaderValue("en-US")); //client.DefaultRequestHeaders.AcceptLanguage.Add(new StringWithQualityHeaderValue("en", 0.8)); var response = await client.GetAsync(String.Format("/webservice/GetSearchResults.htm?zws-id={0}&address={1}&citystatezip={2}", API_KEY, address, citystatezip)); response.EnsureSuccessStatusCode(); string streamResult = await response.Content.ReadAsStringAsync(); streamResult = "<searchresults>" + streamResult.Substring(38 + 302); streamResult = streamResult.Replace("</SearchResults:searchresults>", "</searchresults>"); XmlDocument doc = new XmlDocument(); doc.LoadXml(streamResult); string json = JsonConvert.SerializeXmlNode(doc); ZillowResponse zResponse = JsonConvert.DeserializeObject <ZillowResponse>(json); Console.Out.WriteLine(json); searchresults oresult = zResponse.searchresults; if (oresult != null && oresult is searchresults) { searchresults searchResult = oresult as searchresults; Message msg = searchResult.message; RealEstateSearchResults restateSearchResults = new RealEstateSearchResults(); if (msg != null && msg.code != null) { errorMap.TryGetValue(msg.code, out restateSearchResults.Error); } if (msg.limitwarning && "0".CompareTo(msg.code) == 0) { if (searchResult.response.results.result != null) { restateSearchResults.Results = new List <RealEstateSearchResult>(); foreach (SimpleProperty result in searchResult.response.results.result) { RealEstateSearchResult sResult = new RealEstateSearchResult { Address = createAddress(result.address), Links = createLinks(result.links), Estimate = createEstimate(result.zestimate), RentalEstimate = createEstimate(result.rentzestimate), NeighborHoods = createNeighborHoods(result.localRealEstate) }; restateSearchResults.Results.Add(sResult); } } else { restateSearchResults.Error = ErrorCodes.LIMIT_REACHED; } } else { if (!msg.limitwarning) { restateSearchResults.Error = ErrorCodes.LIMIT_REACHED; } } return(restateSearchResults); } } catch (HttpRequestException httpRequestException) { Console.Out.WriteLine(httpRequestException); return(new RealEstateSearchResults { Error = ErrorCodes.SERVER_ERROR }); } catch (Exception ex) { Console.Out.WriteLine(ex); return(new RealEstateSearchResults { Error = ErrorCodes.SERVER_ERROR }); } } return(new RealEstateSearchResults { Error = ErrorCodes.SERVER_ERROR }); }
/// <summary> /// Geocodes and returns the result. /// </summary> /// <param name="street"></param> /// <param name="houseNumber"></param> /// <param name="country"></param> /// <param name="postalCode"></param> /// <param name="commune"></param> /// <returns></returns> public IGeoCoderResult Code( string country, string postalCode, string commune, string street, string houseNumber) { // build the request url. var builder = new StringBuilder(); builder.Append(street); builder.Append(" "); builder.Append(houseNumber); builder.Append(" "); builder.Append(postalCode); builder.Append(" "); builder.Append(commune); builder.Append(" "); builder.Append(country); builder.Append(" "); string url = string.Format(System.Globalization.CultureInfo.InvariantCulture, _geocodingUrl + "&format=xml&polygon=1&addressdetails=1", builder); // create the source and get the xml. IXmlSource source = this.DownloadXml(url); // create the kml. var search_doc = new SearchDocument(source); // check if there are responses. var res = new GeoCoderResult(); res.Accuracy = AccuracyEnum.UnkownLocationLevel; if (search_doc.Search is searchresults) { searchresults result_v1 = search_doc.Search as searchresults; if (result_v1.place != null && result_v1.place.Length > 0) { double latitude; double longitude; if (double.TryParse(result_v1.place[0].lat, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out latitude) && double.TryParse(result_v1.place[0].lon, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out longitude)) { res.Latitude = latitude; res.Longitude = longitude; res.Text = result_v1.place[0].display_name; switch (result_v1.place[0].@class) { case "place": switch (result_v1.place[0].type) { case "town": res.Accuracy = AccuracyEnum.TownLevel; break; case "house": res.Accuracy = AccuracyEnum.AddressLevel; break; } break; case "highway": res.Accuracy = AccuracyEnum.StreetLevel; break; case "boundary": res.Accuracy = AccuracyEnum.PostalCodeLevel; break; } } } } else if (search_doc.Search is OsmSharp.Xml.Nominatim.Reverse.v1.reversegeocode) { reversegeocode result_v1 = search_doc.Search as OsmSharp.Xml.Nominatim.Reverse.v1.reversegeocode; if (result_v1.result != null && result_v1.result.Length > 0) { double latitude; double longitude; if (double.TryParse(result_v1.result[0].lat, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out latitude) && double.TryParse(result_v1.result[0].lon, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out longitude)) { res.Latitude = latitude; res.Longitude = longitude; res.Text = result_v1.result[0].Value; res.Accuracy = AccuracyEnum.UnkownLocationLevel; } } } return(res); }