-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·149 lines (115 loc) · 4.16 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
'use strict'
const settings = require('./settings')
const {
initializeBrowser,
createPage,
pageGoToUrl,
putUserName,
getHiddenName,
getToken,
putPasswordAndToken,
validatePasswordError,
validatePoupWindow,
waitMainView,
userActionsMapping,
closeSession,
getLastLoginDate,
solveCaptcha
} = require('./scraper')
const {
promptUser,
promptToken,
promptPassword,
showMainMenu
} = require('./prompts')
const {
logWarning,
logSuccess,
printToken,
clearScreenshots,
startLoader
} = require('./utils')
const createDependencies = async () => {
return {
"puppeteer": require('puppeteer-extra'),
"chalk": require('chalk'),
"inquirer": require('inquirer'),
"loading": require('loading-cli'),
"recaptcha": require('puppeteer-extra-plugin-recaptcha'),
"stealth": require('puppeteer-extra-plugin-stealth')
}
}
const {
Logger
} = require('./logger');
(async () => {
await clearScreenshots()
const dependecies = await createDependencies()
const browser = await initializeBrowser(
dependecies["puppeteer"],
dependecies["recaptcha"],
dependecies["stealth"],
settings["browserSettings"],
settings["captchaSettings"]
)
const logger = new Logger(dependecies['chalk'])
logger.success("Welcome to BANORTE CLI - 🤖")
const user = await promptUser(dependecies["inquirer"])
const password = await promptPassword(dependecies["inquirer"])
logger.warning("🤖: No la compartas con nadie bb, sólo conmigo 😘")
let loader = startLoader(dependecies["loading"])
const pageSettings = {
...settings["page"]
}
const newPage = await createPage(browser, pageSettings)
const startPage = await pageGoToUrl(newPage, settings["urls"]["start"])
try {
const closeModalIfExists = await validatePoupWindow(
startPage,
settings["modalSelector"],
settings["closeSelector"],
dependecies['chalk']
)
const passwordPage = await putUserName(closeModalIfExists, user, settings["userSelector"], settings["userSubmitSelector"])
const userMaskName = await getHiddenName(passwordPage, settings["hiddenNameSelector"])
const token = await getToken(passwordPage, settings["passwordSelector"], userMaskName)
loader.stop()
printToken(logger, token, userMaskName)
const userToken = await promptToken(dependecies["inquirer"])
loader = startLoader(dependecies["loading"])
const accessPage = await putPasswordAndToken(
passwordPage,
password,
userToken,
settings["passwordLoginSelector"],
settings["tokenLoginSelector"],
settings["submitPasswordSelector"]
)
const solvedCaptchaPage = await solveCaptcha(accessPage, settings["submitPasswordSelector"])
const hasLoginError = await validatePasswordError(solvedCaptchaPage, settings["sessionErrorSelector"])
const accountsPage = await waitMainView(solvedCaptchaPage, settings["accountsViewSelector"])
const lastLoginDate = await getLastLoginDate(accountsPage, settings["lastLoginSelector"])
loader.stop()
if (!lastLoginDate) {
throw new Error("No se completo el login")
}
let userOption = null
let action = null
logger.success("🤖: Sesión iniciada correctamente")
logger.warning(`🤖: Tu último login fue: ${lastLoginDate}`)
while(userOption != "end_session") {
userOption = await showMainMenu(dependecies['inquirer'])
loader = startLoader(dependecies['loading'])
action = userActionsMapping[userOption]
await action(accountsPage, dependecies['chalk'], settings)
loader.stop()
}
await closeSession(accountsPage, settings)
logger.success("🤖: Adiós popo, ya cerre tu sesión!")
} catch (error) {
console.log(error)
loader.stop()
logger.error(`🤖: Ocurrió un error bastardo, y dice así: ${error.message}`)
}
// await browser.close()
})();