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 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 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); } }
private void DisplayTrend(TrendItem trendItem) { Response.Write("<url>"); Response.Write("<loc>" + URLBuilder.BuildFullLiveURL("topic", trendItem.Title) + "</loc>"); Response.Write("<changefreq>hourly</changefreq>"); Response.Write("<priority>0.5</priority>"); Response.Write("</url>"); }
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; } } } }
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 int CompareTo(TrendItem trend2, TrendItemComparerEnum sortBy) { switch (sortBy) { case TrendItemComparerEnum.ID: return ID.CompareTo(trend2.ID); case TrendItemComparerEnum.Title: return Title.CompareTo(trend2.Title); case TrendItemComparerEnum.Weight: return Weight.CompareTo(trend2.Weight); default: return ID.CompareTo(trend2.ID); } }
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 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 AddTrend(TrendItem newTrend) { TrendItem trend = GetTrend(newTrend.ID); if (trend == null) { Add(newTrend); } else { trend.Provider = newTrend.Provider; if (newTrend.Weight > trend.Weight) { trend.Weight = newTrend.Weight; } if (trend.Weight < 5) { trend.Weight = (short)(trend.Weight + 1); } } }
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"); }