-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (26 loc) · 1.58 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
const { python } = require("pythonia");
exports.driver = async function (cmds, executer, head) {
const unchromee = await python("./module.py");
const callbackString = cmds.toString();
const start = []
const code_raw = callbackString.match(/\{([\s\S]*)\}/);
const code_semi = code_raw && code_raw[1].trim();
const lines = code_semi.split('\n');
const code_semi_raw = lines.filter(line => !line.trim().startsWith('add.'));
const code = code_semi_raw.filter(line => !line.trim().startsWith('/'));
const import_matches = callbackString.match(/add\.[^\n]+/g);
const import_matches_replace = import_matches.map(match => match.replace(/^add\./, 'import '));
start.unshift('import undetected_chromedriver as uc')
if(head == "true"){
start.push('driver = uc.Chrome(headless=True)', 'from selenium.common.exceptions import WebDriverException', 'from selenium.webdriver.remote.webdriver import By', 'import selenium.webdriver.support.expected_conditions as EC', 'from selenium.webdriver.support.wait import WebDriverWait')
} else {
start.push('driver = uc.Chrome(headless=False)', 'from selenium.common.exceptions import WebDriverException', 'from selenium.webdriver.remote.webdriver import By', 'import selenium.webdriver.support.expected_conditions as EC', 'from selenium.webdriver.support.wait import WebDriverWait')
}
const middle = start.concat(import_matches_replace)
const all = middle.concat(code)
if (!all) {
console.error("No driver commands found in the callback.");
return [];
}
unchromee.dr(all, executer);
}