public static void Run() { // Get keywords. Read Frisim. Parse. Store. string[] keywords = MediaEntries.GetOldMediaKeywords(); foreach (string keyword in keywords) { // string rssUrl = String.Format("http://sesam.se/search/?c=m&q={0}&&output=rss", keyword.ToLower()); string rssUrl = String.Format("http://www.frisim.com/rss/?q={0}&k=nyheter", keyword.ToLower()); // Read the RSS URL into memory, then feed RssReader from a MemoryStream HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(rssUrl); request.UserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5"; HttpWebResponse resp = (HttpWebResponse)request.GetResponse(); RssReader reader = new RssReader(resp.GetResponseStream()); try { Rss rss = reader.Read(); foreach (RssChannelItem item in rss.Channel.Items) { // We want the title, media name, link and pubdate. string url = item.Link; DateTime dateTime = item.PubDate; string title = item.Title; string mediaName = item.Categories[0].Name; MediaEntry.CreateFromKeyword(keyword, mediaName, false, url, title, dateTime); } } catch (Exception e) { throw new ReaderException("feed:" + rssUrl + "Status=" + resp.StatusCode, e); } finally { request.GetResponse().GetResponseStream().Close(); } } }
public static void Run() { // Get keywords. Read Knuff. Parse. Store. string[] keywords = MediaEntries.GetBlogKeywords(); foreach (string keyword in keywords) { string rssUrl = "http://knuff.se/rss/q/" + keyword; // Read the RSS URL into memory, then feed RssReader from a MemoryStream HttpWebRequest request = (HttpWebRequest)WebRequest.Create(rssUrl); request.UserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9b5) Gecko/2008050509 Firefox/3.0b5"; HttpWebResponse resp = (HttpWebResponse)request.GetResponse(); RssReader reader = new RssReader(resp.GetResponseStream()); try { Rss rss = reader.Read(); foreach (RssChannelItem item in rss.Channel.Items) { // We want the title, link and pubdate. string url = item.Link; DateTime dateTime = item.PubDate; int dividerIndex = item.Title.LastIndexOf('('); if (item.Title.EndsWith("))")) { dividerIndex = item.Title.Substring(0, item.Title.Length - 7).LastIndexOf('('); } string title = item.Title.Substring(0, dividerIndex).Trim(); string blogName = item.Title.Substring(dividerIndex + 1, item.Title.Length - dividerIndex - 2); bool newEntry = MediaEntry.CreateFromKeyword(keyword, blogName, true, url, title, dateTime); if (newEntry) { try { PingCreeper(url); } catch (Exception) { // Ignore exceptions here, move on to the next entry } } } } catch (Exception e) { throw new ReaderException("feed:" + rssUrl + ", Status=" + resp.StatusCode, e); } finally { request.GetResponse().GetResponseStream().Close(); } } }