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;
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        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));
            }
        }
Ejemplo n.º 6
0
        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);
                }
            }
        }