Skip to content

Instantly share code, notes, and snippets.

@sizovilya
Last active April 28, 2017 09:41
Show Gist options
  • Save sizovilya/f05c1d7ca92059006ab8e7294bf142fc to your computer and use it in GitHub Desktop.
Save sizovilya/f05c1d7ca92059006ab8e7294bf142fc to your computer and use it in GitHub Desktop.
sql.connect(config.sqlConfig).then(pool => {
this.pool = pool;
pool.request().query `select * from dbo.Groups`
})
.then(iSuccesfullyGetGroups.bind(this), errorConnect)
.then(startParsing.bind(this))
function iSuccesfullyGetGroups(result){
const groups = result.recordset;
if (groups.length > 0) {
VK.auth.user().then(token => {
for (const group of groups) {
VK.call('execute.getPosts', {
mode: "getOffset",
groupId: group.GroupId,
topicId: group.TopicId
}).then(res => {
console.log(res);
return this.pool.request().query `UPDATE dbo.Groups SET offset = ${res.count} WHERE Id = ${group.Id}`
}).catch(err => {});
}
});
}
}
function startParsing(pool) {
setInterval(() => {
pool.request().query(`select * from dbo.Groups`).then(successGetGroups.bind(this));
}, 5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment