APP-Backend / test-keywords.mjs
Luca448's picture
Update independent app to newest state with LFS and binary removals
ff36e71
Raw History Blame Contribute Delete
960 Bytes
const keywords = ['Wat Phra Kaew', 'Wat Arun', 'Chao Phraya', 'Tuk-Tuk'];
async function test() {
const fetchPromises = keywords.map(async (keyword) => {
try {
const res = await fetch(`https://de.wikipedia.org/w/api.php?action=query&generator=search&gsrsearch=${encodeURIComponent(keyword)}&gsrlimit=1&prop=pageimages&format=json&pithumbsize=1000&origin=*`);
const data = await res.json();
if (data.query && data.query.pages) {
const pageId = Object.keys(data.query.pages)[0];
const p = data.query.pages[pageId];
if (p.thumbnail && p.thumbnail.source) {
return { url: p.thumbnail.source, keyword: keyword };
}
}
} catch (e) {
console.error("Keyword fetch failed", keyword, e);
}
return null;
});
const results = await Promise.all(fetchPromises);
console.log(results.filter(r => r !== null));
}
test();