private static void Report() { if (String.IsNullOrEmpty(_adminEmail) || DateTime.UtcNow.Hour < _reportingHour || DateTime.UtcNow.Day == _lastReportDate?.Day) { return; } var userManager = new UserManager(); var userProfiles = userManager.GetUserProfiles(); var emailBody = new StringBuilder(); emailBody.AppendLine("Username\tNew Items"); emailBody.AppendLine(); foreach (var userProfile in userProfiles) { var count = userManager.GetNewItemCount(userProfile.Username, out string userNewItemCountFile); emailBody.AppendLine($"{userProfile.Username}\t{count}"); File.Delete(userNewItemCountFile); } var mailMan = new MailMan(_mailManUsername, _mailMainPassword); mailMan.SendMail(_adminEmail, emailBody.ToString(), $"Stats: {DateTime.Now:dd-mm-yyyy}"); Console.WriteLine("Report sent."); }
private static void Monitor() { var userManager = new UserManager(); var userProfiles = userManager.GetUserProfiles(); foreach (var userProfile in userProfiles) { var newItems = new List <ApartmentListing>(); foreach (var url in userProfile.ListingUrls) { var plugin = PluginHelper.GetPlugin(url); if (plugin == null) { Console.WriteLine($"Could not find plugin for '{url}'."); continue; } Console.WriteLine("Searching for new listings..."); var listing = plugin.GetApartmentListing(url); foreach (var l in listing) { if (userProfile.History.Contains(l.Link)) { continue; } userManager.AddToHistory(userProfile.Username, url); newItems.Add(l); } } if (!newItems.Any()) { Console.WriteLine("No new items found."); continue; } Console.WriteLine($"Sending {newItems.Count} new listings."); var mailMan = new MailMan(_mailManUsername, _mailMainPassword); foreach (var listing in newItems) { mailMan.SendMail(userProfile.Email, listing.Link, $"{listing.Title} {listing.Price}"); userManager.AddToHistory(userProfile.Username, listing.Link); } } Console.WriteLine("Monitor done."); }