track top 10 pages, untested but it should work
All checks were successful
Deploy Backend / deploy (push) Successful in 2m27s
All checks were successful
Deploy Backend / deploy (push) Successful in 2m27s
This commit is contained in:
parent
dad8afe282
commit
29f9b305e7
@ -35,22 +35,33 @@ app.use(
|
|||||||
pattern: "1 0 * * *", // Every day at 00:01 (London time)
|
pattern: "1 0 * * *", // Every day at 00:01 (London time)
|
||||||
timezone: "Europe/London",
|
timezone: "Europe/London",
|
||||||
run: async () => {
|
run: async () => {
|
||||||
console.log("Fetching first page of players from ScoreSaber...");
|
const pages = 10;
|
||||||
const page = await scoresaberService.lookupPlayers(1);
|
let toTrack: PlayerDocument[] = await PlayerModel.find({});
|
||||||
|
const toRemoveIds: string[] = [];
|
||||||
|
|
||||||
|
// loop through pages to fetch the top players
|
||||||
|
console.log(`Fetching ${pages} pages of players from ScoreSaber...`);
|
||||||
|
for (let i = 0; i < pages; i++) {
|
||||||
|
const pageNumber = i + 1;
|
||||||
|
console.log(`Fetching page ${pageNumber}...`);
|
||||||
|
const page = await scoresaberService.lookupPlayers(pageNumber);
|
||||||
if (page === undefined) {
|
if (page === undefined) {
|
||||||
console.log("Failed to fetch players from ScoreSaber");
|
console.log(`Failed to fetch players on page ${pageNumber}, skipping page...`);
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
for (const player of page.players) {
|
for (const player of page.players) {
|
||||||
await PlayerService.getPlayer(player.id, true);
|
const foundPlayer = await PlayerService.getPlayer(player.id, true);
|
||||||
|
await PlayerService.trackScoreSaberPlayer(foundPlayer, player);
|
||||||
|
toRemoveIds.push(foundPlayer.id);
|
||||||
}
|
}
|
||||||
console.log("All players on the front page are now being tracked :)");
|
}
|
||||||
|
console.log(`Finished tracking player statistics for ${pages} pages, found ${toRemoveIds.length} players.`);
|
||||||
|
|
||||||
// ---
|
// remove all players that have been tracked
|
||||||
|
toTrack = toTrack.filter(player => !toRemoveIds.includes(player.id));
|
||||||
|
|
||||||
console.log("Tracking player statistics...");
|
console.log(`Tracking ${toTrack.length} player statistics...`);
|
||||||
const players: PlayerDocument[] = await PlayerModel.find({});
|
for (const player of toTrack) {
|
||||||
for (const player of players) {
|
|
||||||
await PlayerService.trackScoreSaberPlayer(player);
|
await PlayerService.trackScoreSaberPlayer(player);
|
||||||
}
|
}
|
||||||
console.log("Finished tracking player statistics.");
|
console.log("Finished tracking player statistics.");
|
||||||
|
@ -67,10 +67,14 @@ export class PlayerService {
|
|||||||
* Tracks a players statistics
|
* Tracks a players statistics
|
||||||
*
|
*
|
||||||
* @param foundPlayer the player to track
|
* @param foundPlayer the player to track
|
||||||
|
* @param playerToken an optional player token
|
||||||
*/
|
*/
|
||||||
public static async trackScoreSaberPlayer(foundPlayer: PlayerDocument) {
|
public static async trackScoreSaberPlayer(
|
||||||
|
foundPlayer: PlayerDocument,
|
||||||
|
playerToken?: ScoreSaberPlayerToken
|
||||||
|
): Promise<void> {
|
||||||
const dateToday = getMidnightAlignedDate(new Date());
|
const dateToday = getMidnightAlignedDate(new Date());
|
||||||
const player = await scoresaberService.lookupPlayer(foundPlayer.id);
|
const player = playerToken ? playerToken : await scoresaberService.lookupPlayer(foundPlayer.id);
|
||||||
if (player == undefined) {
|
if (player == undefined) {
|
||||||
console.log(`Player "${foundPlayer.id}" not found on ScoreSaber`);
|
console.log(`Player "${foundPlayer.id}" not found on ScoreSaber`);
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user