295 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			295 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
let a = [1,2,3]
 | 
						|
 | 
						|
console.log(a.slice(0,4))
 | 
						|
 | 
						|
 | 
						|
 | 
						|
// const puppeteer = require("puppeteer");
 | 
						|
// const zulip = require("zulip-js");
 | 
						|
 | 
						|
// (async () => {
 | 
						|
//   const browser = await puppeteer.launch();
 | 
						|
//   const page = await browser.newPage();
 | 
						|
 | 
						|
//   // Điều hướng đến trang web chứa thẻ <a>
 | 
						|
//   await page.goto("https://www.cskh.evnspc.vn/TraCuu/LichNgungGiamCungCapDien");
 | 
						|
 | 
						|
//   // Tìm thẻ <a> cần click dựa trên selector CSS hoặc XPath
 | 
						|
//   const selectBoxSelector1 = "select#idCongTyDienLuc";
 | 
						|
//   await page.waitForSelector(selectBoxSelector1);
 | 
						|
//   await page.select(selectBoxSelector1, "PB11");
 | 
						|
 | 
						|
//   // Chờ cho trang mới mở
 | 
						|
//   // await page.waitForNavigation('select#idCongTyDienLuc');
 | 
						|
 | 
						|
//   // In ra nội dung của trang mới
 | 
						|
//   setTimeout(async () => {
 | 
						|
//     const tableData = await page.evaluate(() => {
 | 
						|
//       const tbody = document.querySelector("table"); // Lựa chọn thẻ <tbody> cần trích xuất
 | 
						|
//       const rows = tbody.querySelectorAll("tr"); // Lựa chọn tất cả các hàng (thẻ <tr>) bên trong thẻ <tbody>
 | 
						|
//       // const headerRow = document.querySelectorAll("thead"); // Lựa chọn tất cả các hàng (thẻ <tr>) bên trong thẻ <tbody>
 | 
						|
//       // Lấy tên các cột từ hàng đầu (thẻ <th>)
 | 
						|
//       // const headerColumns = headerRow.querySelectorAll("tr");
 | 
						|
//       // const columnNames = headerColumns.map((headerColumn) =>
 | 
						|
//         // headerColumn.textContent.trim()
 | 
						|
//       // );
 | 
						|
//       const data1 = [];
 | 
						|
//       // headerColumns.forEach((clo) => {
 | 
						|
//       //   const columns = Array.from(clo.querySelectorAll("th")); // Lựa chọn tất cả các cột (thẻ <td>) trong hàng
 | 
						|
//       //   const rowData = columns.map((column) => column.textContent.trim()); // Lấy nội dung của các cột và xóa khoảng trắng
 | 
						|
//       //   data1.push(rowData); // Thêm dữ liệu của hàng vào mảng data
 | 
						|
//       // });
 | 
						|
 | 
						|
//       // Lặp qua từng hàng và lấy nội dung của các cột (thẻ <td>) trong hàng
 | 
						|
//       const data = [];
 | 
						|
//       rows.forEach((row) => {
 | 
						|
//         const columns = Array.from(row.querySelectorAll("td")); // Lựa chọn tất cả các cột (thẻ <td>) trong hàng
 | 
						|
//         const headers = Array.from(row.querySelectorAll("th"));
 | 
						|
//         const rowHeader = headers.map((header) => header.textContent.trim());
 | 
						|
//         const rowData = columns.map((column) => column.textContent.trim()); // Lấy nội dung của các cột và xóa khoảng trắng
 | 
						|
//         data.push(rowData); // Thêm dữ liệu của hàng vào mảng data
 | 
						|
//         data1.push(rowHeader)
 | 
						|
//       });
 | 
						|
 | 
						|
//       return { data: data, columnNames: data1 };
 | 
						|
//     });
 | 
						|
//     const content = []
 | 
						|
//     tableData.data?.map((u,index)=>{
 | 
						|
//       for(let i=0; i<u.length;i++){
 | 
						|
//         tableData.data[index] = tableData.columnNames[index]+": "+u[]
 | 
						|
//       }
 | 
						|
//     })
 | 
						|
//     console.log("Table data:", );
 | 
						|
 | 
						|
//     await browser.close();
 | 
						|
//   }, 5000);
 | 
						|
// })();
 | 
						|
// console.log("data: ",
 | 
						|
// data.paragraphText
 | 
						|
//       .split("   ")
 | 
						|
//       .filter((i) => i.includes("KDC 91B") || i.includes("KDC91B")))
 | 
						|
// if (
 | 
						|
//   data.paragraphText
 | 
						|
//     .split("   ")
 | 
						|
//     .filter((i) => i.includes("KDC 91B") || i.includes("KDC91B")).length > 0
 | 
						|
// ) {
 | 
						|
//   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-------",
 | 
						|
//     };
 | 
						|
//   client.messages.send(params);
 | 
						|
// }
 | 
						|
 | 
						|
// 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)
 | 
						|
// })()
 |