-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
44 lines (32 loc) · 1013 Bytes
/
main.js
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
let img_list = [];
let imgUrl = [];
let index = 0
async function fetchData() {
try {
const response = await fetch('https://api.artic.edu/api/v1/artworks?fields=image_id,title,artist_display,place_of_origin,medium_display,short_description,date_display,department_title?page=1&limit=10');
const artworks = response.data.data;
artworks.forEach(artwork => {
//make a class for each artwork!!
img_list.push(artwork.image_id);
});
} catch (error) {
console.error('Error:', error.message);
}
}
async function getImage(imgID) {
try {
// Fetch image URL only
const imageUrl = `https://www.artic.edu/iiif/2/${imgID}/full/843,/0/default.jpg`;
imgUrl.push(imageUrl)
} catch (error) {
console.error(`Error fetching image ${imgID}:`, error.message);
return null;
}
}
async function run() {
fetchData()
getImage(img_list)
console.log(img_list)
console.log(imgUrl)
}
run()