-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (29 loc) · 870 Bytes
/
index.js
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
const { IgApiClient } = require('instagram-private-api');
const { getRandomFrame } = require('./scrapper.js');
require('dotenv').config();
const ig = new IgApiClient();
const user = process.env.IG_USERNAME;
const pass = process.env.IG_PASSWORD;
async function login() {
// basic login-procedure
ig.state.generateDevice(user);
await ig.account.login(user, pass);
}
const handler = async (event, context) => {
if(!user || !pass){
console.log('Ig username or pass not found');
return
}
await login();
const res = await getRandomFrame();
// console.log('description', res.juicyPostDescription);
const publishResult = await ig.publish.photo({
// attach image as a buffer
file: res.frameBuffer,
// optional, default ''
caption: res.juicyPostDescription,
});
console.log(publishResult);
return;
}
module.exports = {handler};