-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpokeapi_to_syncano.js
More file actions
36 lines (33 loc) · 953 Bytes
/
pokeapi_to_syncano.js
File metadata and controls
36 lines (33 loc) · 953 Bytes
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
var Syncano = require('syncano'); // CommonJS
var PokeApi = require('pokeapi');
var connection = Syncano({
apiKey: '<YOUR_API_KEY>',
defaults: {
instanceName: '<YOUR_INSTANCE_NAME>',
className: 'pokemons'
}
});
var api = PokeApi.v1();
var dataObjects = [];
var pokemons = [];
const toSyncano = function() {
connection.DataObject
.please()
.bulkCreate(dataObjects)
.then((response) => console.log(response))
.catch((error) => console.log(error));
};
for (var i = 1; i <= 151; i++) {
api.get('pokemon', i)
.then(function(response) {
console.log(response);
var types = [];
response.types.forEach((type) => { types.push(type.name) });
connection.DataObject.please().create({
pokemon_id: response.national_id,
name: response.name,
types: types,
image_url: 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/' + response.national_id + '.png'
});
})
}