-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
130 lines (114 loc) · 3.56 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const axios = require("axios");
const cheerio = require("cheerio");
const express = require("express");
const app = express();
// cors policy
app.use((req, res, next) => {
res.header({ "Access-Control-Allow-Origin": "*" });
next();
});
// homepage
app.get("/", (req, res) => {
res.status(200).send({
active: true,
creator: "Subhranshu Choudhury",
});
});
// web status (soa website)
app.get("/web-status/", async (req, res) => {
try {
const response = await axios.get(
"https://www.soa.ac.in/general-notifications"
);
res.send({ status: response.status, statusText: response.statusText });
} catch (error) {
res.status(500).send({ error: true, message: error });
}
});
// Iter General Notification Section
app.get("/gn", async (req, res) => {
const url = "https://www.soa.ac.in/general-notifications";
try {
const { data } = await axios.get(url);
const $ = cheerio.load(data);
const GeneralNotifications = [];
for (let index = 1; index < 21; index++) {
const notification = { event: "", s_date: "", eventLink: "" };
notification.event = $(
`.article-index-${index} a.BlogList-item-title`
).text();
notification.s_date = $(`.article-index-${index} time`).text();
notification.eventLink =
"https://www.soa.ac.in" +
$(`.article-index-${index} a.BlogList-item-title`).attr("href");
GeneralNotifications.push(notification);
}
res.send(GeneralNotifications);
} catch (err) {
res.status(500).send({
error: true,
message: err,
});
}
});
// Iter student notice section
app.get("/sn", async (req, res) => {
const url = "https://www.soa.ac.in/iter-student-notice";
try {
const { data } = await axios.get(url);
const $ = cheerio.load(data);
const GeneralNotifications = [];
for (let index = 1; index < 21; index++) {
const notification = { event: "", s_date: "", eventLink: "" };
notification.event = $(
`.article-index-${index} a.BlogList-item-title`
).text();
notification.s_date = $(`.article-index-${index} time`).text();
notification.eventLink =
"https://www.soa.ac.in" +
$(`.article-index-${index} a.BlogList-item-title`).attr("href");
GeneralNotifications.push(notification);
}
res.send(GeneralNotifications);
} catch (err) {
res.status(500).send({
error: true,
message: err,
});
}
});
app.get("/en", async (req, res) => {
const url = "https://www.soa.ac.in/iter-exam-notice";
try {
const { data } = await axios.get(url);
const $ = cheerio.load(data);
const GeneralNotifications = [];
for (let index = 1; index < 21; index++) {
const notification = { event: "", s_date: "", eventLink: "" };
notification.event = $(
`.article-index-${index} a.BlogList-item-title`
).text();
notification.s_date = $(`.article-index-${index} time`).text();
notification.eventLink =
"https://www.soa.ac.in" +
$(`.article-index-${index} a.BlogList-item-title`).attr("href");
GeneralNotifications.push(notification);
}
res.send(GeneralNotifications);
} catch (err) {
res.status(500).send({
error: true,
message: err,
});
}
});
// * for any url
app.get("*", (req, res) => {
res.status(404).send({
message: "wrong route",
});
});
const PORT = process.env.PORT || 4000;
app.listen(PORT, () => {
console.log("Server running on Port ", PORT);
});