public TrendsList GetTrends() { TrendsList buzzList = new TrendsList(); try { //RSSConnector rss = new RSSConnector(); //Channel buzzLeaderChannel = rss.GetChannel("http://buzz.yahoo.com/feeds/buzzoverl.xml"); //Channel buzzMoversChannel = rss.GetChannel("http://buzz.yahoo.com/feeds/buzzoverm.xml"); //string html = new HTMLConnector().GetHTMLDocument("http://buzzlog.yahoo.com/overall/"); //YahooTrendsParser parser = new YahooTrendsParser(); //parser.Parse(buzzLeaderChannel, buzzList); //parser.Parse(buzzMoversChannel, buzzList); //parser.Parse(html, buzzList); } catch (Exception exception) { ErrorService.Log("YahooTrendsService", "GetTrends", null, exception); } return buzzList; }
public void Parse(JArray rootTrendsArray, TrendsList trendsList) { LogService.Debug(this.GetType(), "Entering Parse for TwitterTrendsParser"); if (rootTrendsArray != null && rootTrendsArray.Count > 0) { JObject rootObject = (JObject) rootTrendsArray.First; if (rootObject != null) { JArray trendsJArray = rootObject.Value<JArray>("trends"); if (trendsJArray != null) { foreach (JObject trendJObject in trendsJArray) { string name = trendJObject.Value<string>("name"); if (name != null && !name.Contains("#")) { TrendItem trendItem = new TrendItem(name, name, ProviderEnum.Twitter); trendItem.Weight = 1; trendsList.AddTrend(trendItem); } } } } } LogService.Debug(this.GetType(), "Exiting Parse for TwitterTrendsParser"); }
public void Parse(string html, TrendsList trendsList) { const string trendsMarker = "<td class=\"subject\">"; const string trendsEndMarker = "</a>"; const string trendStartMarker = "\">"; int index = 0; int endPos = 0; int startPos = 0; int startMarkerPos = html.IndexOf(trendsMarker); while (startMarkerPos >= 0) { index++; endPos = html.IndexOf(trendsEndMarker, startMarkerPos); startPos = html.IndexOf(trendStartMarker, startMarkerPos + trendsMarker.Length); string trendName = html.Substring(startPos + trendStartMarker.Length, endPos - startPos - trendStartMarker.Length); if (trendName.Length > 0 && trendName.IndexOf(">") < 0 && trendName.IndexOf("<") < 0) { TrendItem trendItem = new TrendItem(trendName, trendName, ProviderEnum.Yahoo); trendItem.Weight = CalculateWeight(index / 2); trendsList.AddTrend(trendItem); } else { LogService.Warn(typeof(YahooTrendsParser), "Error parsing trendname " + trendName); } startMarkerPos = html.IndexOf(trendsMarker, endPos); } }
public TrendsList GetTrends() { string url; switch (iTunesType) { case ITunesTypeEnum.Top10Songs: url = "http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/limit=10/xml"; break; case ITunesTypeEnum.TopMovies: url = "http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topMovies/xml"; break; default: url = "http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/ws/RSS/topsongs/limit=10/xml"; break; } TrendsList trendsList = new TrendsList(); try { AtomConnector AtomConnector = new AtomConnector(); EntryData data = AtomConnector.GetEntryData(url); new ITunesTrendsParser().Parse(data, iTunesType, trendsList); } catch (Exception exception) { ErrorService.Log("ITunesTrendsService", "GetTrends", url, exception); } return trendsList; }
public TrendsList GetTrends() { TrendsList trendsList = CategorizationCacheHelper.ReadTrends(); if (trendsList == null) { trendsList = new TrendsList(); CategoriesList categoriesList = GetCategories(); foreach (CategoryItem categoryItem in categoriesList) { TopicList topicList = categoryItem.TopicList; foreach (TopicItem topicItem in topicList) { TrendItem trendItem = new TrendItem(topicItem.ID, topicItem.Title, ProviderEnum.TheInternetBuzz); trendItem.Weight = 3; trendsList.AddTrend(trendItem); } } trendsList.Sort(); CategorizationCacheHelper.CacheTrends(trendsList); } return trendsList; }
public TrendsList GetTrends() { TrendsList trendsList = new TrendsList(); TrendsList currentTrendsList = new TrendsList(); try { TwitterCredentials accessToken = new TwitterAuthService().Authenticate(); string headerName = "Authorization"; string headerValue = accessToken.User + " " + accessToken.Token; JSONConnector JSONConnector = new JSONConnector(); JArray currentTrendsArray = JSONConnector.GetJSONArrayWithHeader(CURRENT_TRENDS_URL, headerName, headerValue); new TwitterTrendsParser().Parse(currentTrendsArray, currentTrendsList); } catch (Exception exception) { ErrorService.Log("TwitterTrendsService", "GetTrends", null, exception); } if (twitterTrendsQueue.Count >= QUEUE_SIZE) { twitterTrendsQueue.Dequeue(); } twitterTrendsQueue.Enqueue(currentTrendsList); foreach (TrendsList twitterTrendsList in twitterTrendsQueue) { trendsList.AddTrends(twitterTrendsList); } return trendsList; }
protected override void LoadData() { Trace.Write("TrendsControl LoadData() - Start Calling Trends Command"); if (TrendsCommand != null) { TrendsList = TrendsCommand.GetTrends(); } Trace.Write("TrendsControl LoadData() - End Calling Trends Command"); }
public void AddTrends(TrendsList trendsList) { if (trendsList != null) { foreach (TrendItem newTrend in trendsList) { AddTrend(newTrend); } } }
public void Parse(EntryData entryData, TrendsList trendsList) { foreach (Entry entry in entryData.EntryList) { string content = entry.Content; int endPos = content.IndexOf("</a>"); while (endPos > 0) { int startPos = content.Substring(0, endPos).LastIndexOf(">") + 1; if (startPos > 0 && endPos > startPos) { string trendName = content.Substring(startPos, endPos - startPos); TrendItem trendItem = new TrendItem(trendName, trendName, ProviderEnum.Google); int classStartPos = content.Substring(0, endPos).LastIndexOf("span class=") + 12; int classEndPos = content.Substring(0, endPos).IndexOf(">", classStartPos) - 1; if (classStartPos > 0 && classEndPos > classStartPos) { string className = content.Substring(classStartPos, classEndPos - classStartPos); if (className.Contains("Volcanic")) { trendItem.Weight = 5; } else if (className.Contains("On_Fire")) { trendItem.Weight = 4; } else if (className.Contains("Spicy")) { trendItem.Weight = 3; } else if (className.Contains("Medium")) { trendItem.Weight = 2; } else { trendItem.Weight = 1; } } trendsList.AddTrend(trendItem); endPos = content.IndexOf("</a>", endPos + 1); } else { endPos = -1; } } } }
static public void Serialize(TrendsList trendsList) { string filepath = HostingEnvironment.MapPath("~/data/Trends.xml"); Type type = typeof(TrendsList); Type[] extraTypes = new Type[] { typeof(TrendItem), typeof(SuggestionItem) }; lock (guard) { XMLSerializer.Serialize(trendsList, type, extraTypes, filepath); } }
public void Parse(string html, TrendsList trendsList) { const string sectionStartTrendsMarker = "<h2>Hot Topics</h2>"; const string sectionEndTrendsMarker = "</div>"; const string trendsEndMarker = "'"; const string trendStartMarker = "title='"; int index = 0; int sectionStartMarkerPos = html.IndexOf(sectionStartTrendsMarker); if (sectionStartMarkerPos >= 0) { int sectionEndMarkerPos = html.IndexOf(sectionEndTrendsMarker, sectionStartMarkerPos + sectionStartTrendsMarker.Length); if (sectionEndMarkerPos >= sectionStartMarkerPos) { int startPos = html.IndexOf(trendStartMarker, sectionStartMarkerPos + trendStartMarker.Length); int endPos = html.IndexOf(trendsEndMarker, startPos + trendStartMarker.Length); while (endPos > startPos && startPos >= 0 && endPos < sectionEndMarkerPos) { index++; string trendName = html.Substring(startPos + trendStartMarker.Length, endPos - startPos - trendStartMarker.Length); if (trendName.Length > 0 && trendName.IndexOf(">") < 0 && trendName.IndexOf("<") < 0) { TrendItem trendItem = new TrendItem(trendName, trendName, ProviderEnum.Alexa); trendItem.Weight = CalculateWeight(index); trendsList.AddTrend(trendItem); } else { LogService.Warn(typeof(AlexaTrendsParser), "Error parsing trendname " + trendName); } startPos = html.IndexOf(trendStartMarker, endPos + trendsEndMarker.Length); endPos = html.IndexOf(trendsEndMarker, startPos + trendStartMarker.Length); } } else { ErrorService.Log("AlexaTrendsService", "GetTrends", "Parsing Html", new Exception("sectionEndMarkerPos is " + sectionEndMarkerPos)); } } else { ErrorService.Log("AlexaTrendsService", "GetTrends", "Parsing Html", new Exception("sectionStartMarkerPos is " + sectionStartMarkerPos)); } }
public void Parse(IEnumerable channel, TrendsList trendsList) { int index = 0; foreach (Item item in channel) { index++; int pos = item.Title.IndexOf(". "); if (pos > 0) { string trendName = item.Title.Substring(pos + 2); TrendItem trendItem = new TrendItem(trendName, trendName, ProviderEnum.Yahoo); trendItem.Weight = CalculateWeight(index); trendsList.AddTrend(trendItem); } } }
public TrendsList GetTrends() { TrendsList buzzList = new TrendsList(); try { string html = new HTMLConnector().GetHTMLDocument("http://www.alexa.com/whatshot"); AlexaTrendsParser parser = new AlexaTrendsParser(); parser.Parse(html, buzzList); } catch (Exception exception) { ErrorService.Log("AlexaTrendsService", "GetTrends", null, exception); } return buzzList; }
public TrendsList GetTrends() { TrendsList trendsList = new TrendsList(); try { AtomConnector atomConnector = new AtomConnector(); EntryData entryData = atomConnector.GetEntryData("http://www.google.com/trends/hottrends/atom/hourly"); new GoogleTrendsParser().Parse(entryData, trendsList); } catch (Exception exception) { ErrorService.Log("GoogleTrendsService", "GetTrends", null, exception); } return trendsList; }
public void Parse(JObject rootObject, TrendsList trendsList) { LogService.Debug(this.GetType(), "Entering Parse for WhatTheThrendTrendsParser"); try { JArray trendsJArray = rootObject.Value<JArray>("trends"); if (trendsJArray != null) { foreach (JObject trendJObject in trendsJArray) { string name = trendJObject.Value<string>("name"); if (name != null && !name.Contains("#") && !name.Contains("WTT test") && !name.Contains("ttrtpt")) { JToken t; trendJObject.TryGetValue("description", out t); if (t.HasValues) { JObject descriptionJSONObject = trendJObject.Value<JObject>("description"); if (descriptionJSONObject != null) { string text = descriptionJSONObject.Value<string>("text"); if (text != null) { TrendItem trendItem = new TrendItem(name, name, ProviderEnum.WhatTheTrend); trendItem.Weight = 5; trendsList.Add(trendItem); ExplanationItem explanationLItem = new ExplanationItem(trendItem.Title, trendItem.Title, text); ExplanationCacheHelper.CacheExplanationItem(trendItem.Title, explanationLItem); } } } } } } } catch (Exception exception) { ErrorService.Log("WhatTheTrendTrendsService", "Parse", null, exception); } LogService.Debug(this.GetType(), "Exiting Parse for WhatTheThrendTrendsParser"); }
public void Parse(EntryData data, ITunesTypeEnum iTunesType, TrendsList trendsList) { LogService.Debug(this.GetType(), "Entering Parse for ITunesTrendsParser"); try { EntryList entryList = data.EntryList; int i = 0; foreach (Entry entry in entryList) { string name; CategoryEnum category; switch (iTunesType) { case ITunesTypeEnum.Top10Songs: name = entry.Get("im:artist"); category = CategoryEnum.Music; break; default: name = entry.Get("im:name"); category = CategoryEnum.Movie; break; } TrendItem trendItem = new TrendItem(name, name, ProviderEnum.ITunes); trendItem.ImageURL = entry.Get("im:image"); trendItem.Weight = CalculateWeight(i); trendItem.Category = category; trendsList.Add(trendItem); i++; } } catch (Exception exception) { ErrorService.Log("ITunesTrendsParser", "Parse", null, exception); } LogService.Debug(this.GetType(), "Exiting Parse for ITunesTrendsParser"); }
public TrendsList GetTrends() { string urlTemplate; switch (trendsType) { case WhatTheTrendTypeEnum.Current: urlTemplate = "http://api.whatthetrend.com/api/v2/trends.json?api_key={0}"; break; case WhatTheTrendTypeEnum.MostEdited: urlTemplate = "http://api.whatthetrend.com/api/v2/trends/active.json?api_key={0}"; break; default: urlTemplate = "http://api.whatthetrend.com/api/v2/trends.json?api_key={0}"; break; } TrendsList trendsList = new TrendsList(); try { string api = ConfigService.GetConfig(ConfigKeys.WHATTHETREND_API_KEY, ""); string url = string.Format(urlTemplate, api); JSONConnector JSONConnector = new JSONConnector(); JObject currentTrendsRootJSONObject = JSONConnector.GetJSONObject(url); new WhatTheThrendTrendsParser().Parse(currentTrendsRootJSONObject, trendsList); } catch (Exception exception) { ErrorService.Log("WhatTheTrendTrendsService", "GetTrends", urlTemplate, exception); } return trendsList; }
public static void CacheTrends(TrendsList trendsList) { int cacheExpiration = int.MaxValue; CacheService.Put("trends", cacheExpiration, trendsList); }
static private TrendsList BuildTrends() { TrendsList trendsList = null; try { ManualResetEvent[] doneEvents = new ManualResetEvent[8]; doneEvents[0] = new ManualResetEvent(false); TrendsWorkerThread googleWorkerThread = new TrendsWorkerThread(new GoogleTrendsService(), doneEvents[0]); ThreadPool.QueueUserWorkItem(googleWorkerThread.ThreadPoolCallback); doneEvents[1] = new ManualResetEvent(false); TrendsWorkerThread twitterWorkerThread = new TrendsWorkerThread(new TwitterTrendsService(), doneEvents[1]); ThreadPool.QueueUserWorkItem(twitterWorkerThread.ThreadPoolCallback); doneEvents[2] = new ManualResetEvent(false); TrendsWorkerThread yahooWorkerThread = new TrendsWorkerThread(new YahooTrendsService(), doneEvents[2]); ThreadPool.QueueUserWorkItem(yahooWorkerThread.ThreadPoolCallback); doneEvents[3] = new ManualResetEvent(false); TrendsWorkerThread whatTheTrendCurrentWorkerThread = new TrendsWorkerThread(new WhatTheTrendTrendsService(WhatTheTrendTypeEnum.Current), doneEvents[3]); ThreadPool.QueueUserWorkItem(whatTheTrendCurrentWorkerThread.ThreadPoolCallback); doneEvents[4] = new ManualResetEvent(false); TrendsWorkerThread whatTheTrendMostEditedWorkerThread = new TrendsWorkerThread(new WhatTheTrendTrendsService(WhatTheTrendTypeEnum.MostEdited), doneEvents[4]); ThreadPool.QueueUserWorkItem(whatTheTrendMostEditedWorkerThread.ThreadPoolCallback); doneEvents[5] = new ManualResetEvent(false); TrendsWorkerThread alexaWorkerThread = new TrendsWorkerThread(new AlexaTrendsService(), doneEvents[5]); ThreadPool.QueueUserWorkItem(alexaWorkerThread.ThreadPoolCallback); doneEvents[6] = new ManualResetEvent(false); TrendsWorkerThread iTunesSongsWorkerThread = new TrendsWorkerThread(new ITunesTrendsService(ITunesTypeEnum.Top10Songs), doneEvents[6]); ThreadPool.QueueUserWorkItem(iTunesSongsWorkerThread.ThreadPoolCallback); doneEvents[7] = new ManualResetEvent(false); TrendsWorkerThread iTunesMoviesWorkerThread = new TrendsWorkerThread(new ITunesTrendsService(ITunesTypeEnum.TopMovies), doneEvents[7]); ThreadPool.QueueUserWorkItem(iTunesMoviesWorkerThread.ThreadPoolCallback); WaitHandle.WaitAll(doneEvents); trendsList = new TrendsList(); trendsList.AddTrends(googleWorkerThread.TrendsList); trendsList.AddTrends(yahooWorkerThread.TrendsList); trendsList.AddTrends(twitterWorkerThread.TrendsList); trendsList.AddTrends(whatTheTrendCurrentWorkerThread.TrendsList); trendsList.AddTrends(whatTheTrendMostEditedWorkerThread.TrendsList); trendsList.AddTrends(alexaWorkerThread.TrendsList); trendsList.AddTrends(iTunesSongsWorkerThread.TrendsList); trendsList.AddTrends(iTunesMoviesWorkerThread.TrendsList); if (trendsList != null && trendsList.Count() > 0) { trendsList.Sort(new TrendItemComparer(TrendItemComparerEnum.Title)); } } catch (Exception exception) { ErrorService.Log("TrendsBuilder", "BuildTrends", "", exception); } return trendsList; }
public static void CacheTrends(TrendsList trendsList) { int cacheExpiration = ConfigService.GetConfig(ConfigKeys.THEINTERNETBUZZ_CATEGORIES_EXPIRATION, 60); CacheService.Put("yearly-trends", cacheExpiration, trendsList); }
static private void PreLoadTrends(TrendsList trendsList) { if (trendsList != null) { TopicService topicService = new TopicService(); SearchService searchService = new SearchService(); VideoService videoService = new VideoService(); foreach (TrendItem trendItem in trendsList) { String query = trendItem.Title; topicService.GetTopic(query); int pageMax = ConfigService.GetConfig(ConfigKeys.THEINTERNETBUZZ_SEARCH_COUNT_PER_PAGE_PER_PROVIDER, 8); SearchContext searchContext = new SearchContext(query, 1, pageMax); searchContext.SearchType = SearchTypeEnum.Web; searchService.Search(searchContext); searchContext.SearchType = SearchTypeEnum.News; searchService.Search(searchContext); videoService.Search(query); } } }
static private void PreLoadTrendsImage(TrendsList trendsList) { if (trendsList != null) { SearchService searchService = new SearchService(); foreach (TrendItem trendItem in trendsList) { if (trendItem.ImageURL == null) { String query = trendItem.Title; SearchContext searchContext = new SearchContext(query, 1, 1); searchContext.SearchType = SearchTypeEnum.Image; SearchResultList searchResultList = searchService.Search(searchContext); if (searchResultList.Count() > 0) { SearchResultItem item = (SearchResultItem)searchResultList.Item(0); trendItem.ImageURL = item.ImageURL; } } if (trendItem.TileImageURL == null && trendItem.ImageURL != null) { int imageSize; switch (trendItem.Weight) { case 1: imageSize = 150; break; case 2: imageSize = 150; break; case 3: imageSize = 150; break; case 4: imageSize = 150; break; case 5: imageSize = 150; break; default: imageSize = 150; break; } string url = "http://src.sencha.io/" + imageSize + "/" + trendItem.ImageURL; HttpStatusCode status = new HTTPConnector().GetStatus(url, "image/jpeg,image/gif.image/png"); if (status == HttpStatusCode.OK) { trendItem.TileImageURL = url; } } } } }