changeset 9:2348344480da

...
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Tue, 31 Mar 2020 15:43:14 +0900
parents 8a7a15dc3b9d
children b6a2d89b06e7
files cmd_donwload.go syllabus/getSyllabus.go
diffstat 2 files changed, 25 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/cmd_donwload.go	Tue Mar 31 15:28:25 2020 +0900
+++ b/cmd_donwload.go	Tue Mar 31 15:43:14 2020 +0900
@@ -28,13 +28,8 @@
 	arr3 := []string{"601495001", "600625001"}
 
 	lwps, err := dh.LecIDStoDonwlodSyllabus(ctx, arr3, outStream)
-	fmt.Println(lwps)
-	for _, lwp := range *lwps {
-		lec, err := dh.LecIDwFilePath2LectureStruct(&lwp)
-		if err != nil {
-			return err
-		}
-		fmt.Println(lec)
-	}
-	return err
+
+	return dh.DumpLectureWithPathJSON(lwps)
 }
+
+
--- a/syllabus/getSyllabus.go	Tue Mar 31 15:28:25 2020 +0900
+++ b/syllabus/getSyllabus.go	Tue Mar 31 15:43:14 2020 +0900
@@ -3,6 +3,7 @@
 import (
 	"bufio"
 	"context"
+	"encoding/json"
 	"fmt"
 	"io"
 	"net/http"
@@ -40,8 +41,8 @@
 }
 
 type LectureWPath struct {
-	ID   string
-	Path string
+	ID   string `json: "id"`
+	Path string `json: "path"`
 }
 
 //CreateGetSyllabus is constructor  and initialize from now time
@@ -234,3 +235,21 @@
 	}
 	return -1
 }
+
+func (g *GetSyllabus)DumpLectureWithPathJSON(lwps *[]LectureWPath) error {
+	bytes, err := json.Marshal(lwps)
+	if err != nil {
+		return err
+	}
+	fp :=  filepath.Join(g.outputdir, "dump.json")
+	file, err := os.Create(fp)
+	bw := bufio.NewWriter(file)
+	_, err = bw.Write(bytes)
+	if err != nil {
+		return err
+	}
+	bw.Flush()
+	file.Close()
+	return nil
+}
+