Skip to content

Commit b62679e

Browse files
committed
update: v2.0.1
1 parent 3db4a06 commit b62679e

File tree

6 files changed

+16
-28
lines changed

6 files changed

+16
-28
lines changed

package.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "twinte-parser",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "Twinte内部で使用するために開発されたKdBパーサ",
55
"private": false,
66
"main": "dist/index.js",
@@ -31,18 +31,16 @@
3131
"eslint-config-prettier": "^6.0.0",
3232
"eslint-plugin-prettier": "^3.1.0",
3333
"prettier": "^2.2.1",
34-
"typescript": "^4.1.3"
34+
"typescript": "^4.1.3",
35+
"ts-node": "^9.1.1"
3536
},
3637
"dependencies": {
3738
"axios": "^0.21.1",
3839
"axios-cookiejar-support": "^1.0.1",
39-
"cli-progress": "^2.1.1",
40-
"colors": "^1.3.3",
4140
"command-line-args": "^5.1.1",
4241
"csv": "^5.1.1",
4342
"iconv-lite": "^0.5.0",
4443
"tough-cookie": "^4.0.0",
45-
"ts-node": "^9.1.1",
4644
"xlsx": "^0.16.9"
4745
}
4846
}

src/app.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as fs from 'fs'
22
import downloadKdb from './kdbDownloader'
33
import parse from './parser'
4-
import * as colors from 'colors'
54
import * as commandLineArgs from 'command-line-args'
65

7-
console.log('twinte-parser v2.0.0')
6+
console.log('twinte-parser v2.0.1')
87

98
const ops = commandLineArgs([
109
{ name: 'year', alias: 'y', defaultValue: undefined },

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import parseKDB from './parser'
2-
import downloadKDB from './kdbDownloader'
2+
import downloadKDB, { NoCoursesFoundError } from './kdbDownloader'
33
export default parseKDB
4-
export { downloadKDB, parseKDB }
4+
export { downloadKDB, parseKDB, NoCoursesFoundError }
55
export * from './types'

src/kdbDownloader.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import _axios from 'axios'
22
import _axiosCookiejarSupport from 'axios-cookiejar-support'
33
import * as iconv from 'iconv-lite'
4-
import * as fs from 'fs'
5-
import * as colors from 'colors'
64
import * as assert from 'assert'
75

86
export class NoCoursesFoundError extends Error {
@@ -32,8 +30,11 @@ const postBody = (obj: any) => {
3230
return urlParams
3331
}
3432

35-
const extractFlowExecutionKey = (html: string) =>
36-
html.match(/&_flowExecutionKey=(.*?)"/m)[1]
33+
const extractFlowExecutionKey = (html: string) => {
34+
const key = html.match(/&_flowExecutionKey=(.*?)"/m)[1]
35+
assert(key)
36+
return key
37+
}
3738

3839
const grantSession = async (): Promise<string> => {
3940
const res = await axios.get<Buffer>('https://kdb.tsukuba.ac.jp/')
@@ -109,7 +110,7 @@ const downloadExcel = async (
109110
}
110111

111112
/**
112-
* KDBからCSVを取得
113+
* KDBからExcelファイルを取得
113114
*/
114115
export default async (
115116
year: number = new Date().getFullYear()

src/parser.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Course, Day, Module } from './types'
22
import * as parseCsv from 'csv-parse/lib/sync'
33
import * as _cliProgress from 'cli-progress'
44
import { read as readXLSX, utils } from 'xlsx'
5+
import * as assert from 'assert'
56

67
/**
78
* '月1,2' 等の曜日と時限の文字列を解析し、分解する
@@ -137,6 +138,7 @@ const analyzeRow = (columns: string[]) => {
137138
Math.max(periodArray.length, roomArray.length)
138139
)
139140

141+
// データが壊れている可能性がある場合
140142
if (
141143
!(
142144
(moduleArray.length === count || moduleArray.length === 1) &&
@@ -174,7 +176,7 @@ const analyzeRow = (columns: string[]) => {
174176
*/
175177
export default (data: Buffer): Course[] => {
176178
const sheet = readXLSX(data).Sheets['開設科目一覧']
177-
179+
assert(sheet)
178180
const courses: Course[] = []
179181

180182
for (let r = 5; ; r++) {

yarn.lock

+1-13
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,6 @@ cli-cursor@^2.1.0:
193193
dependencies:
194194
restore-cursor "^2.0.0"
195195

196-
cli-progress@^2.1.1:
197-
version "2.1.1"
198-
resolved "https://registry.yarnpkg.com/cli-progress/-/cli-progress-2.1.1.tgz#45ee1b143487c19043a3262131ccb4676f87f032"
199-
dependencies:
200-
colors "^1.1.2"
201-
string-width "^2.1.1"
202-
203196
cli-width@^2.0.0:
204197
version "2.2.0"
205198
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.0.tgz#ff19ede8a9a5e579324147b0c11f0fbcbabed639"
@@ -227,10 +220,6 @@ [email protected]:
227220
version "1.1.3"
228221
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
229222

230-
colors@^1.1.2, colors@^1.3.3:
231-
version "1.3.3"
232-
resolved "https://registry.yarnpkg.com/colors/-/colors-1.3.3.tgz#39e005d546afe01e01f9c4ca8fa50f686a01205d"
233-
234223
command-line-args@^5.1.1:
235224
version "5.1.1"
236225
resolved "https://registry.yarnpkg.com/command-line-args/-/command-line-args-5.1.1.tgz#88e793e5bb3ceb30754a86863f0401ac92fd369a"
@@ -688,7 +677,6 @@ lodash@^4.17.11, lodash@^4.17.12:
688677
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52"
689678
integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==
690679

691-
692680
make-error@^1.1.1:
693681
version "1.3.6"
694682
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
@@ -915,7 +903,7 @@ stream-transform@^1.0.8:
915903
version "1.0.8"
916904
resolved "https://registry.yarnpkg.com/stream-transform/-/stream-transform-1.0.8.tgz#54f721122d310eca855a16c97939881ab5bbb76c"
917905

918-
string-width@^2.1.0, string-width@^2.1.1:
906+
string-width@^2.1.0:
919907
version "2.1.1"
920908
resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e"
921909
dependencies:

0 commit comments

Comments
 (0)