Log_service/screenshot.js

260 lines
7.8 KiB
JavaScript

const puppeteer = require("puppeteer");
const zulip = require("zulip-js");
// const axios = require("axios");
(async () => {
// Launch a headless browser
const browser = await puppeteer.launch({
headless: true,
args: ["--no-sandbox"],
});
const config = {
username: "networktool-bot@zulip.ipsupply.com.au",
apiKey: "0jMAmOuhfLvBqKJikv5oAkyNM4RIEoAM",
realm: "https://zulip.ipsupply.com.au",
};
const client = await zulip(config);
// Open a new page
const page = await browser.newPage();
await page.goto("https://ithongtin.com/lich-cup-dien/can-tho/ninh-kieu");
const data = await page.evaluate(() => {
const title = document.title;
const paragraphText = document.querySelector("table").textContent;
return {
title,
paragraphText,
};
});
await browser.close();
let params = {
type: "stream",
to: "Result test - auto.nswteam.net",
topic: "Lịch cúp điện",
content:
":warning: :date: :warning:\n" +
data.paragraphText
.split(" ")
.filter((i) => i.includes("KDC 91B") || i.includes("KDC91B"))[0].replace(/ /g,"\n\n").replace(/KDC 91B/g,"**KDC 91B**") +
"\n-------",
};
if (
data.paragraphText
.split(" ")
.filter((i) => i.includes("KDC 91B") || i.includes("KDC91B")).length > 0
) {
client.messages.send(params);
}
// }, 5000);
// } else {
// console.error(`Element with class name '${className}' not found.`);
// }
// Close the browser
})();
// const zulip = require("zulip-js");
// const config = {
// zuliprc: "./download",
// zulipVersion: "v2",
// };
// async function deleteMessages() {
// const client = await zulip(config);
// // Thay thế "stream-name", "topic-name", và các mốc thời gian cụ thể
// const streamName = "Result test - auto.nswteam.net";
// const topicName = "test";
// try {
// const messages = await client.messages.retrieve({
// anchor: "oldest",
// num_before: 0,
// num_after: 5000, // Điều chỉnh theo nhu cầu của bạn
// narrow: [
// { operator: "stream", operand: streamName },
// { operator: "topic", operand: topicName },
// // {
// // operator: ,
// // operand: `169457100,1694571399`,
// // },
// ],
// });
// // console.log(messages.messages.map(u=>u.reactions))
// const members = await client.users.retrieve();
// // console.log(members.members)
// console.log(messages.messages.length)
// // await client.messages.deleteById([159454, 159455]);
// for (const message of messages.messages) {
// console.log(message.id)
// if (
// message.reactions.filter(
// (i) =>
// i.emoji_name === "working_on_it" &&
// members.members.filter((u) => u.user_id === i.user_id)[0]
// .is_admin === true
// ).length === 0 &&
// message.timestamp < Math.floor((Date.now() - 60000*60*24*10) / 1000)
// ) {
// const res = await client.messages.deleteById({
// message_id: message.id,
// });
// console.log(`Deleted message ID ${message.id}`);
// console.log(res)
// }
// }
// } catch (error) {
// console.error("Error:", error);
// }
// }
// deleteMessages();
// const zulip = require("zulip-js");
// const fs = require("fs");
// const config = {
// zuliprc: "./download",
// zulipVersion: "v2", // Use the appropriate API version
// };
// const imageFilePath = "./screenshot.png";
// const imageBase64 = fs.readFileSync(imageFilePath, { encoding: "base64" });
// async function send() {
// const client = await zulip(config);
// try {
// const message = {
// type: "stream",
// to: "Result test - auto.nswteam.net", // Replace with the target stream name or recipient email
// topic: "AU-dev", // Replace with the message topic
// content: "Check out this image:",
// filename: "asakfga",
// file: imageBase64
// };
// client.messages.sendFile(message).then((response) => {
// console.log("Message sent successfully:", response);
// });
// } catch (error) {
// console.error("Error:", error);
// }
// }
// send();
// Usage example
// const filePath = __dirname+'\\screenshot.png';
// uploadFileToZulip(filePath);
// const zulip = require('zulip-js');
// // Configure your Zulip API details
// const config = {
// username: 'joseph.le@apactech.io',
// apiKey: '7XGrpwzFtQyUVDQzdwL3hjdVSbLx55yt',
// realm: 'https://zulip.ipsupply.com.au',
// };
// async function uploadFileToZulip(filePath) {
// try {
// const client = await zulip(config);
// // Read the file as binary data
// const fs = require('fs');
// const fileData = fs.readFileSync(filePath);
// // Create a FormData object
// const formData = new FormData();
// formData.append('file', fileData);
// // Upload the file
// const response = await client.callEndpoint('POST', 'user_uploads', formData, {headers:{
// 'Content-Type': 'multipart/form-data',
// // other headers if needed
// }});
// // if (response.result === 'success') {
// // const uploadedFileURL = response.uri;
// // console.log('File uploaded successfully. URL:', uploadedFileURL);
// // } else {
// // console.error('Failed to upload file:', response.msg);
// // }
// } catch (error) {
// console.error('Error uploading file:', error);
// }
// }
// const filePath = 'screenshot.png'; // Replace with your file path
// uploadFileToZulip(filePath);
// const puppeteer = require("puppeteer");
// (async () => {
// const browser = await puppeteer.launch();
// // Store the endpoint to be able to reconnect to the browser.
// const browserWSEndpoint = browser.wsEndpoint("https://pptr.dev/api/puppeteer.browser");
// // Disconnect puppeteer from the browser.
// browser.disconnect();
// // Use the endpoint to reestablish a connection
// const browser2 = await puppeteer.connect({browserWSEndpoint});
// // Close the browser.
// await browser2.close();
// })();
// const zulip = require("zulip-js");
// (async () => {
// const config = {
// username: "networktool-bot@zulip.ipsupply.com.au",
// apiKey: "0jMAmOuhfLvBqKJikv5oAkyNM4RIEoAM",
// realm: "https://zulip.ipsupply.com.au",
// };
// const client = await zulip(config);
// const user_id = 45;
// let params = {
// to: "joseph.le@apactech.io",
// type: "private",
// content: "With mirth and laughter let old wrinkles come.",
// };
// console.log(await client.messages.send(params))
// })()
// (async()=>{
// let listLog = []
// let from = 20230926
// let to = 20230926
// const response = await axios.get("http://192.168.5.7:8080/");
// const responseAUTO = await axios.get(
// "http://192.168.5.7:8080/AUTOlog/"
// );
// let data1 = response.data.split("\n")
// .filter((i) => i.search("<a href") !== -1 && i.search(".log") !== -1);
// let data2 = responseAUTO.data.split("\n")
// .filter((i) => i.search("<a href") !== -1 && i.search(".log") !== -1);
// const arrayLine = data1.concat(data2)
// // const arrayLineAUTO = data
// // .split("\n")
// // .filter((i) => i.search("<a href") !== -1 && i.search(".log") !== -1);
// arrayLine.map((u) => {
// let temp = u
// .slice(u.search("<a ") + 9, u.search("</a>"))
// .split(">")[1];
// if (
// parseInt(temp?.split("-")[0]) >= from &&
// parseInt(temp?.split("-")[0]) <= to
// ) {
// listLog.push(
// (u.slice(u.search("<a ") + 9, u.search("</a>")).split(">")[1].includes("AUTO")?"http://192.168.5.7:8080/AUTOlog/":"http://192.168.5.7:8080/") +
// u.slice(u.search("<a ") + 9, u.search("</a>")).split(">")[1] +
// " "
// );
// }
// });
// console.log(listLog)
// })()