public void Parse(JObject searchResultsJSONObject, SearchResultList searchResultList) { try { JArray resultsJArray = searchResultsJSONObject.Value<JArray>("statuses"); foreach (JObject resultJObject in resultsJArray) { SearchResultItem resultItem = new SearchResultItem(); resultItem.Provider = ProviderEnum.Twitter; string content = resultJObject.Value<string>("text"); if (content != null && !content.Contains("#")) { resultItem.Abstract = content.ParseTwitterURL().ParseTwitterUsername().ParseTwitterHashtag(); JObject userDataJObject = resultJObject.Value<JObject>("user"); string image = userDataJObject.Value<string>("profile_image_url"); resultItem.ImageURL = image; string name = userDataJObject.Value<string>("name"); resultItem.Title = name; string screenName = userDataJObject.Value<string>("screen_name"); string url = "http://www.twitter.com/" + screenName; resultItem.URL = url; string publishedDateValue = resultJObject.Value<string>("created_at"); if (publishedDateValue != null) { // format: Sun, 30 Oct 2011 19:54:11 +0000",(publishedDateValue, "ddd, dd MMM yyyy HH':'mm':'ss z"); // new format Mon Sep 24 03:35:21 +0000 2012 //publishedDateValue = publishedDateValue.Replace("+0000", "+0"); //DateTime publishedDate = DateParser.Parse(publishedDateValue, "ddd MMM HH':'mm':'ss z yyyy"); //resultItem.PublishedDate = publishedDate; } searchResultList.Add(resultItem); } } } catch (Exception exception) { ErrorService.Log("TwitterSearchParser", "Search", searchResultList.ToString(), exception); } }
public void Parse(XmlDocument xmlDocument, SearchResultList searchResultList) { string urlTemplate = "http://farm{0}.staticflickr.com/{1}/{2}_{3}.jpg"; try { XmlNodeList resultNodes = xmlDocument.SelectNodes("rsp/photos/photo"); if (resultNodes != null) { foreach (XmlNode resultNode in resultNodes) { Console.WriteLine("resultNode"); SearchResultItem resultItem = new SearchResultItem(); resultItem.Provider = ProviderEnum.Flickr; string id = resultNode.Attributes["id"].Value; string secret = resultNode.Attributes["secret"].Value; string server = resultNode.Attributes["server"].Value; string farm = resultNode.Attributes["farm"].Value; string title = resultNode.Attributes["title"].Value; string url = string.Format(urlTemplate, farm, server, id, secret); resultItem.ImageURL = url; resultItem.Title = title; Console.WriteLine(url); searchResultList.Add(resultItem); } } } catch (Exception exception) { ErrorService.Log("FlickrSearchParser", "Search", searchResultList.ToString(), exception); } }
// INCORRECT RESULT //{ // "responseData": null, // "responseDetails": "Quota Exceeded. Please see http://code.google.com/apis/websearch", // "responseStatus": 403 //} // CORRECT RESULT // { // "responseData": { // "results": [ // { // "GsearchResultClass": "GwebSearch", // "unescapedUrl": "http://en.wikipedia.org/wiki/Stefan_Savi%C4%87", // "url": "http://en.wikipedia.org/wiki/Stefan_Savi%25C4%2587", // "visibleUrl": "en.wikipedia.org", // "cacheUrl": "http://www.google.com/search?q=cache:HWRCbR1U9oEJ:en.wikipedia.org", // "title": "<b>Stefan Savi?</b> - Wikipedia, the free encyclopedia", // "titleNoFormatting": "Stefan Savi? - Wikipedia, the free encyclopedia", // "content": "<b>Stefan Savi?</b> (Cyrillic: ?????? ?????; born 8 January 1991) is a Montenegrin footballer who plays for Manchester City in the Premier League. A centre-back <b>...</b>" // } // ], // "cursor": { // "resultCount": "55,500", // "pages": [ // { // "start": "0", // "label": 1 // } // ], // "estimatedResultCount": "55500", // "currentPageIndex": 0, // "moreResultsUrl": "http://www.google.com/search?oe=utf8&ie=utf8&source=uds&start=0&hl=en&q=Stefan+Savic", // "searchResultTime": "0.18" // } // }, // "responseDetails": null, // "responseStatus": 200 //} public void Parse(JObject searchResultsJSONObject, SearchResultList searchResultList) { try { JObject responseDataJObject = searchResultsJSONObject.Value<JObject>("responseData"); if (responseDataJObject != null) { JArray resultsJArray = responseDataJObject.Value<JArray>("results"); foreach (JObject resultJObject in resultsJArray) { SearchResultItem resultItem = new SearchResultItem(); resultItem.Provider = ProviderEnum.Google; string title = resultJObject.Value<string>("titleNoFormatting"); resultItem.Title = TextCleaner.RemoveHtml(title); string content = resultJObject.Value<string>("content"); resultItem.Abstract = TextCleaner.RemoveHtml(content); string url = resultJObject.Value<string>("unescapedUrl"); resultItem.URL = TextCleaner.RemoveHtml(url); string publisher = resultJObject.Value<string>("publisher"); if (publisher != null) { resultItem.Source = publisher; } string publishedDateValue = resultJObject.Value<string>("publishedDate"); if (publishedDateValue != null) { // format: Thu, 19 Nov 2009 13:05:26 -08:00 DateTime publishedDate = DateParser.Parse(publishedDateValue, "ddd, dd MMM yyyy HH':'mm':'ss zzz"); resultItem.PublishedDate = publishedDate; } searchResultList.Add(resultItem); } } } catch (Exception exception) { ErrorService.Log("GoogleSearchParser", "Search", searchResultList.ToString(), exception); } }