public MoverCardDataModel GetSrapedMoversShakersData(MTGFormatsEnum format) { try { Console.WriteLine(AddDateTimeConsoleWrite.AddDateTime($"[Scraping {format.ToString()}]: Waiting 5 seconds before we begin...")); Thread.Sleep(5000); var scrapedData = new MoverCardDataModel(); Driver.Navigate().GoToUrl($"https://www.mtggoldfish.com/movers/paper/{format}"); var pageUpdatedTime = Driver.FindElement(MoversShakersMappings.PageLastUpdatedXpath).GetAttribute("title").Replace("UTC", ""); DateTime.TryParse(pageUpdatedTime, out DateTime parsedPageUpdatedTime); scrapedData.PageLastUpdated = parsedPageUpdatedTime; scrapedData.Format = format.ToString(); scrapedData.DailyIncreaseList = GetMoversAndShakersData(format, true, true, true); scrapedData.DailyDecreaseList = GetMoversAndShakersData(format, false, true, true); scrapedData.WeeklyIncreaseList = GetMoversAndShakersData(format, true, true, false); scrapedData.WeeklyDecreaseList = GetMoversAndShakersData(format, false, true, false); Console.WriteLine(AddDateTimeConsoleWrite.AddDateTime($"### Successfully scraped {format}. Quitting Driver.. ###")); Driver.Quit(); return(scrapedData); } catch (Exception e) { Driver.Quit(); Console.WriteLine(e); throw; } }
private List <MoverCardDataModel.CardInfo> GetMoversAndShakersData(MTGFormatsEnum format, bool isWinner, bool isPaper, bool isDaily) { var platform = isPaper ? "paper" : "online"; var winnerOrLoser = isWinner ? "winners" : "losers"; var daily = isDaily ? "dod" : "wow"; Driver.Navigate().GoToUrl($"https://www.mtggoldfish.com/movers-details/{platform}/{format}/{winnerOrLoser}/{daily}"); var rows = Driver.FindElement(MoversShakersMappings.TblMovers).FindElements(By.XPath("//tr")); var cardData = new List <MoverCardDataModel.CardInfo>(); foreach (var row in rows) { var rowData = row.FindElements(By.XPath("./*")); if (rowData.Count != 5) { if (rowData.Count == 1) { Console.WriteLine($"Skipping single cell row. Text: {rowData[0].Text}"); } continue; } cardData.Add(new MoverCardDataModel.CardInfo { PriceChange = rowData[0].Text, Name = rowData[2].Text, TotalPrice = rowData[3].Text, ChangePercentage = rowData[4].Text }); } return(cardData); }
private DateTime GetLastDeliveredTime(MTGFormatsEnum format, ulong guildId) { switch (format) { case MTGFormatsEnum.standard: return(MoversShakersJSONController.ReadMoversShakersConfig(guildId).LastDeliveredTime_Standard); case MTGFormatsEnum.modern: return(MoversShakersJSONController.ReadMoversShakersConfig(guildId).LastDeliveredTime_Modern); case MTGFormatsEnum.pioneer: return(MoversShakersJSONController.ReadMoversShakersConfig(guildId).LastDeliveredTime_Pioneer); case MTGFormatsEnum.pauper: return(MoversShakersJSONController.ReadMoversShakersConfig(guildId).LastDeliveredTime_Pauper); case MTGFormatsEnum.legacy: return(MoversShakersJSONController.ReadMoversShakersConfig(guildId).LastDeliveredTime_Legacy); case MTGFormatsEnum.vintage: return(MoversShakersJSONController.ReadMoversShakersConfig(guildId).LastDeliveredTime_Vintage); default: return(DateTime.MinValue); } }
private DateTime GetCurrentScrapeTime(MTGFormatsEnum format) { switch (format) { case MTGFormatsEnum.standard: return(ScrapeTimes.StandardScrapeTime); case MTGFormatsEnum.modern: return(ScrapeTimes.ModernScrapeTime); case MTGFormatsEnum.pioneer: return(ScrapeTimes.PioneerScrapeTime); case MTGFormatsEnum.pauper: return(ScrapeTimes.PauperScrapeTime); case MTGFormatsEnum.legacy: return(ScrapeTimes.LegacyScrapeTime); case MTGFormatsEnum.vintage: return(ScrapeTimes.VintageScrapeTime); default: return(DateTime.MinValue); } }
private void UpdateScrapeTime(MTGFormatsEnum format) { var fileLocation = ConfigurationManager.AppSettings.Get("MoversAndShakersScrapedDataLocation"); VTFileSystemManagement.FileSystemManager fileSystem = new VTFileSystemManagement.FileSystemManager(); switch (format) { case MTGFormatsEnum.standard: ScrapeTimes.StandardScrapeTime = fileSystem.GetFilesLastModifiedTime(fileLocation, $"{format.ToString()}.json"); break; case MTGFormatsEnum.modern: ScrapeTimes.ModernScrapeTime = fileSystem.GetFilesLastModifiedTime(fileLocation, $"{format.ToString()}.json"); break; case MTGFormatsEnum.pioneer: ScrapeTimes.PioneerScrapeTime = fileSystem.GetFilesLastModifiedTime(fileLocation, $"{format.ToString()}.json"); break; case MTGFormatsEnum.pauper: ScrapeTimes.PauperScrapeTime = fileSystem.GetFilesLastModifiedTime(fileLocation, $"{format.ToString()}.json"); break; case MTGFormatsEnum.legacy: ScrapeTimes.LegacyScrapeTime = fileSystem.GetFilesLastModifiedTime(fileLocation, $"{format.ToString()}.json"); break; case MTGFormatsEnum.vintage: ScrapeTimes.VintageScrapeTime = fileSystem.GetFilesLastModifiedTime(fileLocation, $"{format.ToString()}.json"); break; default: break; } }
/// <summary> /// Takes in two objects and will run them through an IEqualityComparer to determine if they're equal. If they're not, we create a new JSON document. /// </summary> /// <param name="format"></param> private void DetermineNewData(MoverCardDataModel newScrapedData, MoverCardDataModel oldScrapedData, MTGFormatsEnum format) { newScrapedData.Format = format.ToString(); if (newScrapedData.DailyIncreaseList.Count != 0 && oldScrapedData.DailyIncreaseList.Count != 0) { for (var i = 0; i < newScrapedData.DailyIncreaseList.Count; i++) { if (!new MoverCardDataEqualityComparer().Equals(newScrapedData.DailyIncreaseList[i], oldScrapedData.DailyIncreaseList[i])) { Console.WriteLine($"New: {newScrapedData.Format} and Old: {oldScrapedData.Format} Differ. Writing to disk..."); MoversShakersJsonController.WriteMoverShakersJsonByFileName(newScrapedData, $"{format.ToString()}.json"); _completedFormats.Add($"{newScrapedData.Format}"); break; } } } else if (newScrapedData.DailyIncreaseList.Count > 0 && oldScrapedData.DailyIncreaseList.Count == 0) { for (int i = 0; i < newScrapedData.DailyIncreaseList.Count; i++) { Console.WriteLine(AddDateTimeConsoleWrite.AddDateTime($"{nameof(oldScrapedData)}.{nameof(oldScrapedData.DailyIncreaseList)} was empty. Created {format.ToString()}.json")); MoversShakersJsonController.WriteMoverShakersJsonByFileName(newScrapedData, $"{format.ToString()}.json"); _completedFormats.Add($"{newScrapedData.Format}"); break; } } }
private Models.DiscordServerChannelModel UpdateLastDeliveredTime(Models.DiscordServerChannelModel discordInformation, MTGFormatsEnum format, DateTime timeToUpdate) { switch (format) { case MTGFormatsEnum.standard: discordInformation.LastDeliveredTime_Standard = timeToUpdate; break; case MTGFormatsEnum.modern: discordInformation.LastDeliveredTime_Modern = timeToUpdate; break; case MTGFormatsEnum.pioneer: discordInformation.LastDeliveredTime_Pioneer = timeToUpdate; break; case MTGFormatsEnum.pauper: discordInformation.LastDeliveredTime_Pauper = timeToUpdate; break; case MTGFormatsEnum.legacy: discordInformation.LastDeliveredTime_Legacy = timeToUpdate; break; case MTGFormatsEnum.vintage: discordInformation.LastDeliveredTime_Vintage = timeToUpdate; break; default: break; } return(discordInformation); }