Spaces:
Paused
Paused
Download test-keywords.mjs from Luca448/APP-Backend: direct link, hf CLI and curl.
- Browser
- Download file 960 Bytes
-
https://huggingface.co/spaces/Luca448/APP-Backend/resolve/main/test-keywords.mjs
- Command line
-
hf download hf://spaces/Luca448/APP-Backend/test-keywords.mjs
-
curl -L -o test-keywords.mjs https://huggingface.co/spaces/Luca448/APP-Backend/resolve/main/test-keywords.mjs
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(); | |