-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
194 lines (179 loc) ยท 6.37 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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
var fs = require("fs");
try {
const dataList = [];
const textFile = fs.readFileSync("subject.txt").toString();
const trimmedTxt = textFile
.replace(/[\x00-\x09\x0B-\x0C\x0E-\x1F\x7F-\x9F]/g, "")
.replace(/[\n\' ']/g, "");
const p1 = trimmedTxt.replaceAll("FL5", "FL\n");
const p2 = p1.replaceAll("์ผ๋ฐ1", "์ผ๋ฐ\n");
const p5 = p2.replaceAll("์ผ๋ฐ2", "์ผ๋ฐ\n");
const p3 = p5.replaceAll("์ผ๋ฐ3", "์ผ๋ฐ\n");
const p8 = p3.replaceAll("์ผ๋ฐ8", "์ผ๋ฐ\n");
const p4 = p8.replaceAll("์ผ๋ฐA", "์ผ๋ฐ\n");
const ptbl = p4.replaceAll("PtBLB", "PtBL\n");
const pmbl = ptbl.replaceAll("PmBLC", "PmBL\n");
const trimNsbp = pmbl.replaceAll(/ /g, "");
const parsedTxt1 = trimNsbp.replaceAll("-/-", "-");
// const parsedTxt2 = parsedTxt1.replaceAll("-", "๋น๋๋ฉด");
const subjectList = parsedTxt1.split("\n");
subjectList[0] = subjectList[0].replace(
"GWAMOK_NOGWAMOK_KNAMEHAKNYUNISU_NAMEHAKJUM#JUDAMDANG_GYOSU_NAMEJUNGWON#BUNHAPYOIL_GYOSIROOM_NAMEJOJIK_GBBUDAMDANG_GYOSU_NAMEGAESUL_JUNGONGGYOYANG_GBGANGJWA_TYPE_NMGANGJWA_TYPE",
""
);
const getClassTypeAndMajor = (string) => {
const classType = ["PtBL", "FL", "์ผ๋ฐ", "PmBL"];
if (string.includes("์ธ๋ฌธ์์ฐํ๋ถ")) {
for (type of classType) {
if (string.includes(type)) {
// console.log(string, string.indexOf("์ธ๋ฌธ์์ฐํ๋ถ") + 6, string.indexOf(type));
const liberalType = string.substring(
string.indexOf("์ธ๋ฌธ์์ฐํ๋ถ") + 6,
string.indexOf(type)
);
let temp = string.replace(liberalType, "");
let major = temp.replace(type, "");
return { major, liberalType, classType: type };
}
}
}
for (type of classType) {
if (string.includes(type)) {
const major = string.replace(type, "");
return { major, classType: type };
}
}
};
const getProfessorNameAndMaxStudent = (string) => {
try {
let profName = "";
let maxStudent = "";
for (char of string) {
if (isNaN(char) === true && maxStudent === "") {
profName += char;
}
if (isNaN(char) === false) {
maxStudent += char;
}
if (profName === "") {
profName = "-";
}
if (isNaN(char) === true && maxStudent !== "") {
return { profName, maxStudent };
}
}
} catch (err) {
console.log("๊ต์๋ช
, ์๊ฐ์ ์ ๋ณด ํ์ฑ ์๋ฌ");
}
};
const getClassHourAndClassroom = (string) => {
const weekDays = ["์)", "์)", "ํ)", "ํ)", "์)", "์)", "๋ชฉ)", "๋ชฉ)", "๊ธ)", "๊ธ)"];
console.log(string);
const A0000Index = string.indexOf("A0000");
const classHour = [];
let lastIndex = 0;
try {
for (weekday of weekDays) {
const weekIndex = string.indexOf(weekday);
if (weekIndex !== -1) {
lastIndex = weekIndex;
classHour.push(string.substring(weekIndex, weekIndex + 13));
string = string.replace(string.substring(weekIndex, weekIndex + 13), "");
}
}
let classroom = string.substring(lastIndex + 13, A0000Index);
if (classroom === "-") {
classroom = "๋ฏธ๋ฐฐ์ ";
}
if (classHour.length === 0) {
classHour.push("๋ฏธ๋ฐฐ์ "); // ๊ฐ์์๊ฐ ์ ๋ณด๊ฐ ์์ต๋๋ค.
return { classHour, classroom: "๋ฏธ๋ฐฐ์ " }; // ๊ฐ์์ค ์ ๋ณด๊ฐ ์์ต๋๋ค.
}
return { classHour, classroom };
} catch (err) {
console.log(err);
}
};
const getSubjectInfo = (subject) => {
//0427ํ๋๋ฌผ๋ฆฌํ๊ต์ 3์ ๋ณ๊ธธ50๊ธ)10:00โผ13:00๊ฐ์๋104A0000์ธ๋ฌธ์์ฐํ๋ถ์์ฐ๊ณผ๊ณผํ์ผ๋ฐ1
// 0776ํ๋ฅ ํต๊ณ๋ก 2์ ํ3๊น์ ์ฅ65์)09:00โผ10:30์)10:30โผ12:00๋น๋๋ฉดA0000์ํํธ์ผ๋ฐ
// subString1 = "์ํํธ์ผ๋ฐ" or "์ธ๋ฌธ์์ฐํ๋ถ์์ฐ๊ณผ๊ณผํ์ผ๋ฐ"
// subString2 = "๊น์ ์ฅ65์)09:00โผ10:30์)10:30โผ12:00๋น๋๋ฉดA0000์ํํธ์ผ๋ฐ"
const A0000Index = subject.indexOf("A0000");
const subString1 = subject.substring(A0000Index + 5, subject.length);
const { major, liberalType, classType } = getClassTypeAndMajor(subString1);
const subjectNumber = subject.substring(0, 4);
const subjectType = ["์ ์ ", "์ ํ", "์ผ์ ", "๊ต์ ", "๊ตํ"];
for (type of subjectType) {
let typeIndex = subject.indexOf(type);
if (typeIndex !== -1) {
if (isNaN(subject[typeIndex + 2])) {
continue;
}
const subString2 = subject.substring(typeIndex + 3, subject.length);
// typeIndex๋ฅผ ์ ํ๋ก ์๊ฐํ๋
/ ํ์ ์ด ๋์ค๋๋ฐ, ๊ต์๊ณผ๋ชฉ์ ์๊ฐํ๋
์ด ์๋ ๊ฒฝ์ฐ๊ฐ ๋๋ถ๋ถ์.
// ์ ์ง๋ณด์ ์, ์ด๋ฅผ ๊ณ ๋ คํด์ผ ํจ
const subjectName = isNaN(subject[typeIndex - 1])
? subject.substring(4, typeIndex)
: subject.substring(4, typeIndex - 1);
const subjectGrade = isNaN(subject[typeIndex - 1]) ? "-" : subject[typeIndex - 1];
const { profName, maxStudent } = getProfessorNameAndMaxStudent(subString2);
const { classHour, classroom } = getClassHourAndClassroom(subString2);
return {
major,
classType,
subjectNumber,
subjectType: type,
subjectGrade,
subjectName,
classHour,
classroom,
profName,
liberalType,
maxStudent,
subjectScore: subject[typeIndex + 2],
};
}
}
};
for (subject of subjectList) {
try {
const {
major,
classType,
subjectNumber,
subjectName,
subjectType,
subjectGrade,
classHour,
classroom,
liberalType,
profName,
maxStudent,
subjectScore,
} = getSubjectInfo(subject);
const data = {
id: Number(subjectNumber),
major,
classType,
subjectNumber,
subjectName,
subjectType,
subjectGrade,
classHour,
classroom,
liberalType,
profName,
maxStudent,
subjectScore,
};
dataList.push(data);
} catch (err) {
continue;
}
}
fs.writeFileSync("data.json", JSON.stringify(dataList));
} catch (err) {
console.log("์กด์ฌํ์ง ์๋ ํ์ผ์ด๊ฑฐ๋, ํ์ผ์ด ์์๋์์ต๋๋ค.");
console.log("ํ์ผ ์ด๋ฆ์ด subject.txt๊ฐ ๋ง๋์ง ํ์ธํด์ฃผ์ธ์.");
}