From 7ec585e1152479c2fdae64de6f7af1aab744f0eb Mon Sep 17 00:00:00 2001 From: far-galaxy Date: Mon, 31 Jul 2023 12:23:26 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5:=20=D0=B7=D0=B0=D0=B3=D1=80?= =?UTF-8?q?=D1=83=D0=B7=D0=BA=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=86=D1=8B=20=D1=81=20=D1=80=D0=B0=D1=81=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/ssau_parser/connecter.go | 7 ++++++ modules/ssau_parser/ssau_parser_test.go | 31 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/modules/ssau_parser/connecter.go b/modules/ssau_parser/connecter.go index cb2614d..884051a 100644 --- a/modules/ssau_parser/connecter.go +++ b/modules/ssau_parser/connecter.go @@ -101,6 +101,9 @@ func DownloadShedule(uri string, week int) (Page, error) { var page Page var err error + if len(uri) < 15 { + return page, fmt.Errorf("uri too short, maybe its wrong: %s", uri) + } page.ID, err = strconv.ParseInt(uri[14:], 0, 64) if err != nil { return page, err @@ -120,6 +123,10 @@ func DownloadShedule(uri string, week int) (Page, error) { return page, err } + if resp.StatusCode != 200 { + return page, fmt.Errorf("responce: %s", resp.Status) + } + page.Doc, err = goquery.NewDocumentFromReader(resp.Body) if err != nil { return page, err diff --git a/modules/ssau_parser/ssau_parser_test.go b/modules/ssau_parser/ssau_parser_test.go index 5c569dd..24c7ab3 100644 --- a/modules/ssau_parser/ssau_parser_test.go +++ b/modules/ssau_parser/ssau_parser_test.go @@ -41,3 +41,34 @@ func pingQuery(query string, t *testing.T) { log.Println(query, list) } } + +var groupUri = []string{ + "/rasp?groupId=530996168", + "/rasp?staffId=59915001", + "/aaa", + "/aaaaaaaaaaaaaa", + "/rasp?groupId=123", +} +var weeks = []int{ + 1, + 2, + 100, +} + +func TestDownloadShedule(t *testing.T) { + // headURL = "https://ssau.ru" + headURL = "http://127.0.0.1:5000" + for _, uri := range groupUri { + for _, week := range weeks { + if _, err := DownloadShedule(uri, week); err != nil { + log.Println(err) + } + } + } + if _, err := DownloadSheduleById(530996168, true, 1); err != nil { + log.Println(err) + } + if _, err := DownloadSheduleById(59915001, false, 1); err != nil { + log.Println(err) + } +}