update function sync SN to ERP

This commit is contained in:
joseph le 2023-09-26 16:50:19 +07:00
parent e88666aa98
commit 3c51af8631
2 changed files with 73 additions and 19 deletions

View File

@ -18,10 +18,23 @@ export default class ErpsController {
// console.log("check!") // console.log("check!")
const listLog: string[] = []; const listLog: string[] = [];
const response = await axios.get("http://192.168.5.7:8080/"); const response = await axios.get("http://192.168.5.7:8080/");
const data = response.data; const responseAUTO = await axios.get(
const arrayLine = data "http://192.168.5.7:8080/AUTOlog/"
);
let data1 = response.data
.split("\n") .split("\n")
.filter((i) => i.search("<a href") !== -1 && i.search(".log") !== -1); .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) => { arrayLine.map((u) => {
let temp = u let temp = u
.slice(u.search("<a ") + 9, u.search("</a>")) .slice(u.search("<a ") + 9, u.search("</a>"))
@ -32,7 +45,7 @@ export default class ErpsController {
parseInt(temp?.split("-")[0]) <= to parseInt(temp?.split("-")[0]) <= to
) { ) {
listLog.push( listLog.push(
"http://192.168.5.7:8080/" + (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] + u.slice(u.search("<a ") + 9, u.search("</a>")).split(">")[1] +
" " " "
); );
@ -290,7 +303,7 @@ export default class ErpsController {
fileName.search("AUTO") !== -1 ? "AUTOlog/" + fileName : fileName; fileName.search("AUTO") !== -1 ? "AUTOlog/" + fileName : fileName;
const res = await axios.get("http://192.168.5.7:8080/" + fName); const res = await axios.get("http://192.168.5.7:8080/" + fName);
const arrayLine = res?.data?.split("\n"); const arrayLine = res?.data?.split("\n");
if (range >= line) { if (range >= line) {
response.status(200).json({ response.status(200).json({
content: arrayLine?.slice(0, line + range)?.join("\n"), content: arrayLine?.slice(0, line + range)?.join("\n"),

View File

@ -1,5 +1,7 @@
// const puppeteer = require("puppeteer"); // const puppeteer = require("puppeteer");
const axios = require("axios");
// (async () => { // (async () => {
// // Launch a headless browser // // Launch a headless browser
// const browser = await puppeteer.launch({ // const browser = await puppeteer.launch({
@ -176,22 +178,61 @@
// // Close the browser. // // Close the browser.
// await browser2.close(); // await browser2.close();
// })(); // })();
const zulip = require("zulip-js"); // const zulip = require("zulip-js");
(async () => { // (async () => {
const config = { // const config = {
username: "networktool-bot@zulip.ipsupply.com.au", // username: "networktool-bot@zulip.ipsupply.com.au",
apiKey: "0jMAmOuhfLvBqKJikv5oAkyNM4RIEoAM", // apiKey: "0jMAmOuhfLvBqKJikv5oAkyNM4RIEoAM",
realm: "https://zulip.ipsupply.com.au", // realm: "https://zulip.ipsupply.com.au",
}; // };
const client = await zulip(config); // const client = await zulip(config);
const user_id = 45; // const user_id = 45;
let params = { // let params = {
to: "joseph.le@apactech.io", // to: "joseph.le@apactech.io",
type: "private", // type: "private",
content: "With mirth and laughter let old wrinkles come.", // content: "With mirth and laughter let old wrinkles come.",
}; // };
console.log(await client.messages.send(params)) // 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)
})() })()