Skip to content

Commit

Permalink
update: 授業の表現を変更 Class -> Lecture
Browse files Browse the repository at this point in the history
add: 年度指定
  • Loading branch information
SIY1121 committed Sep 23, 2019
1 parent d6a7641 commit 317d0f3
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ enum Day {
}
```

### Class
### Lecture
```typescript
interface Class {
id: string
interface Lecture {
lectureID: string
name: string
details: {
module: Module
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twinte-parser",
"version": "1.0.2",
"version": "1.1.0",
"description": "Twinte内部で使用するために開発されたKdBパーサ",
"private": false,
"main": "dist/index.js",
Expand All @@ -15,29 +15,30 @@
"dist"
],
"bin": {
"twinte-parser" : "dist/app.js"
"twinte-parser": "dist/app.js"
},
"scripts": {
"run": "ts-node src/app.ts",
"prepare": "tsc",
"build": "tsc"
},
"devDependencies": {
"@types/cli-progress": "^1.8.1",
"@types/node": "^12.6.2",
"@typescript-eslint/eslint-plugin": "^1.11.0",
"@typescript-eslint/parser": "^1.11.0",
"eslint": "^6.0.1",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-prettier": "^3.1.0",
"prettier": "^1.18.2",
"ts-node": "^8.3.0",
"typescript": "^3.5.3",
"@types/cli-progress": "^1.8.1",
"@types/node": "^12.6.2"
"typescript": "^3.5.3"
},
"dependencies": {
"axios": "^0.19.0",
"cli-progress": "^2.1.1",
"colors": "^1.3.3",
"command-line-args": "^5.1.1",
"csv": "^5.1.1",
"iconv-lite": "^0.5.0"
}
Expand Down
7 changes: 6 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ import * as fs from 'fs'
import kdbGetter from './kdbDownloader'
import parse from './parser'
import * as colors from 'colors'
import * as commandLineArgs from 'command-line-args'

console.log('twinte-parser v0.0.1'.green.bold)

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

const main = async () => {
let csv: string

if (fs.existsSync('./kdb.csv')) {
console.log('i Cache file (kdb.csv) found.'.cyan)
csv = fs.readFileSync('./kdb.csv', 'utf-8')
} else {
csv = await kdbGetter()
csv = await kdbGetter(ops.year)
fs.writeFileSync('./kdb.csv', csv)
}
const classes = parse(csv)
Expand Down
6 changes: 4 additions & 2 deletions src/kdbDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ axios.interceptors.response.use(function(response) {
/**
* KDBからCSVを取得
*/
export default async (): Promise<string> => {
export default async (
year: number = new Date().getFullYear()
): Promise<string> => {
console.log('Downloading csv from kdb...'.cyan)
const params = {
pageId: 'SB0070',
action: 'downloadList',
hdnFy: '2019',
hdnFy: year,
hdnTermCode: '',
hdnDayCode: '',
hdnPeriodCode: '',
Expand Down
8 changes: 4 additions & 4 deletions src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Class, Day, Module } from './types'
import { Lecture, Day, Module } from './types'
import * as parseCsv from 'csv-parse/lib/sync'
import * as _cliProgress from 'cli-progress'

Expand Down Expand Up @@ -72,7 +72,7 @@ const analyzeModule = (str: string): Module[] => {
* CSVをパースする
* @param csv KDBからダウンロードしたcsv文字列
*/
export default (csv: string): Class[] => {
export default (csv: string): Lecture[] => {
//コンソールの進捗バー
const bar = new _cliProgress.Bar({}, _cliProgress.Presets.shades_classic)

Expand All @@ -85,8 +85,8 @@ export default (csv: string): Class[] => {
//////

const classes = rows.map(columns => {
const classData: Class = {
id: columns[0],
const classData: Lecture = {
lectureID: columns[0],
name: columns[1],
details: [],
instructor: columns[8]
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface Class {
id: string
export interface Lecture {
lectureID: string
name: string
details: {
module: Module
Expand Down
32 changes: 32 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ argparse@^1.0.7:
dependencies:
sprintf-js "~1.0.2"

array-back@^3.0.1:
version "3.1.0"
resolved "https://registry.yarnpkg.com/array-back/-/array-back-3.1.0.tgz#b8859d7a508871c9a7b2cf42f99428f65e96bfb0"
integrity sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q==

astral-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
Expand Down Expand Up @@ -185,6 +190,16 @@ colors@^1.1.2, colors@^1.3.3:
version "1.3.3"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.3.3.tgz#39e005d546afe01e01f9c4ca8fa50f686a01205d"

command-line-args@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/command-line-args/-/command-line-args-5.1.1.tgz#88e793e5bb3ceb30754a86863f0401ac92fd369a"
integrity sha512-hL/eG8lrll1Qy1ezvkant+trihbGnaKaeEjj6Scyr3DN+RC7iQ5Rz84IeLERfAWDGo0HBSNAakczwgCilDXnWg==
dependencies:
array-back "^3.0.1"
find-replace "^3.0.0"
lodash.camelcase "^4.3.0"
typical "^4.0.0"

[email protected]:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
Expand Down Expand Up @@ -392,6 +407,13 @@ file-entry-cache@^5.0.1:
dependencies:
flat-cache "^2.0.1"

find-replace@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/find-replace/-/find-replace-3.0.0.tgz#3e7e23d3b05167a76f770c9fbd5258b0def68c38"
integrity sha512-6Tb2myMioCAgv5kfvP5/PkZZ/ntTpVK39fHY7WkWBgvbeE+VHd/tZuZ4mrC+bxh4cfOZeYKVPaJIZtZXV7GNCQ==
dependencies:
array-back "^3.0.1"

flat-cache@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-2.0.1.tgz#5d296d6f04bda44a4630a301413bdbc2ec085ec0"
Expand Down Expand Up @@ -562,6 +584,11 @@ levn@^0.3.0, levn@~0.3.0:
prelude-ls "~1.1.2"
type-check "~0.3.2"

lodash.camelcase@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6"
integrity sha1-soqmKIorn8ZRA1x3EfZathkDMaY=

lodash.get@~4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
Expand Down Expand Up @@ -861,6 +888,11 @@ typescript@^3.5.3:
version "3.5.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.3.tgz#c830f657f93f1ea846819e929092f5fe5983e977"

typical@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/typical/-/typical-4.0.0.tgz#cbeaff3b9d7ae1e2bbfaf5a4e6f11eccfde94fc4"
integrity sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw==

uri-js@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.2.2.tgz#94c540e1ff772956e2299507c010aea6c8838eb0"
Expand Down

0 comments on commit 317d0f3

Please sign in to comment.