-
Notifications
You must be signed in to change notification settings - Fork 2
/
apiData.txt
85 lines (56 loc) · 1.78 KB
/
apiData.txt
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
// Code used to get exercise data from API into our database
const apiUrlPrefix = `https://api.api-ninjas.com/v1/exercises?offset=`;
const apiKey = API_KEY;
let getExercises = async (num) => {
// console.log('hello1');
const apiUrl = apiUrlPrefix + num;
const apiKey = API_KEY;
let apiResults = await fetch(apiUrl, {
headers: {
'X-Api-Key': apiKey
}
})
.then(response => {return response.json()})
.catch(error => {
console.error('Error fetching data from the API:', error);
});
return apiResults;
}
// getExercises(10);
let getAllExercises = async (num = 0) => {
// if(num < 9){
// console.log('hello');
const results = await getExercises(num);
if (results.length>0){
return results.concat(await getAllExercises(num+10));
}
else{
return results;
}
// }
}
let getList = async() =>{
const entireList=await getAllExercises();
for(let i = 0; i < entireList.length -1; i++){
let curr = entireList[i];
if(curr){
// console.log(curr);
let name = curr.name;
let type = curr.type;
let muscle = curr.muscle;
let equipment = curr.equipment;
let instructions = curr.instructions;
console.log(name, type, muscle);
// try {
await db.exercises.create({name, type, muscle, equipment, instructions});
// } catch (error) {
// }
// console.log(entireList[i].name);
}
}
// entireList.forEach(result => {
// console.log(result[name]);
// })
// console.log(entireList);
}
getList();