static async Task SeasonalImport(string path, int year) { using var seasonalRetriever = new MaddenImporter.Core.SeasonalRetriever(); var workbook = new ClosedXML.Excel.XLWorkbook(); var players = (await seasonalRetriever.GetAllPlayers(year)).ToList(); ExcelExtensions.WritePlayerSheet <PassingPlayer>(workbook, Extensions.GetPlayersOfType <PassingPlayer>(players)); ExcelExtensions.WritePlayerSheet <RushingPlayer>(workbook, Extensions.GetPlayersOfType <RushingPlayer>(players)); ExcelExtensions.WritePlayerSheet <DefensePlayer>(workbook, Extensions.GetPlayersOfType <DefensePlayer>(players)); ExcelExtensions.WritePlayerSheet <ReturningPlayer>(workbook, Extensions.GetPlayersOfType <ReturningPlayer>(players)); ExcelExtensions.WritePlayerSheet <KickingPlayer>(workbook, Extensions.GetPlayersOfType <KickingPlayer>(players)); ExcelExtensions.WritePlayerSheet <ReceivingPlayer>(workbook, Extensions.GetPlayersOfType <ReceivingPlayer>(players)); workbook.SaveAs(path + "/players.xlsx"); workbook.Dispose(); }
static void CareerImport(string path, string username, string password, int startYear, int endYear) { if (!System.IO.File.Exists("./geckodriver") && !System.IO.File.Exists("./geckodriver.exe")) { Console.WriteLine("\nGecko driver not found. Please download it from https://github.com/mozilla/geckodriver/releases and put it in this folder."); Console.WriteLine("If you are a GNU/Linux user, you may need to run chmod +x geckodriver"); return; } if (System.IO.File.Exists("login.private")) { var data = System.IO.File.ReadAllLines("login.private"); if (data.Length < 2) { ThrowFatalError("Login file exists, but username and password were not found."); } username ??= data[0].Trim(); password ??= data[1].Trim(); } if (startYear > 0 && (startYear < 1950 || startYear > DateTime.Now.Year)) { ThrowFatalError("Start year is too early."); } if (endYear < 1950 || endYear > DateTime.Now.Year) { ThrowFatalError("End year is invalid."); } if (startYear == 0) { startYear = endYear - 25; } Console.WriteLine($"Using start year {startYear} and end year {endYear}."); try { using var careerRetriever = new CareerRetriever("./"); var players = careerRetriever.GetAllPlayers(username, password, startYear, endYear).ToList(); var workbook = new ClosedXML.Excel.XLWorkbook(); ExcelExtensions.WritePlayerSheet <PassingPlayer>(workbook, Extensions.GetPlayersOfType <PassingPlayer>(players)); ExcelExtensions.WritePlayerSheet <RushingPlayer>(workbook, Extensions.GetPlayersOfType <RushingPlayer>(players)); ExcelExtensions.WritePlayerSheet <DefensePlayer>(workbook, Extensions.GetPlayersOfType <DefensePlayer>(players)); ExcelExtensions.WritePlayerSheet <ReturningPlayer>(workbook, Extensions.GetPlayersOfType <ReturningPlayer>(players)); ExcelExtensions.WritePlayerSheet <KickingPlayer>(workbook, Extensions.GetPlayersOfType <KickingPlayer>(players)); ExcelExtensions.WritePlayerSheet <ReceivingPlayer>(workbook, Extensions.GetPlayersOfType <ReceivingPlayer>(players)); path += "/players-career.xlsx"; workbook.SaveAs(path); Console.WriteLine($"Saved workbook to {path}"); workbook.Dispose(); } catch (ArgumentNullException) { ThrowFatalError("You must provide a username and password, either through the command-line options, or in a login.private file in the same directory as the executable.", "Use the --help parameter if needed."); } catch (ApplicationException) { ThrowFatalError("Login failed. Check your username and password.", "Make sure you can log in with your own browser first."); } }