Пример #1
0
        public async Task Execute(IJobExecutionContext context)
        {
            var targetArticles = await _pttService.CrawlTargetArticleLinks("Stock", "標的", 1);

            var pttArticlesInDatabase = await _pttArticleRepo.GetAllArticlesTitle("Stock");

            var latestArticles = targetArticles.Where(article =>
                                                      pttArticlesInDatabase.All(x => x.Title != article.Title));

            var tasks = Enumerable.Empty <Task>().ToList();

            foreach (var article in latestArticles)
            {
                tasks.Add(_telegramService.SendMessage(article.ToPttLink()));
                tasks.Add(_pttArticleRepo.Insert(article));
            }

            Task.WaitAll(tasks.ToArray());
        }
Пример #2
0
        public async Task <OkResult> CrawlPtt(string board, string titleElement, int pageAmount)
        {
            var targetArticles = await _pttService.CrawlTargetArticleLinks(board, titleElement, pageAmount);

            var pttArticlesInDatabase = await _pttArticleRepo.GetAllArticlesTitle(board);

            var latestArticles = targetArticles.Where(article =>
                                                      pttArticlesInDatabase.All(x => x.Title != article.Title));

            var tasks = Enumerable.Empty <Task>().ToList();

            foreach (var article in latestArticles)
            {
                tasks.Add(_telegramService.SendMessage(article.ToPttLink()));
                tasks.Add(_pttArticleRepo.Insert(article));
            }

            await Task.WhenAll(tasks);

            return(Ok());
        }