From 21aa21e03f197b100036bf2e333e7296c019c8f9 Mon Sep 17 00:00:00 2001 From: Vishal Date: Thu, 22 Aug 2024 23:25:47 +0530 Subject: [PATCH] update code to diff and save Signed-off-by: Vishal --- .github/workflows/rust.yml | 2 +- example/index.ts | 19 - example/old_state.html | 3912 ----------------- notification_push/index.js | 37 + notification_push/index.ts | 42 + .../package-lock.json | 4 +- {example => notification_push}/package.json | 3 +- 7 files changed, 83 insertions(+), 3936 deletions(-) delete mode 100644 example/index.ts delete mode 100644 example/old_state.html create mode 100644 notification_push/index.js create mode 100644 notification_push/index.ts rename {example => notification_push}/package-lock.json (97%) rename {example => notification_push}/package.json (91%) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 991fdf8..18f030f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -33,4 +33,4 @@ jobs: run: wasm-pack build -t nodejs --features wasm - name: Update node package - run: rsync -avz --delete pkg/ ~/notification-system-wasm + run: rsync -avz --delete pkg/ ~/notification-system-wasm/pkg/ diff --git a/example/index.ts b/example/index.ts deleted file mode 100644 index 871656f..0000000 --- a/example/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -import notification_system from "notification-system"; -import fs from "node:fs"; - -let html = await fetch("https://dtu.ac.in/") - .then(response => { - return response.text(); - }); - -let old_html = fs.readFileSync("old_state.html").toString(); -let config = notification_system.Configuration.default_config(); - - -let diff = notification_system.difference(html, old_html,config); - -console.log(diff); - -fs.writeFileSync("old_state.html", html); - -fs.writeFileSync("diff.json", JSON.stringify(diff, null, 2)); diff --git a/example/old_state.html b/example/old_state.html deleted file mode 100644 index 490a505..0000000 --- a/example/old_state.html +++ /dev/null @@ -1,3912 +0,0 @@ - - - - - - - - - - - - - - - -Delhi Technological University - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
- -
- - - -
- - - - -
- - - - - - - - - -
- - - -
- -
- -
- - - - - - - -
- - - -
- - - - - - - - - - - - - - - - - - - -
- -
- - - -
- - - - -
- - - -
- - - -
- - - - - - - - -
- -
- - - - - -
Important Updates
- - - - - » Revised Notification : Annual Fee structure for the Studens seeking admissions in the AY 2024-25 DTU Date:05.07.2024 -
-
- » Notification : Minor in Semiconductors and Microelectronics under Vinod Dham Centre of Excellence for Semiconductors and Microelectronics. Date:27.11.2023 -
-
- » Notification : Minor in Electric Vehicle Technology under centre of Excellence of Electric Vehicles and Related Technologies Date:24.11.2023 -
-
- » AICTE: Extension of Approval (EoA) Date:08.05.2023 -
-
- - » Annual Fee of all programs for the students taking admission in the Academic Session 2023-24 Date:12.04.2023 -
-
- - » DTU Innovation and start-up policy Date:29.10.2022 -
-
- - » Guidelines regarding Award of Medals to DTU students during Convocation of the University Date:29.06.2022 -
-
- - - » AICTE: Extension of Approval (EoA) -
-
- - » DTU Times Mobile App Launched -
  ||   Android -   ||   IOS  ||   -
-
- - » Revised Record Retention schedule of materials related to Recruitment Test. -
-
- - » Guidelines for Corpus fund at DTU -
-
- - » Notification regarding grant of adequate weightage to the Ph.D Degree Holders -
-
- - » Notification regarding guidelines for exemption of screening test for the posts of Assistant Professors -
-
- - » Central and Departmental Purchase Committee -
-
- - » Guidelines for setting Good Quality Question Papers -
  ||   Details -   ||   Automated Sheet  ||   -
-
- - » Notification : Grading System Date:12.02.2019 -
-
- - » Implementation of Court Order regarding dress code for exams/tests/interviews etc. Date:20.12.2018 -
-
- - » Feedback on Programme Outcome (PO) in acedemic departments Date:05.10.2018 -
-
- - » Promotion of Academic Intergrity and Prevention of Plagiarism Date:20.09.2018 -
-
- - » Ordinance 1(B) for all Undergraduate and Post graduate Degree Programs Date:14.09.2018 -
-
- - » Regulations for the Presenting Paper in the International Conferences / Symposia by the Faculty Date:14.09.2018 -
-
- - » CGPA to Percentage conversion Date:14.09.2018 -
-
- - » CL Educate Ltd. and DTU signed a MEMORANDUM OF UNDERSTANDING (MoU) for fostering collaboration on research, innovation and start-up incubation through CL Educate’s Worldwide Academia Industry Network (WAIN), an open innovation platform -
  ||   MOU -   ||   Web Link -   ||   - Date:08.06.2018 -
