Mercurial > hg > Members > anatofuz > lectable
view lectable/getSyllabus.go @ 0:5191dd198bf4
add convertSyllabus method
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 30 Mar 2020 20:40:42 +0900 |
parents | |
children | 1f47625c6948 |
line wrap: on
line source
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 := "</span>" 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 }