# HG changeset patch # User anatofuz # Date 1585568442 -32400 # Node ID 5191dd198bf48c63679fbd09794b888989130968 add convertSyllabus method diff -r 000000000000 -r 5191dd198bf4 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Mon Mar 30 20:40:42 2020 +0900 @@ -0,0 +1,27 @@ +syntax:glob + +# Created by https://www.gitignore.io/api/go +# Edit at https://www.gitignore.io/?templates=go + +### Go ### +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +### Go Patch ### +/vendor/ +/Godeps/ + +# End of https://www.gitignore.io/api/go diff -r 000000000000 -r 5191dd198bf4 go.mod --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/go.mod Mon Mar 30 20:40:42 2020 +0900 @@ -0,0 +1,5 @@ +module ie.u-ryukyu.ac.jp/hg/y19/index.cgi/home/hg/y19/k198584/Tools/lectable + +go 1.14 + +require github.com/pkg/errors v0.9.1 diff -r 000000000000 -r 5191dd198bf4 lectable/getSyllabus.go --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lectable/getSyllabus.go Mon Mar 30 20:40:42 2020 +0900 @@ -0,0 +1,92 @@ +package lectable + +import ( + "bufio" + "os" + "strings" + + "github.com/pkg/errors" +) + +const ( + monday int = iota + tuesday + wednesday + thursday + friday +) + +type lectureDay struct { + dayOfWeek int + period int + lastPeriod int + hasLast bool +} + +type lecture struct { + id string + name string + day *lectureDay + teacher string +} + +func getSyllabus(lectureID, filePath string) (*lecture, error) { + file, err := os.Open(filePath) + + if err != nil { + return nil, errors.Wrap(err, "failed open html file") + } + scanner := bufio.NewScanner(file) + + var lec lecture + lec.id = lectureID + + dayPeriodID := "ctl00_phContents_Detail_lbl_day_period\">" + lectureNameID := "ctl00_phContents_Detail_lbl_lbl_lct_name_double\">" + teacherNameID := "ctl00_phContents_Detail_lbl_syl_staff_name_double\">" + + endSpan := "" + + for scanner.Scan() { + line := scanner.Text() + + // day Period + if i := strings.Index(line, dayPeriodID); i >= 0 { + if j := strings.Index(line, endSpan); j >= 0 { + i += len(dayPeriodID) + day := line[i:j] + if k := strings.Index(day, "~"); k >= 0 { + lec.day.hasLast = true + } else { + lec.day.hasLast = false + } + } + continue + } + + // lecture name + if i := strings.Index(line, lectureNameID); i >= 0 { + if j := strings.Index(line, endSpan); j >= 0 { + i += len(lectureNameID) + lec.name = line[i:j] + } + continue + } + + //teacher name + if i := strings.Index(line, teacherNameID); i >= 0 { + if j := strings.Index(line, endSpan); j >= 0 { + i += len(teacherNameID) + lec.teacher = line[i:j] + } + break + } + } + + file.Close() + return &lec, nil +} + +func kanjiday2int(kanjiDay string) (int, error) { + return 0, nil +}