-
Notifications
You must be signed in to change notification settings - Fork 1
/
main2.js
92 lines (79 loc) · 2.47 KB
/
main2.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import puppeteer from 'puppeteer-extra';
import { executablePath } from 'puppeteer';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
import axios from 'axios';
import fs from 'fs';
// URLS and constants
const TEMP_MAIL_URL = 'https://tempmailo.com/';
const ORELLY_REGISTER_URL = 'https://www.oreilly.com/start-trial/api/v1/registration/individual/';
const PASSWORD = 'Temp@123';
const MAX_RETRIES = 10;
// Enable stealth plugin for puppeteer
puppeteer.use(StealthPlugin());
// Function to get random name
const getRandomName = () => (Math.random() + 1).toString(36).substring(7);
// Function to get email ID
const getEmailId = async () => {
const browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox'],
ignoreHTTPSErrors: true,
executablePath: executablePath(),
});
try {
const page = await browser.newPage();
await page.goto(TEMP_MAIL_URL, { waitUntil: 'networkidle0' });
const emailId = await page.$eval('#i-email', node => node.value);
await page.screenshot({ path: './screenshot.jpg', type: 'jpeg', fullPage: 'true' });
return emailId;
} catch (err) {
console.error(err);
return 'temp@email.com';
} finally {
await browser.close();
}
};
// Function to create O'Reilly account
const createOReillyAccount = async () => {
const emailId = await getEmailId();
const data = {
email: emailId,
password: PASSWORD,
first_name: getRandomName(),
last_name: getRandomName(),
country: 'IN',
t_c_agreement: true,
contact: true,
path: '/start-trial/',
source: 'payments-client-register',
trial_length: 10,
};
try {
const response = await axios.post(ORELLY_REGISTER_URL, data);
console.log('Account created successfully');
const accountDetails = {
emailId,
password: PASSWORD,
accountCreatedOn: new Date().toLocaleDateString(),
};
fs.appendFile('account-details.txt', '\n' + JSON.stringify(accountDetails), err => {
if (err) throw err;
console.log('Successfully saved!');
});
} catch (err) {
console.error('Failed to create OReilly account', err);
}
};
// Main function
const main = async () => {
for (let i = 0; i < MAX_RETRIES; i++) {
try {
await createOReillyAccount();
console.log('Successfully created OReilly account! Enjoy');
break;
} catch (err) {
console.error('There was some error while trying to create Orelly account.', err);
}
}
};
main().catch(err => console.error(err));