-
-
Save KamilLelonek/d6c712960efcabf726cbe4e7dcb06762 to your computer and use it in GitHub Desktop.
fetch demographics data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import request from 'request-promise'; | |
exports.run = async() => { | |
const bloggers = await global.db.models.Blogger.findAll({ | |
where: { | |
instagramDemographics: { | |
$ne: null, | |
}, | |
}, | |
}); | |
global.winston.info(`Fetching 'demographics data' for '${bloggers.length}' bloggers.`); | |
for (const blogger of bloggers) { | |
try { | |
const buffer = new Buffer([process.env.DEMOGRAPHICS_USERNAME, process.env.DEMOGRAPHICS_PASSCODE].join(':')); | |
const credentials = buffer.toString('base64'); | |
const data = await request.post({ | |
json: true, | |
/* eslint max-len: 0 */ | |
url: `https://www.demographicspro.com/6/api/get_aggregate_analysis?for=request_id&data=${blogger.instagramDemographics}&network=instagram`, | |
headers: { | |
Authorization: `Basic ${credentials}`, | |
}, | |
}); | |
await blogger.getInstagramDemographics(data); | |
// Mark as complete once inertd into the DB | |
} catch (err) { | |
console.log(err); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment