public static List<ArticleType> SampleList() { string path = "C:\\Users\\Kgosi\\Documents\\Visual Studio 2012\\Projects\\TheOne\\TheOne\\App_Data\\Articles.xml"; WebRequest request = WebRequest.Create(path); WebResponse response = request.GetResponse(); StringBuilder sb = new StringBuilder(""); Stream rssStream = response.GetResponseStream(); XmlDocument rssDoc = new XmlDocument(); rssDoc.Load(path); XmlNodeList rssItems = rssDoc.SelectNodes("Articles/Article"); var itemList = new List<ArticleType>(); for (int i = 0; i < rssItems.Count; i++) { var tempItem = new ArticleType(); tempItem.imageUrl = rssItems[i]["ImageURL"].InnerText; tempItem.imageCaption = rssItems[i]["ImageCaption"].InnerText; tempItem.heading = rssItems[i]["Heading"].InnerText; tempItem.source = rssItems[i]["Source"].InnerText; tempItem.genre = rssItems[i]["Genre"].InnerText; tempItem.content = rssItems[i]["Content"].InnerText; tempItem.link = rssItems[i]["Link"].InnerText; if (Validators.ValidateArticle(tempItem)) { itemList.Add(tempItem); } } return itemList; }
public static bool ValidateArticle(ArticleType article) { bool isValid = true; if (String.IsNullOrEmpty(article.heading) || String.IsNullOrEmpty(article.content)) { isValid = false; } return isValid; }
public static List<ArticleType> YahooList(string category) { var itemList = new List<ArticleType>(); try { WebRequest request = WebRequest.Create("http://news.yahoo.com/rss/" + category); WebResponse response = request.GetResponse(); StringBuilder sb = new StringBuilder(""); Stream rssStream = response.GetResponseStream(); XmlDocument rssDoc = new XmlDocument(); rssDoc.Load(rssStream); XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item"); for (int i = 0; i < rssItems.Count; i++) { var tempItem = new ArticleType(); //tempItem.isMain = (i == 0); if (rssItems[i]["media:content"] != null) { var imageUrl = rssItems[i]["media:content"].Attributes[0].InnerText; tempItem.imageUrl = imageUrl;//(tempItem.isMain) ? String.Concat("http", Regex.Split(imageUrl, "http")[2]) : imageUrl; } tempItem.heading = HttpUtility.HtmlDecode(rssItems[i]["title"].InnerText); tempItem.link = rssItems[i]["link"].InnerText; tempItem.content = HttpUtility.HtmlDecode(rssItems[i]["description"].InnerText); tempItem.source = (rssItems[i]["source"] != null) ? String.Concat("Source : ", HttpUtility.HtmlDecode(rssItems[i]["source"].InnerText)) : String.Empty; if (!String.IsNullOrEmpty(rssItems[i]["pubDate"].InnerText)) { var pubDate = DateTime.Now.Subtract(DateTime.Parse(rssItems[i]["pubDate"].InnerText)).ToString(); tempItem.pubDate = Helpers.PublishDateTime(pubDate); } Regex regex = new Regex(@"</?\w+((\s+\w+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)+\s*|\s*)/?>", RegexOptions.Singleline); tempItem.content = Regex.Replace(tempItem.content, regex.ToString(), String.Empty); if (Validators.ValidateArticle(tempItem)) { itemList.Add(tempItem); } } } catch (Exception) { //throw; } return itemList; }
public static List<ArticleType> ReutersList(string category) { var itemList = new List<ArticleType>(); var url = String.Empty; switch (category) { case "health": url = "http://feeds.reuters.com/reuters/lifestyle"; break; case "tech": url = "http://feeds.reuters.com/reuters/technologyNews"; break; case "business": url = "http://feeds.reuters.com/reuters/businessNews"; break; case "entertainment": url = "http://feeds.reuters.com/reuters/entertainment"; break; case "sports": url = "http://feeds.reuters.com/reuters/sportsNews"; break; default: url = "http://feeds.reuters.com/reuters/topNews"; break; } try { WebRequest request = WebRequest.Create("http://feeds.reuters.com/Reuters/worldNews");//WebRequest.Create(path); WebResponse response = request.GetResponse(); StringBuilder sb = new StringBuilder(""); Stream rssStream = response.GetResponseStream(); XmlDocument rssDoc = new XmlDocument(); rssDoc.Load(rssStream); XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item"); for (int i = 0; i < rssItems.Count; i++) { var tempItem = new ArticleType(); tempItem.imageUrl = Regex.Match(rssItems[i].InnerXml, "<img.*?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase).Groups[1].Value; tempItem.heading = HttpUtility.HtmlDecode(rssItems[i]["title"].InnerText); tempItem.content = HttpUtility.HtmlDecode(rssItems[i]["description"].InnerText); tempItem.link = rssItems[i]["link"].InnerText; Regex regex = new Regex(@"</?\w+((\s+\w+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)+\s*|\s*)/?>", RegexOptions.Singleline); tempItem.content = Regex.Replace(tempItem.content, regex.ToString(), String.Empty); if (Validators.ValidateArticle(tempItem)) { itemList.Add(tempItem); } } } catch (Exception) { //throw; } return itemList; }
public static List<ArticleType> TimesLiveList(string category) { var itemList = new List<ArticleType>(); var url = String.Empty; switch (category) { case "health": url = "http://www.timeslive.co.za/lifestyle/?service=rss"; break; case "tech": url = "http://www.timeslive.co.za/scitech/?service=rss"; break; case "business": return null; case "entertainment": url = "http://www.timeslive.co.za/entertainment/?service=rss"; break; case "sports": url = "http://www.timeslive.co.za/sport/?service=rss"; break; default: url = "http://www.timeslive.co.za/?service=rss"; break; } try { WebRequest request = WebRequest.Create(url); WebResponse response = request.GetResponse(); StringBuilder sb = new StringBuilder(""); Stream rssStream = response.GetResponseStream(); XmlDocument rssDoc = new XmlDocument(); rssDoc.Load(rssStream); XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item"); for (int i = 0; i < rssItems.Count; i++) { var tempItem = new ArticleType(); //tempItem.imageUrl = Regex.Match(rssItems[i]["description"].InnerText, "<img.*?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase).Groups[1].Value; tempItem.imageUrl = (rssItems[i]["enclosure"] != null) ? rssItems[i]["enclosure"].Attributes["url"].Value : String.Empty; ; tempItem.heading = HttpUtility.HtmlDecode((rssItems[i]["title"].InnerText)); tempItem.content = HttpUtility.HtmlDecode(rssItems[i]["description"].InnerText); tempItem.link = rssItems[i]["link"].InnerText; //Regex regex = new Regex(@"</?\w+((\s+\w+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)+\s*|\s*)/?>", RegexOptions.Singleline); //tempItem.content = Regex.Replace(tempItem.content, regex.ToString(), String.Empty); if (!String.IsNullOrEmpty(rssItems[i]["pubDate"].InnerText)) { var pubDate = DateTime.Now.Subtract(DateTime.Parse(rssItems[i]["pubDate"].InnerText.Replace("\n", "").Trim())).ToString(); tempItem.pubDate = Helpers.PublishDateTime(pubDate); } tempItem.source = "Times LIVE"; if (Validators.ValidateArticle(tempItem)) { itemList.Add(tempItem); } } } catch (Exception) { //throw; } return itemList; }
public static List<ArticleType> TwentyFourDotcom(string category) { var itemList = new List<ArticleType>(); var url = String.Empty; switch (category) { case "health": url = "http://feeds.health24.com/articles/health24/News/rss"; break; case "tech": url = "http://feeds.news24.com/articles/News24/SciTech/rss"; break; case "business": url = "http://feeds.24.com/articles/Fin24/News/rss"; break; case "entertainment": url = "http://feeds.news24.com/articles/channel/news/rss"; break; case "sports": url = "http://24.com.feedsportal.com/c/33816/f/607928/index.rss"; break; default: url = "http://feeds.news24.com/articles/News24/TopStories/rss"; break; } try { WebRequest request = WebRequest.Create("http://mg.co.za/rss/");//WebRequest.Create(path); WebResponse response = request.GetResponse(); StringBuilder sb = new StringBuilder(""); Stream rssStream = response.GetResponseStream(); XmlDocument rssDoc = new XmlDocument(); rssDoc.Load(rssStream); XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item"); for (int i = 0; i < rssItems.Count; i++) { var tempItem = new ArticleType(); if (rssItems[i]["media:content"] != null) { var imageUrl = rssItems[i]["media:content"].Attributes[0].InnerText; tempItem.imageUrl = String.Concat("http", Regex.Split(imageUrl, "http")[2]); } tempItem.heading = HttpUtility.HtmlDecode(rssItems[i]["title"].InnerText); tempItem.content = HttpUtility.HtmlDecode(rssItems[i]["description"].InnerText); tempItem.source = (rssItems[i]["source"] != null) ? String.Concat("Source : ", HttpUtility.HtmlDecode(rssItems[i]["source"].InnerText)) : String.Empty; tempItem.link = rssItems[i]["link"].InnerText; //tempItem.pubDate = DateTime.Parse(rssItems[i]["pubdate"].InnerText); Regex regex = new Regex(@"</?\w+((\s+\w+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)+\s*|\s*)/?>", RegexOptions.Singleline); tempItem.content = Regex.Replace(tempItem.content, regex.ToString(), String.Empty); if (Validators.ValidateArticle(tempItem)) { itemList.Add(tempItem); } } } catch (Exception) { // throw; } return itemList; }
public static List<ArticleType> BBCList(string category) { var itemList = new List<ArticleType>(); var url = String.Empty; switch (category) { case "health": url = "http://feeds.bbci.co.uk/health/rss.xml"; break; case "tech": url = "http://feeds.bbci.co.uk/news/technology/rss.xml"; break; case "business": url = "http://feeds.bbci.co.uk/news/business/rss.xml"; break; case "entertainment": url = "http://feeds.bbci.co.uk/news/entertainment_and_arts/rss.xml"; break; case "sports": url = "http://feeds.bbci.co.uk/sport/rss.xml"; break; default: url = "http://feeds.bbci.co.uk/news/rss.xml"; break; } try { WebRequest request = WebRequest.Create("http://feeds.bbci.co.uk/news/rss.xml");//WebRequest.Create(path); WebResponse response = request.GetResponse(); StringBuilder sb = new StringBuilder(""); Stream rssStream = response.GetResponseStream(); XmlDocument rssDoc = new XmlDocument(); rssDoc.Load(rssStream); XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item"); for (int i = 0; i < rssItems.Count; i++) { var tempItem = new ArticleType(); if (rssItems[i]["media:thumbnail"] != null) { if (rssItems[i]["media:thumbnail"].NextSibling != null) { var urls = rssItems[i]["media:thumbnail"].NextSibling; tempItem.imageUrl = urls.Attributes["url"].InnerText; } } tempItem.link = rssItems[i]["link"].InnerText; tempItem.heading = HttpUtility.HtmlDecode((rssItems[i]["title"].InnerText)); tempItem.content = HttpUtility.HtmlDecode(rssItems[i]["description"].InnerText); if (!String.IsNullOrEmpty(rssItems[i]["pubDate"].InnerText)) { var pubDate = DateTime.Now.Subtract(DateTime.Parse(rssItems[i]["pubDate"].InnerText)).ToString(); tempItem.pubDate = Helpers.PublishDateTime(pubDate); } tempItem.source = "BBC News"; Regex regex = new Regex(@"</?\w+((\s+\w+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)+\s*|\s*)/?>", RegexOptions.Singleline); tempItem.content = Regex.Replace(tempItem.content, regex.ToString(), String.Empty); if (Validators.ValidateArticle(tempItem)) { itemList.Add(tempItem); } } } catch (Exception) { //throw; } return itemList; }