private static async Task Sync(Logger logger, AlertsDatabase db) { await db.Database.EnsureCreatedAsync(); var foundPages = await OtoDomCrawler.Search(SpecificOtoDomSearchUrl); var knownPages = await db.Pages.ToListAsync(); var newPages = foundPages.Except(knownPages).ToList(); db.Pages.AddRange(newPages); await db.SaveChangesAsync(); foreach (var page in newPages) { logger.Information($"[{page.Title}]({page.Link})"); } }
public static async Task Main(string[] args) { var config = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build() .Get <Config>(); using (var logger = new LoggerConfiguration() .WriteTo.Telegram(config.TelegramApiKey, config.TelegramChatId) .CreateLogger()) try { using (var db = new AlertsDatabase()) await Sync(logger, db); } catch (Exception ex) { logger.Error(ex, "Oops :("); } }