示例#1
0
    public async Task SaveTweetsAsync(List <ThirdNews> list)
    {
        var result = new List <ThirdNews>(list);
        var news   = await _context.ThirdNews.OrderByDescending(n => n.DatePublished)
                     .Where(n => n.Type == NewsSource.Tweet)
                     .Take(50).ToListAsync();

        foreach (var item in list)
        {
            if (news.Any(n => n.IdentityId == item.IdentityId ||
                         n.Title.GetSimilar(item.Title) >= 0.6))
            {
                result.Remove(item);
            }
        }

        if (result.Count > 0)
        {
            await _context.AddRangeAsync(result);

            await _context.SaveChangesAsync();

            _logger.LogInformation("===Start=== Add tweets " + result.Count);
        }
    }
    public async Task AddThirdNewsAsync(List <ThirdNews> list)
    {
        var result = new List <ThirdNews>(list);
        var news   = await _context.ThirdNews.OrderByDescending(n => n.DatePublished)
                     .Where(n => n.Type == NewsSource.News)
                     .Take(50).ToListAsync();

        _logger.LogInformation("today total news: " + list.Count);

        foreach (var item in list)
        {
            if (news.Any(n => n.Title.GetSimilar(item.Title) >= 0.6 || n.Title.Equals(item.Title)))
            {
                result.Remove(item);
            }
        }
        _logger.LogInformation("added news: " + result.Count);

        if (result.Count > 0)
        {
            await _context.AddRangeAsync(result);

            await _context.SaveChangesAsync();
        }
    }