Skip to content

Instantly share code, notes, and snippets.

@Ara4Sh
Forked from m-esm/code-node.js
Created July 11, 2023 10:33
Show Gist options
  • Save Ara4Sh/7687c6df169f6f51545ad820188a25d2 to your computer and use it in GitHub Desktop.
Save Ara4Sh/7687c6df169f6f51545ad820188a25d2 to your computer and use it in GitHub Desktop.
embassy-appointment-n8n
const vision = require("@google-cloud/vision");
const puppeteer = require("puppeteer");
const fs = require("fs-extra");
const URL = "https://YOUR_EMBASSY_URL_AND_THE_PAGE";
const browser = await puppeteer.connect({
browserWSEndpoint: `ws://browserless:3000?token=TOKEN_HERE`,
args: [`--window-size=1024,860`],
defaultViewport: {
width: 1024,
height: 860,
},
});
const page = await browser.newPage();
await page.goto(URL, { waitUntil: "networkidle0" });
const client = new vision.ImageAnnotatorClient({
credentials: "GET_SERVICE_ACCOUNT_JSON_FROM_GCP_CONSOLE",
});
const captchaImg = await page.screenshot({
clip: {
height: 50,
width: 150,
x: 360,
y: 460,
},
});
fs.writeFileSync("captcha.jpeg", captchaImg);
const [result] = await client.documentTextDetection({
image: { content: captchaImg },
});
const fullTextAnnotation = result.fullTextAnnotation;
const captcha = fullTextAnnotation.text;
await page.type("#ctl00_MainContent_txtCode", captcha);
await page.click("input[type=submit]");
const afterCaptchaContent = await page.content();
if (afterCaptchaContent.includes("правильно")) throw new Error("wrong captcha");
fs.writeFileSync("screenshot1.jpeg", await page.screenshot());
await page.waitForSelector("#ctl00_MainContent_ButtonB", {
visible: true,
timeout: 1000,
});
await page.click("input[type=image]", { waitUntil: "networkidle0" });
await page.reload({ waitUntil: "networkidle0" });
const content = await page.content();
fs.writeFileSync("screenshot2.jpeg", await page.screenshot());
if (content.includes("Извините")) {
return { result: "Still no availability 🙁", captcha };
}
return { result: "Availability found 🎉🔥💦🎉🔥💦", captcha };
mkdir /tmp/n8n_image_builder
rm /tmp/n8n_image_builder/Dockerfile
sudo echo '
FROM n8nio/n8n:latest
RUN apk add --update python3 py3-pip
RUN npm install -g uuid
RUN npm install -g lodash
RUN npm install -g puppeteer
RUN npm install -g fs-extra
RUN npm install -g @google-cloud/vision
RUN CHMOD -R 777 /data
VOLUME ['/home/node/.n8n']
' >/tmp/n8n_image_builder/Dockerfile
cd /tmp/n8n_image_builder/
sudo docker build -t sad-n8n .
sudo docker run -d --name browserless \
--restart always \
-p 3330:3000 \
-e "TOKEN=_____TOKEN_HERE_____" \
-e "ENABLE_CORS=true" \
-e "FUNCTION_BUILT_INS=[\"url\", \"util\"]" \
-e "FUNCTION_EXTERNALS=[\"request\", \"fetch\"]" \
-e "PREBOOT_CHROME=true" \
-e "KEEP_ALIVE=true" \
browserless/chrome
base_data_path="/home/something/docker"
cname="n8n"
sudo docker remove ${cname} --force
sudo docker run -it -d \
--restart always \
--name ${cname} \
-e NODE_FUNCTION_ALLOW_BUILTIN=* \
-e NODE_FUNCTION_ALLOW_EXTERNAL=* \
-e N8N_ENCRYPTION_KEY=____N8N_ENCRYPTION_KEY_HERE____ \
-e N8N_USER_MANAGEMENT_DISABLED=false \
-e N8N_HOST=n8n.something.xyz \
-e WEBHOOK_URL=https://n8n.something.com/ \
-p 5678:5678 \
-v ${base_data_path}/${cname}:/home/node/.n8n \
-l traefik.backend=${cname} \
-l traefik.docker.network=bridge \
-l traefik.enable=true \
-l traefik.frontend.entryPoints=http \
-l traefik.frontend.rule=Host:n8n.something.com \
--link browserless:browserless \
sad-n8n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment