Skip to content

Commit

Permalink
Add script to check for discrepancies between Yugipedia and the offic…
Browse files Browse the repository at this point in the history
…ial database
  • Loading branch information
kevinlul committed Sep 2, 2024
1 parent c63b33f commit 6d392eb
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 6 deletions.
40 changes: 34 additions & 6 deletions .github/workflows/merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jobs:
with:
repository: DawnbrandBots/yaml-yugi-zh
path: yaml-yugi-zh
- uses: actions/checkout@v4
with:
repository: db-ygoresources-com/yugioh-card-history
path: yugioh-card-history
- uses: actions/setup-python@v5
with:
python-version: "3.12"
Expand Down Expand Up @@ -98,12 +102,7 @@ jobs:
run: |
sed -s '1i---' data/cards/*.yaml > ../aggregate/cards.yaml
sed -s '1i---' data/rush/*.yaml > ../aggregate/rush.yaml
- if: steps.commit.outputs.status > 0
run: cp aggregate/* yaml-yugi/src/web
- if: steps.commit.outputs.status > 0
uses: actions/upload-pages-artifact@v3
with:
path: yaml-yugi/src/web
- if: steps.commit.outputs.status > 0
uses: actions/setup-node@v4
with:
Expand All @@ -113,6 +112,35 @@ jobs:
- if: steps.commit.outputs.status > 0
working-directory: yaml-yugi
run: yarn

- if: steps.commit.outputs.status > 0
working-directory: yaml-yugi
run: yarn --silent check-for-ygoresources-discrepancies ../yugioh-card-history ja > ../aggregate/discrepancy.ja.json || true
- if: steps.commit.outputs.status > 0
working-directory: yaml-yugi
run: yarn --silent check-for-ygoresources-discrepancies ../yugioh-card-history en > ../aggregate/discrepancy.en.json || true
- if: steps.commit.outputs.status > 0
working-directory: yaml-yugi
run: yarn --silent check-for-ygoresources-discrepancies ../yugioh-card-history de > ../aggregate/discrepancy.de.json || true
- if: steps.commit.outputs.status > 0
working-directory: yaml-yugi
run: yarn --silent check-for-ygoresources-discrepancies ../yugioh-card-history es > ../aggregate/discrepancy.es.json || true
- if: steps.commit.outputs.status > 0
working-directory: yaml-yugi
run: yarn --silent check-for-ygoresources-discrepancies ../yugioh-card-history fr > ../aggregate/discrepancy.fr.json || true
- if: steps.commit.outputs.status > 0
working-directory: yaml-yugi
run: yarn --silent check-for-ygoresources-discrepancies ../yugioh-card-history it > ../aggregate/discrepancy.it.json || true
- if: steps.commit.outputs.status > 0
working-directory: yaml-yugi
run: yarn --silent check-for-ygoresources-discrepancies ../yugioh-card-history pt > ../aggregate/discrepancy.pt.json || true

- if: steps.commit.outputs.status > 0
run: cp aggregate/* yaml-yugi/src/web
- if: steps.commit.outputs.status > 0
uses: actions/upload-pages-artifact@v3
with:
path: yaml-yugi/src/web
- if: steps.commit.outputs.status > 0
working-directory: yaml-yugi
name: Load (push)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"load": "ts-node src/load.ts",
"check-for-missing-fake-password": "ts-node src/assignments/check-for-missing.ts",
"check-for-missing-names": "ts-node src/check-for-missing-names.ts",
"check-for-ygoresources-discrepancies": "ts-node src/check-for-ygoresources-discrepancies.ts data/cards",
"format:check": "yarn prettier --check 'src/**/*.{js,ts}'",
"lint": "eslint 'src/**/*.ts'"
},
Expand Down
94 changes: 94 additions & 0 deletions src/check-for-ygoresources-discrepancies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// SPDX-FileCopyrightText: © 2024 Kevin Lu
// SPDX-Licence-Identifier: AGPL-3.0-or-later
import fs from "fs";
import path from "path";
import { parseDocument } from "htmlparser2";

if (process.argv.length < 5) {
console.error(`Usage: ${process.argv[1]} <data/cards> <db-ygoresources-com/yugioh-card-history> <lang>`);
process.exit(1);
}

function stripRuby(html: string): string {
if (!html.includes("<ruby>")) {
return html;
}
let rubyless = "";
const doc = parseDocument(html);
for (const element of doc.children) {
if (element.type === "text") {
rubyless += element.data;
} else if (element.type === "tag" && element.name === "ruby" && element.children[0].type === "text") {
rubyless += element.children[0].data;
}
}
return rubyless;
}

interface SideBySide {
// null is only possible for no Pendulum Effect
wk: string | null;
db: string | null;
}

interface Discrepancy {
yugipedia_page_id: number;
konami_id: number;
password: number;
name_en: string;
name?: SideBySide;
text?: SideBySide;
pendulum?: SideBySide;
}

(async () => {
const files = await fs.promises.readdir(process.argv[2]);
const lang = process.argv[4];
const discrepancies = [];
for (const file of files) {
if (file.endsWith(".json")) {
const card = JSON.parse(await fs.promises.readFile(path.join(process.argv[2], file), "utf8"));
if (card.konami_id && card.sets[lang]) {
try {
const official = JSON.parse(await fs.promises.readFile(path.join(process.argv[3], lang, `${card.konami_id}.json`), "utf8"));
const discrepancy: Discrepancy = {
yugipedia_page_id: card.yugipedia_page_id,
konami_id: card.konami_id,
password: card.password,
name_en: card.name.en
};
const name = stripRuby(card.name[lang]);
if (name !== official.name) {
discrepancy.name = {
wk: name,
db: official.name
};
}
const text = stripRuby(card.text[lang]).replaceAll("● ", "●");
if (text !== official.effectText) {
discrepancy.text = {
wk: text,
db: official.effectText
};
}
if (card.pendulum_effect) {
const pendulum = card.pendulum_effect[lang] ? stripRuby(card.pendulum_effect[lang]) : null;
if (pendulum != official.pendEffect) {
discrepancy.pendulum = {
wk: pendulum,
db: official.pendEffect
};
}
}
if (discrepancy.name || discrepancy.text || discrepancy.pendulum) {
discrepancies.push(discrepancy);
}
} catch (e) {
console.warn(`Trying to find official data for ${card.konami_id}|${card.password} [${card.name.en}]`, e);
}
}
}
}
process.stdout.write(JSON.stringify(discrepancies, null, 2) + "\n");

Check failure on line 92 in src/check-for-ygoresources-discrepancies.ts

View workflow job for this annotation

GitHub Actions / lint-typescript

Unexpected string concatenation
process.exitCode = Math.min(255, discrepancies.length);
})();

0 comments on commit 6d392eb

Please sign in to comment.