์ ๊ตญ ์ด, ๋ฑ, ๊ณ ๋ฑํ๊ต ๋ฐ ๋ณ์ค์ ์น์ ๊ธ์, ํ์ฌ์ผ์ ํ์ฑ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
๋ณธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ Node.js
ํ๊ฒฝ์์ ์ฌ์ฉํ ์ ์๋ ๊ธ์ API
+ ํ์ฌ์ผ์ API
ํตํฉ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์
๋๋ค.
์ ๊ตญ ๊ต์ก์ฒญ ํ์ ์๋น์ค ํ์ด์ง(stu.xxx.go.kr)๋ฅผ ํ์ฑํ์ฌ ์ด๋ฒ ๋ฌ ํ์ฌ์ผ์ ๊ณผ ๊ธ์ ์ ๋ณด๋ฅผ JSON ๋ฐ์ดํฐ๋ก ์ ๊ณตํฉ๋๋ค.
- Promise๋ฅผ ์ ๊ทน ์ง์ํ์ฌ ๋น๋๊ธฐ ํจ์์์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
NPM ์ ์ฅ์๋ฅผ ํตํด ๋ค์ด๋ก๋ ๋ฐ์ ์ ์์ผ๋ฉฐ ๋ณ๋ค๋ฅธ ์์ ์์ด ๋ฐ๋ก ์ฌ์ฉ ๊ฐ๋ฅํฉ๋๋ค.
npm i node-school-kr
์๋ ๋ช
๋ น์ด๋ฅผ ์
๋ ฅํ์ฌ ๋ฏธ๋ฆฌ ์์ฑ๋ ์์ ์ฝ๋๋ฅผ ์คํํด๋ณผ ์ ์์ต๋๋ค.
sample/sample.js
์ฝ๋๊ฐ ์คํ๋๋ฉฐ, ํ๊ต๋ ๊ด๋ช
๊ฒฝ์ํ๊ณ๊ณ ๋ฑํ๊ต
๊ธฐ์ค์ผ๋ก ์คํ๋ฉ๋๋ค.
npm test
node-school-kr
๋ชจ๋์ ๋ถ๋ฌ์จ ํ ์ธ์คํด์ค๋ฅผ ์์ฑํฉ๋๋ค.
์์ฑ ํ ๋ฐ๋์ init()
๋ฅผ ํธ์ถํ์ฌ ๋ฐ์ดํฐ๋ฅผ ์กฐํํ ํ๊ต๋ก ์ด๊ธฐํํฉ๋๋ค.
- init() ํธ์ถ ์์ด ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์ฌ ๊ฒฝ์ฐ Error๊ฐ Throw ๋ฉ๋๋ค.
const School = require('node-school-kr')
const school = new School()
/*
* @param type: ํ๊ต ์ ํ(์ด, ์ค, ๊ณ , ๋ณ์ค์ ์น์)
* @param region: ๊ต์ก์ฒญ ๊ดํ ์ง์ญ
* @param schoolCode: ํ๊ต ๊ณ ์ ์ฝ๋
*/
school.init(/* Type */, /* Region */, /* SchoolCode */)
ํ๊ต ์ข
๋ฅ๋ School.Type
์์ ์ ํํ ์ ์์ต๋๋ค.
const School = require('node-school-kr')
const school = new School()
/* 4 */
console.log(School.Type.HIGH)
// School.Type.KEY
์ ํ | Key | Value |
---|---|---|
๋ณ์ค์ ์น์ | KINDERGARTEN |
1 |
์ด๋ฑํ๊ต | ELEMENTARY |
2 |
์คํ๊ต | MIDDLE |
3 |
๊ณ ๋ฑํ๊ต | HIGH |
4 |
์ง์ญ์ ์์ฑํ School.Region
์์ ์ ํํ ์ ์์ต๋๋ค.
const School = require('node-school-kr')
const school = new School()
/* stu.sen.go.kr */
console.log(School.Region.SEOUL)
// School.Region.KEY
์ง์ญ | Key | Value |
---|---|---|
์์ธ | SEOUL |
stu.sen.go.kr |
์ธ์ฒ | INCHEON |
stu.ice.go.kr |
๋ถ์ฐ | BUSAN |
stu.pen.go.kr |
๊ด์ฃผ | GWANGJU |
stu.gen.go.kr |
๋์ | DAEJEON |
stu.dge.go.kr |
๋๊ตฌ | DEAGU |
stu.dge.go.kr |
์ธ์ข | SEJONG |
stu.sje.go.kr |
์ธ์ฐ | ULSAN |
stu.use.go.kr |
๊ฒฝ๊ธฐ | GYEONGGI |
stu.goe.go.kr |
๊ฐ์ | KANGWON |
stu.kwe.go.kr |
์ถฉ๋ถ | CHUNGBUK |
stu.cbe.go.kr |
์ถฉ๋จ | CHUNGNAM |
stu.cne.go.kr |
๊ฒฝ๋ถ | GYEONGBUK |
stu.gbe.go.kr |
๊ฒฝ๋จ | GYEONGNAM |
stu.gne.go.kr |
์ ๋ถ | JEONBUK |
stu.jbe.go.kr |
์ ๋จ | JEONNAM |
stu.jne.go.kr |
์ ์ฃผ | JEJU |
stu.jje.go.kr |
ํ๊ต ๊ณ ์ ์ฝ๋๋ ์ฌ๊ธฐ์์ ํ๊ต๋ช
์ผ๋ก ๊ฒ์ํ ์ ์์ต๋๋ค.
ํ๊ต ์ฝ๋๋ X000000000
ํ์์ 10์๋ฆฌ ๋ฌธ์์ด์
๋๋ค.
โป ์๋ ์์ ๋ ๊ฒฝ๊ธฐ๋์ ๊ด๋ช
๊ฒฝ์ํ๊ณ๊ณ ๋ฑํ๊ต
๋ฅผ ๊ธฐ์ค์ผ๋ก ์งํ๋ฉ๋๋ค.
- Promise๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ์ฌ ๋น๋๊ธฐ ํจ์(Async/Await)์์ ์ฌ์ฉ ๊ฐ๋ฅ
- ์ด๊ธฐํ(init) ์์ ์์ด ๋ฐ์ดํฐ ๋ถ๋ฌ์ฌ ๊ฒฝ์ฐ Error๊ฐ Throw ๋ฉ๋๋ค.
- ํ์ฑ ๋์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ ๊ฒฝ์ฐ ๋ฉ์์ง ์ถ๋ ฅ ๋ฐ ๋น์ด์๋ ๊ฐ์ฒด ๋ฐํ
{}
- init() ๋ ์์ฑ๋ ์ธ์คํด์ค๋น
1ํ๋ง
๊ฐ๋ฅ - reset() ์ ํตํด ๋ค๋ฅธ ํ๊ต ์ ๋ณด๋ก
์ฌ์ค์
๊ฐ๋ฅ
const School = require('node-school-kr')
const school = new School()
school.init(School.Type.HIGH, School.Region.GYEONGGI, 'J100000488')
const School = require('node-school-kr')
const school = new School()
/* ๊ฒฝ๊ธฐ๋ ๊ด๋ช
์์ ๊ด๋ช
๊ณ ๋ฑํ๊ต๋ก init() */
school.init(School.Type.HIGH, School.Region.GYEONGGI, 'J100000482')
/* ๊ฒฝ๊ธฐ๋ ๊ด๋ช
์์ ๊ด๋ช
๊ฒฝ์ํ๊ณ๊ณ ๋ฑํ๊ต๋ก ์ฌ์ค์ ํ๋ ์ฝ๋ */
school.reset(School.Type.HIGH, School.Region.GYEONGGI, 'J100000488')
๊ธ์ / ํ์ฌ์ผ์ ์ ๋ณด๋ ํ๊ฒ URL์ ์ ์ํ์ฌ ๋ฐ์ดํฐ๋ฅผ ํ์ฑํฉ๋๋ค.
const School = require('node-school-kr')
const school = new School()
school.init(School.Type.HIGH, School.Region.GYEONGGI, 'J100000488')
// ๊ธ์, ํ์ฌ์ผ์ ๋ฐ์ดํฐ ํ์ฑ ํ๊ฒ ํ์ด์ง URL
console.log(school.getTargetURL('meal'))
console.log(school.getTargetURL('calendar'))
/*
https://stu.goe.go.kr/sts_sci_md00_001.do?schulCode=J100000488&schulCrseScCode=4&schulKndScCode=4
https://stu.goe.go.kr/sts_sci_sf01_001.do?schulCode=J100000488&schulCrseScCode=4&schulKndScCode=4
*/
const School = require('node-school-kr')
const school = new School()
school.init(School.Type.HIGH, School.Region.GYEONGGI, 'J100000488')
const sampleAsync = async function() {
const meal = await school.getMeal()
const calendar = await school.getCalendar()
// ์ค๋ ๋ ์ง
console.log(`${meal.month}์ ${meal.day}์ผ`)
// ์ค๋ ๊ธ์ ์ ๋ณด
console.log(meal.today)
// ์ด๋ฒ ๋ฌ ๊ธ์ ์ ๋ณด
console.log(meal)
// ์ด๋ฒ ๋ฌ ํ์ฌ์ผ์
console.log(calendar)
}
sampleAsync()
const School = require('node-school-kr')
const school = new School()
school.init(School.Type.HIGH, School.Region.GYEONGGI, 'J100000488')
const samplePromise = function() {
school.getMeal().then(meal => {
// ์ค๋ ๋ ์ง
console.log(`${meal.month}์ ${meal.day}์ผ`)
// ์ค๋ ๊ธ์ ์ ๋ณด
console.log(meal.today)
// ์ด๋ฒ ๋ฌ ๊ธ์ ์ ๋ณด
console.log(meal)
return school.getCalendar()
}).then(calendar) => {
// ์ด๋ฒ ๋ฌ ํ์ฌ์ผ์
console.log(calendar)
})
}
samplePromise()
getMeal
๋ฐํ ๋ฐ์ดํฐ ํ์์ ์๋์ ๊ฐ์ต๋๋ค.
Key | Value | ๋น๊ณ |
---|---|---|
1 ~ 31 | ํด๋น ๋ ์ง์ ๊ธ์ | ๊ธ์์ด ์๋ ๊ฒฝ์ฐ ๋น ๋ฌธ์์ด |
month | ์ด๋ฒ ๋ฌ | |
day | ์ค๋ ๋ ์ง | |
today | ์ค๋ ๊ธ์ |
{
'1': '[์ค์]\n๋ฐ์ํ๋ฏธ๋ฐฅ\n๋ฏธ์ญ๊ตญ5.6.9....', // ์ด๋ฒ๋ฌ 1์ผ ๋ฉ๋ด
'2': '[์ค์]\n์ผ๊ฐ์ด๋์ฅ๋ฌด์นจ5.6.\n์นผ์์ฐน์....', // ์ด๋ฒ๋ฌ 2์ผ ๋ฉ๋ด
'3': '[์ค์]\nํฌ์๋ฐํ์คํ(์ฃผ์)1.2.5.6.9.13.15.\n....', // ์ด๋ฒ๋ฌ 3์ผ ๋ฉ๋ด
'4': '', // ๊ธ์์ด ์์ ๊ฒฝ์ฐ ๋น ๋ฌธ์์ด
'5': '',
...
'month': 5, // ์ด๋ฒ ๋ฌ
'day': 3, // ์ค๋ ๋ ์ง
'today': '[์ค์]\nํฌ์๋ฐํ์คํ(์ฃผ์)1.2.5.6.9.13.15.\n....' // ์ค๋ ๋ฉ๋ด
}
getCalendar
๋ฐํ ๋ฐ์ดํฐ ํ์์ ์๋์ ๊ฐ์ต๋๋ค.
Key | Value | ๋น๊ณ |
---|---|---|
1 ~ 31 | ํด๋น ๋ ์ง์ ์ผ์ | ์ผ์ ์ด ์๋ ๊ฒฝ์ฐ ๋น ๋ฌธ์์ด |
month | ์ด๋ฒ ๋ฌ |
{
'1': '', // ์ด๋ฒ ๋ฌ 1์ผ์ ์ผ์
'2': '', // ์ผ์ ์ด ์์ ๊ฒฝ์ฐ ๋น ๋ฌธ์์ด
'3': '',
'4': '๊ฐ๊ต๊ธฐ๋
์ผ', // 4์ผ ์ผ์
'5': '',
'6': '',
'7': '๋์ฒด๊ณตํด์ผ',
...
'month': 5 // ์ด๋ฒ ๋ฌ
}
๊ต์ก์ฒญ ํํ์ด์ง์ ๋ฆฌ๋ด์ผ ๋ฑ์ ๋ฌธ์ ๋ก ํ์ฑ์ด ๋ถ๊ฐ๋ฅ ํ ์ ์์ต๋๋ค. ์ด์๋ฅผ ๋จ๊ฒจ์ฃผ์๋ฉด ์ต๋ํ ๋น ๋ฅด๊ฒ ์์ ํ์ฌ ๋ฐ์ํ๋๋ก ํ๊ฒ ์ต๋๋ค.
2.0.0
- โป ๊ธฐ์กด ๋ฒ์ ๊ณผ
ํธํ๋์ง ์์ต๋๋ค.
(์๋ ๋ณ๊ฒฝ์ฌํญ์ ํ์ธ ํด์ฃผ์ธ์) - Type, Region ํ๋กํผํฐ ๊ฐ์ Symbol ๊ธฐ๋ฐ์ผ๋ก ๊ตฌํ
- ์๋ฌ ๋ฐ์ ์ํฉ ์ถ๊ฐ ๋ฐ ๊ธฐ์กด ์๋ฌ ๋ฉ์์ง ์์
- getNotice ๋ฉ์๋๋ช
๋ณ๊ฒฝ ->
getCalendar
- getTargetURL ๋ฉ์๋ ์ถ๊ฐ (ํ์ฑํ ํ๊ฒ URL์ ๋ฐํํฉ๋๋ค, ์ฐธ๊ณ )
- ์์ ๋ฐ README ๋ด์ฉ ์์ ์ฌํญ์ ๋ง๊ฒ ์ ๋ฐ์ดํธ / ๋ด์ฉ ์ถ๊ฐ
- ์ฝ๋ ์ฃผ์ ์ ๋ฐ์ดํธ
- โป ๊ธฐ์กด ๋ฒ์ ๊ณผ
1.0.1
- NPM ์ ์ฅ์์ ์ด๋ฆ ๋์ผํ๊ฒ Git ์ ์ฅ์ ์ด๋ฆ ๋ณ๊ฒฝ (์ด๋ฏธ ์ฌ์ฉ์ค์ธ ์ด๋ฆ)
- node-school -> node-school-kr
- README ๋ฌธ์ ๋ด์ฉ ์์
- ์๋ฌ ๋ฉ์์ง ๊ตฌ๋ถ ๋ฌธ์ ์ถ๊ฐ (๊ธ์ ํ์ฑ ์๋ฌ์ธ์ง ํ์ฌ์ผ์ ํ์ฑ ์๋ฌ์ธ์ง ๊ตฌ๋ถ)
- NPM ์ ์ฅ์์ ์ด๋ฆ ๋์ผํ๊ฒ Git ์ ์ฅ์ ์ด๋ฆ ๋ณ๊ฒฝ (์ด๋ฏธ ์ฌ์ฉ์ค์ธ ์ด๋ฆ)
1.0.0
- ์ฒซ ๋ฒ์งธ ๋ฆด๋ฆฌ์ฆ!
๋ณธ ํ๋ก์ ํธ๋ School API๋ฅผ ์ฐธ๊ณ ํ์ฌ Node.js ํ๊ฒฝ์์ ์ฌ์ฉํ ์ ์๋๋ก ์๋ก ํฌํ ํ ํ๋ก์ ํธ์ ๋๋ค.