const City = sequelize.define("city",
{
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true,
allowNull: false
},
title: {
type: Sequelize.STRING,
allowNull: false
},
area: {
type: Sequelize.STRING,
allowNull: false
},
region: {
type: Sequelize.STRING,
allowNull: false
},
}
);
let offset = 0;
let count = 1;
do {
let response = await axios.get(`https://api.vk.com/method/\
database.getCities?\
&country_id=1&need_all=1&count=1000&offset=${offset}&\
access_token=${vk.vk.ACCESS_TOKEN}&v=5.110`);
let items = response.data.response.items
items.map(async function(item) {
City.create({
id: item.id,
title: item.title,
area: item.area ? item.area: '',
region: item.region ? item.region: '',
}).then(res => {console.log(res.title)})
.catch(error => {console.log(error)})
})
offset += response.data.response.items.length;
count = response.data.response.count;
console.log(`offset: ${offset}\ncount: ${count}`);
} while (offset != count);