-
- - » Circular regarding Earned Leave for all the employees (Teaching & Non Teaching) Date:31.01.2018 -
-
- -
- -
- - - - -
- - -
- - -
- - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - -
- - - - - - - -
- - - -
- - - - - - - -
- - - -
- - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
- -
- -
- -
- - - -
- -
-
-
- -
- - - - - diff --git a/notification_push/index.js b/notification_push/index.js new file mode 100644 index 0000000..9a566e2 --- /dev/null +++ b/notification_push/index.js @@ -0,0 +1,37 @@ +import notification_system, { Configuration } from "notification-system"; +import fs from "node:fs"; +function save_request(data) { + fetch("http://localhost:8080/api/v1/notification/save", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ data: data, secret: process.env.NOTIF_SECRET }), + }) + .then(response => { + if (response.status != 200) { + throw new Error("Failed to save request"); + } + return response.json(); + }) + .then(data => console.log("Request saved", data)) + .catch(error => console.error(error)); +} +let html = await fetch("https://dtu.ac.in/") + .then(response => { + return response.text(); +}); +let config = Configuration.default_config(); +if (fs.existsSync("old_state.html")) { + let old_html = fs.readFileSync("old_state.html").toString(); + let diff = notification_system.difference(html, old_html, config); + console.log(JSON.stringify(diff, null, 2)); + if (diff.length > 0) { + save_request(diff); + } +} +else { + let diff = []; + console.log(diff); +} +fs.writeFileSync("old_state.html", html); diff --git a/notification_push/index.ts b/notification_push/index.ts new file mode 100644 index 0000000..1587af4 --- /dev/null +++ b/notification_push/index.ts @@ -0,0 +1,42 @@ +import notification_system, { InformationUpdate, Configuration } from "notification-system"; +import fs from "node:fs"; + + +function save_request(data: InformationUpdate) { + fetch("http://localhost:8080/api/v1/notification/save", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ data: data, secret: process.env.NOTIF_SECRET }), + }) + .then(response => { + if (response.status != 200) { + throw new Error("Failed to save request"); + } + return response.json(); + }) + .then(data => console.log("Request saved", data)) + .catch(error => console.error(error)); +} + +let html = await fetch("https://dtu.ac.in/") + .then(response => { + return response.text(); + }); + +let config = Configuration.default_config(); + +if (fs.existsSync("old_state.html")) { + let old_html = fs.readFileSync("old_state.html").toString(); + let diff = notification_system.difference(html, old_html, config); + console.log(JSON.stringify(diff, null, 2)); + if (diff.length > 0) { + save_request(diff); + } +} else { + let diff: InformationUpdate = []; + console.log(diff); +} + +fs.writeFileSync("old_state.html", html); diff --git a/example/package-lock.json b/notification_push/package-lock.json similarity index 97% rename from example/package-lock.json rename to notification_push/package-lock.json index 90d5292..58969f8 100644 --- a/example/package-lock.json +++ b/notification_push/package-lock.json @@ -9,10 +9,10 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "@types/node": "^22.5.0", "notification-system": "file:../pkg" }, "devDependencies": { - "@types/node": "^22.5.0", "typescript": "^5.5.4" } }, @@ -24,7 +24,6 @@ "version": "22.5.0", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.0.tgz", "integrity": "sha512-DkFrJOe+rfdHTqqMg0bSNlGlQ85hSoh2TPzZyhHsXnMtligRWpxUySiyw8FY14ITt24HVCiQPWxS3KO/QlGmWg==", - "dev": true, "license": "MIT", "dependencies": { "undici-types": "~6.19.2" @@ -52,7 +51,6 @@ "version": "6.19.8", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", - "dev": true, "license": "MIT" } } diff --git a/example/package.json b/notification_push/package.json similarity index 91% rename from example/package.json rename to notification_push/package.json index bd54083..38079cd 100644 --- a/example/package.json +++ b/notification_push/package.json @@ -10,9 +10,10 @@ "license": "ISC", "description": "", "dependencies": { + "@types/node": "^22.5.0", "notification-system": "file:../pkg" }, "devDependencies": { "typescript": "^5.5.4" } -} \ No newline at end of file +}