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

copyrightViolationBot: check against hamichlol. #505

Merged
merged 1 commit into from Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions bot/API/copyvios.ts
Expand Up @@ -32,8 +32,18 @@ export type CopyViolationRespons = {
}[];
}

export default async function checkCopyViolations(title: string, lang = 'he'): Promise<CopyViolationRespons> {
const res = await fetch(`${baseUrl}?version=1&action=search&project=wikipedia&lang=${lang}&title=${encodeURIComponent(title)}`);
export default async function checkCopyViolations(
title: string,
lang: string,
url?: string,
): Promise<CopyViolationRespons> {
const sharedParams = `version=1&project=wikipedia&lang=${lang}&title=${encodeURIComponent(title)}`;
if (url) {
const res = await fetch(`${baseUrl}?action=compare&${sharedParams}&url=${encodeURIComponent(url)}`);

return res.json();
}
const res = await fetch(`${baseUrl}?action=search&${sharedParams}`);

return res.json();
}
70 changes: 41 additions & 29 deletions bot/maintenance/copyrightViolation.ts
Expand Up @@ -53,6 +53,8 @@ async function getLastRun(api: ReturnType<typeof NewWikiApi>): Promise<string> {
const NOT_FOUND = 'not found';
const DISAMBIGUATION = 'פירושונים';

const HAMICHLOL_DOMAIN = 'https://www.hamichlol.org.il/';

export default async function copyrightViolationBot() {
const api = NewWikiApi();
const currentRun = new Date();
Expand All @@ -72,45 +74,55 @@ export default async function copyrightViolationBot() {
});
return;
}
const res = await checkCopyViolations(page.title);
if (res.status === 'error') {
if (res.error?.code === 'bad_title') {
otherLogs.push({
text: NOT_FOUND,
title: page.title,
error: true,
});
} else {
const results = await Promise.all([
checkCopyViolations(page.title, 'he'),
checkCopyViolations(page.title, 'he', `${HAMICHLOL_DOMAIN}${encodeURIComponent(page.title)}`),
]);
results.forEach((res) => {
if (res.status === 'error') {
if (res.error?.code === 'no_data') { // Url not found
return;
}

if (res.error?.code === 'bad_title') {
otherLogs.push({
text: NOT_FOUND,
title: page.title,
error: true,
});
return;
}
logs.push({
title: page.title,
text: `[[${page.title}]] - ${res.error?.info}`,
error: true,
});

return;
}
return;
}

const { url, confidence, violation } = res.best ?? { violation: 'none', confidence: 0 };
if (violation === 'none') {
otherLogs.push({
const { url, confidence, violation } = res.best ?? { violation: 'none', confidence: 0 };
if (violation === 'none') {
otherLogs.push({
title: page.title,
text: `[[${page.title}]] ${confidence.toFixed(2)}${url ? ` [${url}]` : ''}`,
rank: confidence,
});
return;
}
const matchText = textFromMatch(confidence, violation, url, true);
logs.push({
title: page.title,
text: `[[${page.title}]] ${confidence.toFixed(2)}${url ? ` [${url}]` : ''}`,
text: `[[${page.title}]]{{כ}}${matchText}`,
rank: confidence,
});
return;
}
const matchText = textFromMatch(confidence, violation, url, true);
logs.push({
title: page.title,
text: `[[${page.title}]]{{כ}}${matchText}`,
rank: confidence,
});
res.sources?.filter((source) => source.violation !== 'none' && source.url != null && source.url !== url).forEach((source) => {
const currText = textFromMatch(source.confidence, source.violation, source.url);
logs.push({
title: page.title,
text: `[[${page.title}]]{{כ}}${currText}`,
rank: source.confidence,
res.sources?.filter((source) => source.violation !== 'none' && source.url != null && source.url !== url).forEach((source) => {
const currText = textFromMatch(source.confidence, source.violation, source.url);
logs.push({
title: page.title,
text: `[[${page.title}]]{{כ}}${currText}`,
rank: source.confidence,
});
});
});
});
Expand Down