Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser.js {id}elo #33

Open
ekisler opened this issue Jan 1, 2025 · 1 comment
Open

parser.js {id}elo #33

ekisler opened this issue Jan 1, 2025 · 1 comment

Comments

@ekisler
Copy link

ekisler commented Jan 1, 2025

Hice una pequeña adaptación de código porque no estaba funcionando el /id/elo, espero que la revises que se se puede mejorar mucho, sin embargo asi funciona:


const parseEloFromProfilePage = (data) => {
const $ = cheerio.load(data);
const table_entries = $("table.profile-table.profile-table_chart-table tbody");

if (table_entries.length === 0) {
    throw "Not found";
}

const elo = [];
table_entries.map((i) => {
    const row = cheerio.load(table_entries[i])("td");
    elo.push({
        date: row[0].children[0].data.replace(/\s/g, ""),
        standard: row[1].children[0].data.replace(/\s/g, ""),
        rapid: row[3].children[0].data.replace(/\s/g, ""),
        blitz: row[5].children[0].data.replace(/\s/g, ""),
    });
});

return elo;

};


@ekisler
Copy link
Author

ekisler commented Jan 1, 2025

otra solución propuesta, mas parecido a lo que ya esta creado seria:
/**

  • Parse player ELO from FIDE player page
  • @param {Object} data
  • @throws {String}
  • @returns {JSON} Player ELO
    */

const parseEloFromProfilePage = (data) => {
const $ = cheerio.load(data);

if ($(".profile-top-ratingCont").length === 0) {
    throw "Not found";
}

const standard_elo = $(".profile-top-rating-data_gray")
    .text()
    .trim()
    .replace(/\s+/g, " ")
    .replace(/\n/g, " ")
    .replace(/^inactive\s+/i, "inactive ");
const rapid_elo = $(".profile-top-rating-data_red")
    .text()
    .trim()
    .replace(/\s+/g, " ")
    .replace(/\n/g, " ")
    .replace(/^inactive\s+/i, "inactive ");
const blitz_elo = $(".profile-top-rating-data_blue ")
    .text()
    .trim()
    .replace(/\s+/g, " ")
    .replace(/\n/g, " ")
    .replace(/^inactive\s+/i, "inactive ");

return {
    standard_elo,
    rapid_elo,
    blitz_elo,
};

};

Ambas soluciones siempre pueden mejorarse y refactoizar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant