forked from jpchip/giveaway-grabber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (44 loc) · 1.2 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /usr/bin/env node
require('dotenv').config();
const puppeteer = require('puppeteer');
const args = require('yargs').argv;
const { enterGiveaways } = require('./src/giveaways');
const signIn = require('./src/signIn');
//start index code
(async () => {
const username = process.env.AMAZON_USERNAME || args.username;
const password = process.env.AMAZON_PASSWORD || args.password;
if (!username || !password) {
console.error('Missing required username and/or password!');
return;
}
//add to process.env to be used elsewhere if needed
process.env.AMAZON_USERNAME = username;
process.env.AMAZON_PASSWORD = password;
if (args.blacklist) {
process.env.BLACKLIST = args.blacklist;
}
if (args.SENDGRID_API_KEY) {
process.env.SENDGRID_API_KEY = args.SENDGRID_API_KEY;
}
if (args.SENDGRID_CC) {
process.env.SENDGRID_CC = args.SENDGRID_CC;
}
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
let pageNumber = 1;
if (args.page) {
pageNumber = args.page;
}
//sign in
await signIn(
page,
username,
password,
pageNumber,
args.hasOwnProperty('2FA')
);
//enter giveaways
await enterGiveaways(page, args.page || 1);
await browser.close();
})();