コード例 #1
0
ファイル: ArgoticFeedReader.cs プロジェクト: dbusha/Firehose
        public async Task <IEnumerable <FeedItem> > UpdateFeedAsync(Feed feed)
        {
            var list = new List <FeedItem>();

            switch (feed.FeedType)
            {
            case FeedType.Rss:
                var rss = RssFeed.Create(new Uri(feed.Address));
                foreach (var item in rss.Channel.Items)
                {
                    list.Add(new FeedItem(item));
                }
                break;

            case FeedType.Atom:
                var atom = AtomFeed.Create(new Uri(feed.Address));
                foreach (var entry in atom.Entries)
                {
                    list.Add(new FeedItem(entry));
                }
                break;

            default:
                var unknown = GenericSyndicationFeed.Create(new Uri(feed.Address));
                foreach (var item in unknown.Items)
                {
                    list.Add(new FeedItem(item));
                }
                break;
            }

            return(list);
        }
コード例 #2
0
    private static void caryVideoChecker(object source, ElapsedEventArgs e)
    {
        SyndicationResourceLoadSettings settings = new SyndicationResourceLoadSettings();

        settings.RetrievalLimit = 1;

        Uri      feedUrl = new Uri("https://www.youtube.com/feeds/videos.xml?user=carykh");
        AtomFeed feed    = AtomFeed.Create(feedUrl, settings);
        var      videos  = feed.Entries;

        bool alreadyPosted = false;

        if (videos.Count() == 0)
        {
            Console.WriteLine("[Error] Feed contained no information.");
        }

        foreach (var video in videos)
        {
            try
            {
                string        videoUrlsFile = Directory.GetCurrentDirectory() + "/videoUrls.txt";          // String for the video URLS to check if a post is new, uses "videoUrls.txt" in directory the .exe is run from by default
                var           logFile       = File.ReadAllLines(videoUrlsFile);
                List <string> videoUrls     = new List <string>(logFile);

                string newVideoUrl = video.Links.FirstOrDefault().Uri.ToString();
                string videoTitle  = video.Title.Content;

                foreach (var videoUrl in videoUrls)
                {
                    if (newVideoUrl == videoUrl)
                    {
                        alreadyPosted = true;
                    }
                }

                try
                {
                    if (alreadyPosted == false)
                    {
                        Console.WriteLine($"Found new video URL - {newVideoUrl} (\"{videoTitle}\") - Sending to discord");

                        using (StreamWriter text = File.AppendText(videoUrlsFile))
                            text.WriteLine(newVideoUrl);

                        _client.GetServer(184755239952318464).GetChannel(185111014671515649).SendMessage("@everyone `carykh` has uploaded a new YouTube video!\n" +
                                                                                                         $"\"{videoTitle}\" - {newVideoUrl}");
                    }
                }
                catch (Exception error)
                {
                    Console.WriteLine($"[Error] Bot ran into an issue while trying to post the video to discord. {error.ToString()}");
                }
            }
            catch (Exception error)
            {
                Console.WriteLine("[Error] An error occured during the video check -" + error.ToString());
            }
        }
    }
コード例 #3
0
        /// <summary>
        /// Provides example code for the AtomFeed.Create(Uri) method
        /// </summary>
        public static void CreateExample()
        {
            AtomFeed feed = AtomFeed.Create(new Uri("http://news.google.com/?output=atom"));

            foreach (AtomEntry entry in feed.Entries)
            {
                if (entry.PublishedOn >= DateTime.Today)
                {
                    //  Perform some processing on the feed entry
                }
            }
        }
コード例 #4
0
ファイル: Phabricator.cs プロジェクト: duaneking/Tychaia
        public AtomFeed GetFeed(string id)
        {
            var feed = this.BlogCache.Get("feed-" + id) as AtomFeed;

            if (feed == null)
            {
                feed = AtomFeed.Create(new Uri("http://code.redpointsoftware.com.au/phame/blog/feed/" + id + "/"));
                this.BlogCache.Add(
                    new CacheItem("feed-" + id, feed),
                    new CacheItemPolicy {
                    AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(15)
                }
                    );
            }
            return(feed);
        }
コード例 #5
0
ファイル: ArgoticFeedReader.cs プロジェクト: dbusha/Firehose
        public Feed GetFeed(Feed feed)
        {
            switch (feed.FeedType)
            {
            case FeedType.Rss:
                var rss = RssFeed.Create(new Uri(feed.Address));
                return(new Feed(rss));

            case FeedType.Atom:
                var atom = AtomFeed.Create(new Uri(feed.Address));
                return(new Feed(atom));

            default:
                var unknown = GenericSyndicationFeed.Create(new Uri(feed.Address));
                return(new Feed(unknown));
            }
        }