Skip to content

Commit

Permalink
refactor: process only a quarter of the pokemon for flavor updates ev…
Browse files Browse the repository at this point in the history
…ery day

[skip publish]
  • Loading branch information
favna committed Apr 1, 2024
1 parent 6f19b64 commit ade6b0b
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { green } from 'colorette';
import { writeFile } from 'node:fs/promises';
import { format } from 'prettier';
import prettierConfig from '../../../../.prettierrc.mjs';
import { ensureLogfileExists, getBulbapediaReadyPokemon } from '../utils/bulbapedia-utils.js';
// import { createFlaresolverrSession, destroyFlaresolverrSession } from '../utils/flaresolverr-session-management.js';
import { rootDir } from '../../../utils.js';
import { ensureLogfileExists, getBulbapediaReadyPokemon } from '../utils/bulbapedia-utils.js';
import { logFile } from './constants.js';
import { gameSorter } from './game-sorter.js';
import { log } from './log-wrapper.js';
Expand All @@ -16,10 +15,27 @@ const failedPokemonTextFile = new URL('./failed-pokemon.json', import.meta.url);

await ensureLogfileExists(logFile);

for (const pokemon of getBulbapediaReadyPokemon()) {
// await createFlaresolverrSession();
const pokemonToParse = getBulbapediaReadyPokemon();

// Get the current day of the month
const dayOfMonth = new Date().getDate();

// Use modulo to get a number between 0 and 3
const quarterToProcess = dayOfMonth % 4;

// Calculate the size of each quarter
const quarterSize = Math.ceil(pokemonToParse.length / 4);

// Split the array into quarters
const quarters = Array(4)
.fill(0)
.map((_, i) => pokemonToParse.slice(i * quarterSize, (i + 1) * quarterSize));

// Select the quarter to process
const pokemonToProcess = quarters[quarterToProcess];

for (const pokemon of pokemonToProcess) {
await parsePokemon(pokemon);
// await destroyFlaresolverrSession();
}

await log({ msg: "Done fetching and storing data in memory, sorting version_id's", color: green, isBold: true, isIndent: false });
Expand Down

0 comments on commit ade6b0b

Please sign in to comment.