Exemplo n.º 1
0
        static void Do(string url)
        {
            var links = FeedReader.GetFeedUrlsFromUrl(url);

            foreach (var link in links)
            {
                try
                {
                    string title = link.Title;
                    if (string.IsNullOrEmpty(title))
                    {
                        title = url.Replace("https", "").Replace("http", "").Replace("www.", "");
                    }
                    title = Regex.Replace(title.ToLower(), "[^a-z]*", "");
                    var curl = FeedReader.GetAbsoluteFeedUrl(url, link);

                    string content = Helpers.Download(curl.Url);
                    System.IO.File.WriteAllText("c:\\data\\feeds\\" + title + "_" + Guid.NewGuid().ToString() + ".xml", content);
                    Console.Write("+");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(link.Title + " - " + link.Url + ": " + ex.ToString());
                }
            }
        }
Exemplo n.º 2
0
        static string GetFeedUrl(string url)
        {
            var urls = FeedReader.GetFeedUrlsFromUrl(url);

            string feedUrl = null;

            if (urls.Count() < 1) // no url - probably the url is already the right feed url
            {
                feedUrl = url;
            }
            else if (urls.Count() == 1)
            {
                feedUrl = urls.First().Url;
            }
            else if (urls.Count() == 2) // if 2 urls, then its usually a feed and a comments feed, so take the first per default
            {
                feedUrl = urls.First().Url;
            }
            else
            {
                // show all urls and let the user select (or take the first or ...)
                // ...
            }

            return(feedUrl);
        }
Exemplo n.º 3
0
        public void TestParseAndAbsoluteUrlDerStandard1()
        {
            string url   = "derstandard.at";
            var    links = FeedReader.GetFeedUrlsFromUrl(url);

            foreach (var link in links)
            {
                var absoluteUrl = FeedReader.GetAbsoluteFeedUrl(url, link);
                Assert.IsTrue(absoluteUrl.Url.StartsWith("http://"));
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter feed url:");
            string url = Console.ReadLine();

            var urls = FeedReader.GetFeedUrlsFromUrl(url);

            string feedUrl;

            if (urls.Count() < 1)
            {
                feedUrl = url;
            }
            else if (urls.Count() == 1)
            {
                feedUrl = urls.First().Url;
            }
            else if (urls.Count() == 2) // if 2 urls, then its usually a feed and a comments feed, so take the first per default
            {
                feedUrl = urls.First().Url;
            }
            else
            {
                int i = 1;
                Console.WriteLine("Found multiple feed, please choose:");
                foreach (var feedurl in urls)
                {
                    Console.WriteLine($"{i++.ToString()} - {feedurl.Title} - {feedurl.Url}");
                }
                var input = Console.ReadLine();
                int index;
                if (!int.TryParse(input, out index) || index < 1 || index > urls.Count())
                {
                    Console.WriteLine("Wrong input. Press key to exit");
                    Console.ReadKey();
                    return;
                }
                feedUrl = urls.ElementAt(index).Url;
            }

            var reader = FeedReader.Read(feedUrl);

            foreach (var item in reader.Items)
            {
                Console.WriteLine(item.Title + " - " + item.Link);
            }

            Console.ReadKey();
        }