How to use the wtf_wikipedia.fetch function in wtf_wikipedia

To help you get started, we’ve selected a few wtf_wikipedia examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github KorySchneider / wikit / index.js View on Github external
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
github datafornews / metada / react / src / utils / getWikiImage.js View on Github external
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,
github xyfir / illuminsight / lib / reader / get-wiki-article.ts View on Github external
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,
  });
}

wtf_wikipedia

parse wikiscript into json

MIT
Latest version published 4 months ago

Package Health Score

78 / 100
Full package analysis