Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
wtf_wikipedia.from_api(country.name.common, 'en', function (markup) {
console.log(markup)
var wiki = wtf_wikipedia.parse(markup)
if (wiki.type === 'disambiguation') {
console.log(country.name.common, 'disambiguation. fetching flag from +(country)')
return wtf_wikipedia.from_api(country.name.common + ' (country)', 'en', function (markup) {
var wiki = wtf_wikipedia.parse(markup)
console.log(country.name.common, '(country) wiki', wiki)
console.log(country.name.common, '(country) infobox', wiki.infobox)
if (wiki.infobox && wiki.infobox.image_flag && wiki.infobox.image_flag.text) {
console.log(country.name.common, '(country) flag', wiki.infobox.image_flag.text)
}
resolve(wiki.infobox)
})
}
console.log(country.name.common, 'infobox', wiki.infobox)
if (wiki.infobox && wiki.infobox.image_flag && wiki.infobox.image_flag.text) {
wtf_wikipedia.from_api(country.name.common, 'en', function (markup) {
console.log(markup)
var wiki = wtf_wikipedia.parse(markup)
if (wiki.type === 'disambiguation') {
console.log(country.name.common, 'disambiguation. fetching flag from +(country)')
return wtf_wikipedia.from_api(country.name.common + ' (country)', 'en', function (markup) {
var wiki = wtf_wikipedia.parse(markup)
console.log(country.name.common, '(country) wiki', wiki)
console.log(country.name.common, '(country) infobox', wiki.infobox)
if (wiki.infobox && wiki.infobox.image_flag && wiki.infobox.image_flag.text) {
console.log(country.name.common, '(country) flag', wiki.infobox.image_flag.text)
}
resolve(wiki.infobox)
})
}
console.log(country.name.common, 'infobox', wiki.infobox)
if (wiki.infobox && wiki.infobox.image_flag && wiki.infobox.image_flag.text) {
console.log(country.name.common, 'flag', wiki.infobox.image_flag.text)
country.flag = 'https://en.m.wikipedia.org/wiki/File:' + wiki.infobox.image_flag.text
}
resolve(wiki.infobox)
})
const fetch_page = function (title, cb) {
wtf_wikipedia.from_api(title, lang, function (markup) {
let text = wtf_wikipedia.plaintext(markup) || '';
let filename = __dirname + '/corpus/' + title + '.txt';
fs.writeFileSync(filename, text, 'utf8')
let mb = (fs.statSync(filename).size || 0) / 1000000.0;
console.log(title + ' - ' + mb.toFixed(2) + 'mb');
cb(null, '');
});
};
return new Promise(resolve => {
if (state.debug) {
console.log('ActionWikipedia'.bold.yellow, `concept: ${concept}`);
}
if (!concept) resolve(state);
wikipedia.from_api(concept, 'en', (response) => {
const document = wikipedia.parse(response);
if (document.type === 'page' && document.categories.length > 0) {
const summary = document.text.Intro.map(sentence => sentence.text).join(' ');
state.action = {
ms: (new Date() - ms),
engine: 'wikipedia',
entity: entities.knowledge,
image: `http://en.wikipedia.org/wiki/${document.images[0]}`,
title: document.infobox.name ? document.infobox.name.text : concept,
value: summary,
related: extract(document.infobox),
};
resolve(state);
}
names.forEach(function(name) {
WikipediaApi.from_api(name, 'en', function(markup) {
if(!markup){ console.log(name); return;}
var id = wikis[name][0];
var fullName = name;
var occupation = parseJob(markup);
var extract = parseExtract(markup);
var url = 'http://en.wikipedia.org/wiki/' + encodeURIComponent(fullName);
var update = {
'id': id,
'wikipedia': {
'fullName': fullName,
'occupation': occupation,
'extract': extract,
'url': url
}
};
this.onCommand_wiki = function(nick, args) {
var chan = this.channel;
if(args.trim() !== "") {
wikipedia.from_api(args, "en", function(markup){
var text = wikipedia.plaintext(markup).substring(0,100) + "...";
if (text != "...") {
chan.say(text + " https://en.wikipedia.org/w/index.php?title=" + encodeURIComponent(args));
} else {
chan.say("No page found");
}
});
} else {
chan.say("You're doing it wrong.\nUsage: " + settings.defaultCommandPrefix + "!wiki ");
}
};
};