index.js
5.12 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
const config = require('./config')
const mongoose = require("mongoose");
const { range } = require("express/lib/request");
const xlsx = require("xlsx");
fs.readdirSync(testFolder).forEach(file => {
console.log(file);
});
const excelFile = xlsx.readFile("./GuideLine/컴퓨터공학과 권장이수 가이드라인.xlsx");
const sheetName = excelFile.SheetNames[0];
const firstSheet = excelFile.Sheets[sheetName];
const jsonData = xlsx.utils.sheet_to_json(firstSheet);
var first_first = [];
var first_second = [];
var second_first = [];
var second_second = [];
var third_first = [];
var third_second = [];
var fourth_first = [];
var fourth_second = [];
var new_list = [];
function jason_to_arry() {
for (var data in jsonData) {
first_first.push(jsonData[data]['1학년 1학기']);
first_second.push(jsonData[data]['1학년 2학기']);
second_first.push(jsonData[data]['2학년 1학기']);
second_second.push(jsonData[data]['2학년 2학기']);
third_first.push(jsonData[data]['3학년 1학기']);
third_second.push(jsonData[data]['3학년 2학기']);
fourth_first.push(jsonData[data]['4학년 1학기']);
fourth_second.push(jsonData[data]['4학년 2학기']);
}
}
// json -> array로 변경
function remove_null() {
first_first = first_first.filter(function (item) {
return item !== null && item !== undefined && item !== '';
});
first_second = first_second.filter(function (item) {
return item !== null && item !== undefined && item !== '';
});
second_first = second_first.filter(function (item) {
return item !== null && item !== undefined && item !== '';
});
second_second = second_second.filter(function (item) {
return item !== null && item !== undefined && item !== '';
});
third_first = third_first.filter(function (item) {
return item !== null && item !== undefined && item !== '';
});
third_second = third_second.filter(function (item) {
return item !== null && item !== undefined && item !== '';
});
fourth_first = fourth_first.filter(function (item) {
return item !== null && item !== undefined && item !== '';
});
fourth_second = fourth_second.filter(function (item) {
return item !== null && item !== undefined && item !== '';
});
new_list.push(first_first);
new_list.push(first_second)
new_list.push(second_first)
new_list.push(second_second);
new_list.push(third_first)
new_list.push(third_second);
new_list.push(fourth_first);
new_list.push(fourth_second);
}
// null 값 제거
jason_to_arry()
remove_null()
const connect = mongoose.connect(config.url,
{
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("DB : Succesfully Connected"))
.catch((err) => console.log(err.message));
var express = require('express');
var major_list = ["A07337", "A10628", "A07308", "A10627"];
const { Subinfo } = require('./models/model');
var request = require('request');
for (i in major_list) {
var options = {
'method': 'GET',
'url': `https://sugang.khu.ac.kr/core?attribute=lectListJson&lang=ko&loginYn=N&menu=1&p_major=${i}&p_year=2022&p_term=10&initYn=Y`,
'headers': {
'Cookie': 'JSESSIONID=aHGSkYnn7ZmXH5Wgx8So3tatw4J7LyR5g98tqYffSUU7qPhC7FFjOaemFCb8UgU5.amV1c19kb21haW4vV0hfU3VnYW5nMQ==; WMONID=R84FN19dbP4'
},
formData: {
'attribute': 'lectListJson',
'lang': 'ko',
'loginYn': 'N',
'menu': '1',
'p_major': 'A07308',
'p_year': '2022',
'p_term': '10',
'initYn': 'Y'
}
};
request(options, async function (error, response) {
if (error) throw new Error(error);
var jason = response.body
var json = JSON.parse(jason)
const data = {}
var x = 0, y = 0;
var z = '필수';
for (var i = 0; i < new_list.length; i++) {
if (i % 2 == 0) {
x++;
}
for (var j = 0; j < new_list[i].length; j++) {
if (new_list[i][j] == '선택') {
z = '선택';
continue;
}
if (i % 2 == 0) {
y = 1;
} else {
y = 2;
}
var subinfo = new Subinfo({
campus: "국제",
college: "소프트웨어융합대학",
department: "컴퓨터공학과",
grade: x + "학년" + y + "학기",
name: new_list[i][j],
choice: z
})
subinfo.save((err, result) => {
if (err) {
return err;
} else {
// console.log(result);
}
})
}
}
for (var i in json["rows"]) {
var obj = {};
obj['time'] = json["rows"][i]["timetable"];
obj['prof'] = json["rows"][i]["teach_na"];
obj['credit'] = json["rows"][i]["unit_num"];
obj['name'] = json["rows"][i]["subjt_name"];
await Subinfo.findOne({ name: obj['name'] }).then((sub) => {
if (sub) {
var body = {
prof: obj['prof'],
time: obj['time']
}
sub.credit = obj['credit']
sub.subject.push(body);
sub.save((err, result) => {
if (err) {
console.log(err)
} else if (result) {
console.log(result);
}
})
}
})
}
});
};