-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.js
More file actions
40 lines (29 loc) · 1.31 KB
/
user.js
File metadata and controls
40 lines (29 loc) · 1.31 KB
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
/**
* InstaScripts
* A Collection of Instagram Facilitator Scripts
* https://github.com/ashenm/instascripts
*
* Ashen Gunaratne
* mail@ashenm.ml
*
*/
const qs = require('qs');
const axios = require('axios');
module.exports = async function (username, cookie={}) {
const response = await axios.get(`https://www.instagram.com/${username}/?__a=1`, {
headers: { 'Cookie': qs.stringify(cookie).replace(/&/g, '; '), 'X-CSRFToken': cookie.csrftoken || '', 'X-Instagram-AJAX': '1' }, validateStatus: null });
return response.data.graphql && response.status === 200 ? response.data.graphql.user
: { error: { code: response.status, message: require('http').STATUS_CODES[response.status] } };
};
if (require.main === module) {
const argv = require('yargs').boolean('login').argv;
if (argv._.length) {
Promise.resolve(argv.login ? require('./login')() : {}).then(credentials =>
Promise.all(argv._.map(user => module.exports(user, credentials)))).then(console.info);
return;
}
require('prompts')({ type: 'text', name: 'user', message: 'Username' }).then(response => Promise.all([
Promise.resolve(response.user), Promise.resolve(argv.login ? require('./login')() : {})
])).then(argv => module.exports.apply(null, argv)).then(console.info);
}
/* vim: set expandtab shiftwidth=2 syntax=javascript: */