-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.mjs
109 lines (98 loc) · 3.23 KB
/
test.mjs
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* https://github.com/tbo47/ez-opendata
*
* Run `node test.mjs` to test the functions.
*/
import {
openstreetmapExtractDiets,
openstreetmapGeocoding,
openstreetmapGetPOIs,
openstreetmapGetPOIsBbox,
wikidataQuery,
wikimediaGetThumb,
wikimediaGetThumbs,
wikimediaPicOfTheDay,
wikimediaQuery,
wikipediaQuery,
} from './index.js'
const okEmoji = '✅'
{
try {
const res = await openstreetmapGeocoding('20 rue du Faubourg Saint-Antoine, 75012 Paris')
console.log(res)
} catch (error) {
console.log(error)
}
console.log(`${okEmoji} openstreetmapGeocoding`)
process.exit()
}
{
try {
const POIs = await openstreetmapGetPOIs('14.67,-17.46,14.71,-17.41', [
['amenity', 'cafe'],
['amenity', 'restaurant'],
])
if (POIs.length === 0) throw new Error('No POIs found. The openstreetmap API may be down.')
} catch (error) {
console.log(error)
}
console.log(`${okEmoji} openstreetmapGetPOIs`)
}
{
const POIs = await openstreetmapGetPOIsBbox(
{ _northEast: { lat: 14.71, lng: -17.41 }, _southWest: { lat: 14.67, lng: -17.47 } },
[
['amenity', 'cafe'],
['amenity', 'restaurant'],
]
)
if (POIs.length === 0) throw new Error('No POIs found. The openstreetmap API may be down.')
console.log(`${okEmoji} openstreetmapGetPOIsBbox`)
const diets = openstreetmapExtractDiets(POIs)
if (diets.length === 0) throw new Error('No diets.')
console.log(`${okEmoji} openstreetmapExtractDiets`)
}
{
try {
const articles = await wikipediaQuery()
if (articles.length === 0) throw new Error('No items found.')
} catch (error) {
console.log(error)
}
console.log(`${okEmoji} wikipediaQuery`)
}
{
const northEast = { lat: 14.78, lng: -17.4706 }
const southWest = { lat: 14.7, lng: -17.578 }
try {
const items = await wikidataQuery(northEast, southWest)
if (items.length === 0) throw new Error('No items found.')
console.log(`${okEmoji} wikidataQuery`)
} catch (error) {
console.log(error)
}
}
{
const images = await wikimediaPicOfTheDay('fr')
if (images.length === 0) throw new Error('No images found. The wikimedia API may be down.')
console.log(`${okEmoji} wikimediaPicOfTheDay`)
}
{
const pics = await wikimediaGetThumbs([136289240, 136289206], 'width', 400)
if (pics.length === 0) throw new Error('No items found.')
console.log(`${okEmoji} wikimediaGetThumbs`)
}
{
const northEast = { lat: 14.71, lng: -17.41 }
const southWest = { lat: 14.67, lng: -17.47 }
const limit = 10
const images = await wikimediaQuery(northEast, southWest, limit)
if (images.length === 0) throw new Error('No images found. The wikimedia API may be down.')
if (images.length !== limit) throw new Error('Not the amount of images expected. The wikimedia API may be down.')
console.log(`${okEmoji} wikimediaQuery`)
const pageId = images[0].pageid
const thumbWidth = 400 // 400px
const imageDetails = await wikimediaGetThumb(pageId, thumbWidth)
if (!imageDetails.title) throw new Error('A title is expected here.')
console.log(`${okEmoji} wikimediaInfo`)
}