Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function printWikiSummary(queryText) {
let spinner = ora({ text: 'Searching...', spinner: 'dots4' }).start();
queryText = queryText.replace(/_/g, ' ');
wiki.fetch(queryText, _lang, (err, doc) => {
spinner.stop();
if (err) {
console.log('Error:', err);
}
if (doc) {
let summary = doc.sections()[0].text();
// Handle ambiguous results
if (_disambig || isDisambiguationPage(doc) || summary.includes('may refer to:')) {
handleAmbiguousResults(doc, queryText);
return;
}
// Output
return;
}
const lang = entity.wiki_link.split('://')[1].split('.')[0];
const wiki = entity.wiki_link.split('/');
const pageTitle = wiki[wiki.length - 1];
let escapedTitle = pageTitle.indexOf('%') > -1 ? pageTitle : encodeURIComponent(pageTitle);
escapedTitle = escapedTitle.replace('%25C3%2589', 'E').replace("'", '%27');
const pageIdRequest = `https://${lang}.wikipedia.org/w/api.php?action=query&titles=${escapedTitle}&format=json&origin=*`
const pageIdResponse = await fetch(pageIdRequest);
const data = await pageIdResponse.json();
if (data && data.query && data.query.pages) {
const page = Object.keys(data.query.pages)[0];
wtf.fetch(parseInt(page, 10), lang).then(doc => {
const info = doc.infobox(0).data;
const images = ["logo", "image"];
for (const img of images) {
if (Object.keys(info).indexOf(img) > -1) {
const name = replaceAll(info[img].data.text, " ", "_");
const mdi = md5(name)
imageAddress = `https://upload.wikimedia.org/wikipedia/${lang}/${mdi[0]}/${mdi[0] + mdi[1]}/${name}`;
checkImage(
imageAddress,
() => { setImageUrl(imageAddress, component, entity) },
() => {
imageAddress = `https://upload.wikimedia.org/wikipedia/commons/${mdi[0]}/${mdi[0] + mdi[1]}/${name}`;
checkImage(
imageAddress,
export function getWikiArticle(
title: string,
recipe: Illuminsight.WikiRecipe,
): Promise {
return wtf.fetch(title, undefined, {
wikiUrl: recipe.proxy ? process.enve.PROXY_URL + recipe.api : recipe.api,
});
}