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(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");
        }
Esempio n. 3
0
        public EntryData GetEntryData(string url) 
        {

            WebRequest request = WebRequest.Create(url);
            XmlDocument atomDoc = null;

            using (WebResponse response = request.GetResponse())
            {
                Stream atomStream = response.GetResponseStream();
                
                atomDoc = new XmlDocument();
                atomDoc.Load(atomStream);

                atomStream.Close();
                response.Close();
            }

            XmlNamespaceManager nsmanager = new XmlNamespaceManager(atomDoc.NameTable);
            nsmanager.AddNamespace("default", "http://www.w3.org/2005/Atom");

            EntryData entryData = new EntryData();

            EntryList entryList = new EntryList();
            entryData.EntryList = entryList;

            XmlNode updatedNode = atomDoc.SelectSingleNode("default:feed/default:updated", nsmanager);
            if (updatedNode != null)
            {
                // format 2009-12-24T05:53:20Z
                // format 2013-01-23T11:51:59-07:0 +0
                string dateString = updatedNode.InnerText;
                if (dateString.Contains("-07:0"))
                {
                    dateString = dateString.Replace("-07:0", " -7");
                }
                else
                {
                    dateString = dateString.Substring(0, dateString.Length - 1) + " +0";
                }
                DateTime updatedDate = DateParser.Parse(dateString, "yyyy'-'MM'-'dd'T'HH':'mm':'ss z");
                entryData.LastBuildDate = updatedDate;
            }

            XmlNodeList atomEntryNodeList = atomDoc.SelectNodes("default:feed/default:entry", nsmanager);

            if (atomEntryNodeList != null)
            {
                Console.WriteLine("LIST " + atomEntryNodeList.Count);

                foreach (XmlNode atomEntryNode in atomEntryNodeList)
                {
                    Entry entry = new Entry();

                    foreach (XmlNode childNode in atomEntryNode.ChildNodes)
                    {
                        if (childNode.Name == "title")
                        {
                            entry.Title = childNode.InnerText;
                        }
                        else if (childNode.Name == "id")
                        {
                            entry.ID = childNode.InnerText;
                        }
                        else if (childNode.Name == "content")
                        {
                            entry.Content = childNode.InnerText;
                        }
                        else
                        {
                            entry.Set(childNode.Name, childNode.InnerText);
                        }
                    }
                    entryList.Add(entry);
                }
            }
            return entryData;
        }