Mercurial > hg > Members > anatofuz > lectable
comparison syllabus/getSyllabus.go @ 3:e4088b031eba
add cmd
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 31 Mar 2020 12:17:52 +0900 |
parents | dccd0dd6cfbc |
children | a0d23f38344d |
comparison
equal
deleted
inserted
replaced
2:dccd0dd6cfbc | 3:e4088b031eba |
---|---|
2 | 2 |
3 import ( | 3 import ( |
4 "bufio" | 4 "bufio" |
5 "io" | 5 "io" |
6 "net/http" | 6 "net/http" |
7 "net/url" | |
7 "os" | 8 "os" |
9 "path" | |
10 "path/filepath" | |
8 "strconv" | 11 "strconv" |
9 "strings" | 12 "strings" |
10 "time" | 13 "time" |
11 | 14 |
12 "github.com/pkg/errors" | 15 "github.com/pkg/errors" |
44 | 47 |
45 //CreateGetSyllabus is constructor and initialize from now time | 48 //CreateGetSyllabus is constructor and initialize from now time |
46 func CreateGetSyllabus() *GetSyllabus { | 49 func CreateGetSyllabus() *GetSyllabus { |
47 var gs GetSyllabus | 50 var gs GetSyllabus |
48 tm := time.Now() | 51 tm := time.Now() |
49 gs.year = tm.Year() | 52 //gs.year = tm.Year() |
53 gs.year = 2019 | |
50 if tm.Month() < 7 { | 54 if tm.Month() < 7 { |
51 gs.term = "previous" | 55 gs.term = "previous" |
52 } else { | 56 } else { |
53 gs.term = "latter" | 57 gs.term = "latter" |
54 } | 58 } |
55 var b strings.Builder | 59 gs.term = "previous" |
56 b.WriteString(strconv.Itoa(gs.year)) | 60 |
57 b.WriteString("/") | 61 gs.outputdir = filepath.Join(strconv.Itoa(gs.year), gs.term) |
58 b.WriteString(gs.term) | |
59 gs.outputdir = b.String() | |
60 return &gs | 62 return &gs |
61 } | 63 } |
62 | 64 |
63 var dayPeriodID = "ctl00_phContents_Detail_lbl_day_period\">" | 65 var dayPeriodID = "ctl00_phContents_Detail_lbl_day_period\">" |
64 var lectureNameID = "ctl00_phContents_Detail_lbl_lbl_lct_name_double\">" | 66 var lectureNameID = "ctl00_phContents_Detail_lbl_lbl_lct_name_double\">" |
65 var teacherNameID = "ctl00_phContents_Detail_lbl_syl_staff_name_double\">" | 67 var teacherNameID = "ctl00_phContents_Detail_lbl_syl_staff_name_double\">" |
66 var endSpan = "</span>" | 68 var endSpan = "</span>" |
67 var dayOfWeeklen = len("月") | 69 var dayOfWeeklen = len("月") |
68 | 70 |
71 //"https://tiglon.jim.u-ryukyu.ac.jp/portal/Public/Syllabus/SyllabusSearchStart.aspx?lct_year=2019&lct_cd=610004071&je_cd=1" | |
72 var endpoint = "https://tiglon.jim.u-ryukyu.ac.jp" | |
73 | |
69 //LecIDtoDownloadSyllabus is download from lecture ID | 74 //LecIDtoDownloadSyllabus is download from lecture ID |
70 func (g *GetSyllabus) LecIDtoDownloadSyllabus(lectureID string) error { | 75 func (g *GetSyllabus) LecIDtoDownloadSyllabus(lectureID string) error { |
71 var strBuilder strings.Builder | 76 var strBuilder strings.Builder |
72 strBuilder.WriteString(g.outputdir) | |
73 strBuilder.WriteString("/") | |
74 strBuilder.WriteString(lectureID) | 77 strBuilder.WriteString(lectureID) |
75 strBuilder.WriteString(".html") | 78 strBuilder.WriteString(".html") |
79 | |
80 putputPath := filepath.Join(g.outputdir, strBuilder.String()) | |
76 | 81 |
77 file, err := os.Create(strBuilder.String()) | 82 file, err := os.Create(strBuilder.String()) |
78 defer file.Close() | 83 defer file.Close() |
79 | 84 |
80 if err != nil { | 85 if err != nil { |
81 return errors.Wrap("failed create html...") | 86 return errors.Wrap("failed create html...") |
82 } | 87 } |
83 | 88 |
84 strBuilder.Reset() | 89 strBuilder.Reset() |
85 | 90 |
86 res, err := http.Get("http://google.com") | 91 u, err := url.Parse(endpoint) |
92 if err != nil { | |
93 return err | |
94 } | |
95 | |
96 u.path = path.Join(u.path, "portal", "Public", "Syllabus", "SyllabusSearchStart.aspx") | |
97 q := u.Query() | |
98 q.Set("lect_year", g.year) | |
99 q.Set("lect_cd", lectureID) | |
100 q.Set("je_cd", "1") | |
101 u.RawQuery = q.Encode() | |
102 | |
103 res, err := http.Get(u.String()) | |
87 defer res.Body.Close() | 104 defer res.Body.Close() |
88 | 105 |
89 if err != nil { | 106 if err != nil { |
90 return errors.Wrap("failed download html") | 107 return errors.Wrap("failed download html") |
91 } | 108 } |