Skip to content

Commit

Permalink
revert live table, reduce logging
Browse files Browse the repository at this point in the history
  • Loading branch information
lineville committed Nov 16, 2023
1 parent 30f6076 commit 4a86252
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
9 changes: 7 additions & 2 deletions USTACLI/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ public static ChromeDriver Create()
"--disable-gpu",
"--disable-logging",
"--disable-dev-shm-usage",
"--disable-crash-reporter",
"--window-size=1920,1080",
"--disable-extensions",
"--log-level=OFF",
"--log-level=3",
"--user-agent=Chrome/73.0.3683.86",
"--output=/dev/null"
);

return new ChromeDriver(options);
ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.SuppressInitialDiagnosticInformation = true;
service.HideCommandPromptWindow = true;
service.EnableVerboseLogging = false;
return new ChromeDriver(service, options);
}
}
63 changes: 31 additions & 32 deletions USTACLI/cli/ListRankingsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public override int Execute(CommandContext context, RankingsSettings settings)

Utilities.InteractiveFallback(settings, configuration, context.Name);

List<Player> players = new List<Player>();

var table = new Table
{
Expand All @@ -34,41 +33,41 @@ public override int Execute(CommandContext context, RankingsSettings settings)
new TableColumn(new Text("Location", new Style(Color.Purple, Color.Black)).LeftJustified())
});

List<Player> players = new List<Player>();

AnsiConsole
.Live(table)
.Cropping(VerticalOverflowCropping.Bottom)
.Overflow(VerticalOverflow.Ellipsis)
.Start(ctx =>
.Status()
.Spinner(new TennisBallSpinner())
.Start("Searching for rankings", _ctx =>
{
var pageNumber = 1;
var keepFetching = true;
// Keep fetching as long as there are more players to fetch and we haven't exceeded settings.Top many players
while (keepFetching)
{
var pageNumber = 1;
var keepFetching = true;

// Keep fetching as long as there are more players to fetch and we haven't exceeded settings.Top many players
while (keepFetching)
// Create the chrome driver service
using (var driver = Driver.Create())
{
// Create the chrome driver service
using (var driver = Driver.Create())
// Scrape a page of players, add them to the list, update the live table and increment the page number
var pageOfPlayers = ScrapeRankings(driver, configuration, settings, context.Name, pageNumber).Take(Math.Min(20, settings.Top - players.Count()));
players.AddRange(pageOfPlayers);
pageNumber++;
if (pageOfPlayers.Count() < 20 || players.Count() >= settings.Top)
{
// Scrape a page of players, add them to the list, update the live table and increment the page number
var pageOfPlayers = ScrapeRankings(driver, configuration, settings, context.Name, pageNumber).Take(Math.Min(20, settings.Top));
players.AddRange(pageOfPlayers);
pageNumber++;

foreach (var player in pageOfPlayers)
{
table.AddRow(new string[] { player.Name.ToString(), player.DistrictRank.ToString(), player.SectionRank.ToString(), player.NationalRank.ToString(), player.TotalPoints.ToString(), player.Location.ToString() });
}

ctx.Refresh();

if (pageOfPlayers.Count() < 20 || players.Count() >= settings.Top)
{
keepFetching = false;
}
} // Driver gets disposed here

}
});
keepFetching = false;
}
} // Driver gets disposed here
}
foreach (var player in players)
{
table.AddRow(new string[] { player.Name.ToString(), player.DistrictRank.ToString(), player.SectionRank.ToString(), player.NationalRank.ToString(), player.TotalPoints.ToString(), player.Location.ToString() });
}
});

// Write to Console
AnsiConsole.Clear();
AnsiConsole.Write(table);
AnsiConsole.WriteLine();

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion USTACLI/usta-cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ToolCommandName>usta-cli</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageVersion>2.0.7</PackageVersion>
<PackageVersion>2.0.8</PackageVersion>
<RepositoryUrl>https://github.com/lineville/usta-cli</RepositoryUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>
Expand Down

0 comments on commit 4a86252

Please sign in to comment.