Example #1
0
        public async Task RunAsync()
        {
            var searchClient = new YouTubeSearchClient(youtubeApiKey);
            var result       = await searchClient.SearchAsync(SearchWord);

            var tableClient = new YouTubeTableClient(storageAccount, tableName);

            var savedLatestItem   = tableClient.GetLatestItem();
            var latestPublishedAt = savedLatestItem?.PublishedAt ?? DateTime.UtcNow.AddHours(-6);

            var newItems = result
                           .Where(x => x.Snippet.PublishedAt.Value.ToUniversalTime() > latestPublishedAt)
                           .ToList();

            foreach (var item in newItems)
            {
                var tableEntity = item.ToEntity();
                try
                {
                    await tableClient.InsertAsync(tableEntity);
                    await Notify2DiscordAsync(tableEntity);
                }
                catch (Exception e)
                {
                    // TODO: log
                    Debug.WriteLine($"{e.Message} {e.StackTrace}");
                }
            }
        }
Example #2
0
        public void GetLatestItemTest()
        {
            var tableName      = ConfigurationManager.AppSettings["TableName"];
            var storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
            var tableClient    = new YouTubeTableClient(storageAccount, tableName);

            tableClient.GetLatestItem();
        }