# HG changeset patch # User anatofuz # Date 1587358299 -32400 # Node ID 7f5ee6f5e801ca1bc6a0f834e7d18cd6fcc78f5b ... diff -r 000000000000 -r 7f5ee6f5e801 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Mon Apr 20 13:51:39 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 7f5ee6f5e801 download.go --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/download.go Mon Apr 20 13:51:39 2020 +0900 @@ -0,0 +1,110 @@ +package syllabusdiff + +import ( + "fmt" + "io" + "net/http" + "net/url" + "os" + "path" + "path/filepath" + "strconv" + "strings" + "time" + + "github.com/pkg/errors" +) + +type season struct { + year int + term string + outputDir string + preOutputDir string +} + +func createSeaspn() *season { + nowSeason := new(season) + tm := time.Now() + year := tm.Year() + var term string + if tm.Month() < 7 { + term = "previous" + } else { + term = "latter" + } + nowSeason.term = term + nowSeason.year = year + yearString := strconv.Itoa(year) + nowSeason.outputDir = filepath.Join(yearString, term) + nowSeason.preOutputDir = filepath.Join("prev", yearString, term) + return nowSeason +} + +type lect struct { + name string + id string + url string +} + +var endpoint = "https://tiglon.jim.u-ryukyu.ac.jp" +var lectureNameID = "ctl00_phContents_Detail_lbl_lbl_lct_name_double\">" // 講義名があるID +var endSpan = "" // 後ろの方 + +// idいれるとダウンロードしてくれる +func (ss *season) downloadSyllabusFromID(lectureID string) (string, error) { + var strBuilder strings.Builder + strBuilder.WriteString(lectureID) + strBuilder.WriteString(".html") + + outputPath := filepath.Join(ss.outputDir, strBuilder.String()) + + if _, err := os.Stat(outputPath); err == nil { + fmt.Printf("already download %s.html\n", lectureID) + return outputPath, nil + } + + file, err := os.Create(outputPath) + defer file.Close() + + if err != nil { + return "", errors.Wrap(err, "failed create html...") + } + + strBuilder.Reset() + + u, err := url.Parse(endpoint) + if err != nil { + return "", err + } + + u.Path = path.Join(u.Path, "portal", "Public", "Syllabus", "SyllabusSearchStart.aspx") + q := u.Query() + q.Set("lct_year", strconv.Itoa(ss.year)) + q.Set("lct_cd", lectureID) + q.Set("je_cd", "1") + u.RawQuery = q.Encode() + + fmt.Println(u.String()) + res, err := http.Get(u.String()) + defer res.Body.Close() + + if err != nil { + return "", errors.Wrap(err, "failed download html") + } + + _, err = io.Copy(file, res.Body) + if err != nil { + return "", errors.Wrap(err, "failed download html") + } + + return outputPath, nil +} + +func downloadWithDiff(url string) error { + return nil +} + +func creatLect(id, lectURL string) (*lect, error) { + lec := &lect{id: id, url: lectURL} + return lec, nil +} diff -r 000000000000 -r 7f5ee6f5e801 go.mod --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/go.mod Mon Apr 20 13:51:39 2020 +0900 @@ -0,0 +1,3 @@ +module www.cr.ie.u-ryukyu.ac.jp/hg/Members/anatofuz/syllabusDiff + +go 1.14