-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwikipedia.js
More file actions
27 lines (25 loc) · 797 Bytes
/
wikipedia.js
File metadata and controls
27 lines (25 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const axios = require('axios');
const { convert } = require('html-to-text');
const logger = require('./logger');
module.exports = async function search(text) {
try {
const results = await axios.get("https://ru.wikipedia.org/w/api.php", {
params: {
action: 'query',
list: 'search',
srsearch: text,
format: 'json',
srlimit: 5
}
})
return results.data.query.search.map(result => ({
title: result.title,
subtitle: convert(result.snippet, {
wordwrap: null,
}),
link: `https://ru.wikipedia.org/wiki/${result.title.replaceAll(' ', '_')}`
}));
} catch (err) {
logger.error(err);
}
}