changeset 0:7f5ee6f5e801 default tip

...
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Mon, 20 Apr 2020 13:51:39 +0900
parents
children
files .hgignore download.go go.mod
diffstat 3 files changed, 140 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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
--- /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 = "</span>"                                                  // 後ろの方
+
+// 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
+}
--- /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