diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1f6b865 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +bdown: + go build -v ./cmd/mtdown + +rdown: + go run ./cmd/mtdown + +bparse: + go build -v ./cmd/mtparse + +rparse: + go run ./cmd/mtparse + +bstep: + go build -v ./cmd/mtstep + +rstep: + go run ./cmd/mtstep + +.DEFAULT_GOAL := bstep diff --git a/cmd/mtdown/main.go b/cmd/mtdown/main.go new file mode 100644 index 0000000..918c1c9 --- /dev/null +++ b/cmd/mtdown/main.go @@ -0,0 +1,33 @@ +package main + +import ( + "fmt" + + "github.com/google/uuid" + "gitstore.ru/tolikproh/mchstest/internal/cnst" + "gitstore.ru/tolikproh/mchstest/internal/model" + "gitstore.ru/tolikproh/mchstest/pkg/util" +) + +func main() { + fmt.Println("Загрузка вопросов для тестирования с сайта:", cnst.Url) + uidMchs, err := uuid.Parse(util.InputTerminal("Необходимо ввести UUID сессии для начала загрузки")) + if err != nil { + fmt.Println("ОШИБКА: формат UUID не верный. Зазрузка отменена.") + } else { + var rN model.ReqNull + var rA model.ReqAnswer + body, _ := util.ReqestToSiteJSON(rN, cnst.Url, uidMchs) + fmt.Println("[") + for i := 0; i < 520; i++ { + d := model.UnmarshalJSONToMTType(body) + fmt.Print(model.MTTypeToJSON(d), ",\n") + rA.Answer = d.ValidAnswer + body, _ = util.ReqestToSiteJSON(rA, cnst.Url, uidMchs) + } + d := model.UnmarshalJSONToMTType(body) + fmt.Println(model.MTTypeToJSON(d)) + fmt.Println("]") + } + +} diff --git a/main.go b/cmd/mtparse/main.go similarity index 100% rename from main.go rename to cmd/mtparse/main.go diff --git a/cmd/mtstep/main.go b/cmd/mtstep/main.go new file mode 100644 index 0000000..772ee98 --- /dev/null +++ b/cmd/mtstep/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "fmt" + + "strconv" + + "github.com/google/uuid" + "gitstore.ru/tolikproh/mchstest/internal/cnst" + "gitstore.ru/tolikproh/mchstest/internal/model" + "gitstore.ru/tolikproh/mchstest/pkg/util" +) + +func main() { + fmt.Println("Утилита для пропуска подготовительных вопросов (марафон) к тестированию с сайта: https://digital.mchs.gov.ru/fgpn/simulator") + uidMchs, err := uuid.Parse(util.InputTerminal("Необходимо ввести UUID сессии для начала загрузки")) + if err != nil { + fmt.Println("ОШИБКА: формат UUID не верный. Завершение работы.") + + } else { + numMchsStr := util.InputTerminal("Необходимо ввести номер вопроса (с 1 до 520)") + numMchs, err := strconv.Atoi(numMchsStr) + if err != nil { + fmt.Println("ОШИБКА: введен не номер. Завершение работы.") + + } + if numMchs <= 0 || numMchs > 520 { + fmt.Println("ОШИБКА: не верный диапазон (должно быть с 1 до 520). Завершение работы.") + } else { + var rN model.ReqNull + var rA model.ReqAnswer + fmt.Print("Выполняется") + body, _ := util.ReqestToSiteJSON(rN, cnst.Url, uidMchs) + for i := 1; i < numMchs; i++ { + d := model.UnmarshalJSONToMTType(body) + fmt.Print(".") + rA.Answer = d.ValidAnswer + body, _ = util.ReqestToSiteJSON(rA, cnst.Url, uidMchs) + } + fmt.Println("\nРабота выполнена, пропущено", numMchs, "вопросов! Обновите страницу на сайте и продолжайте отвечать на подготовительные вопросы.") + } + + } + +} diff --git a/internal/cnst/constants.go b/internal/cnst/constants.go new file mode 100644 index 0000000..457639f --- /dev/null +++ b/internal/cnst/constants.go @@ -0,0 +1,5 @@ +package cnst + +const ( + Url string = "https://digital.mchs.gov.ru/testing/api/instance/" +) diff --git a/internal/model/mtentity.go b/internal/model/mtentity.go new file mode 100644 index 0000000..c908ea9 --- /dev/null +++ b/internal/model/mtentity.go @@ -0,0 +1,52 @@ +package model + +import ( + "encoding/json" + + "github.com/google/uuid" +) + +type MTType struct { + Id uuid.UUID `json:"id"` + CurrentQuestion CQType `json:"current_question"` + CurrentAnswers []CAType `json:"current_answers"` + QuestionCount int `json:"questions_count"` + QuestionNumber int `json:"question_number"` + QuestionStatus []int `json:"questions_statuses"` + ValidAnswer uuid.UUID `json:"valid_answer"` + QuestionPassed int `json:"questions_passed"` + ValidAnswers string `json:"valid_answers"` +} + +type CQType struct { + Id uuid.UUID `json:"id"` + Content string `json:"content"` + ResourcesPath []string `json:"resources_path"` + Types string `json:"type"` + IsAdd bool `json:"id_additional"` +} + +type CAType struct { + Id uuid.UUID `json:"id"` + Title string `json:"title"` + ResourcesPath []string `json:"resources_path"` +} + +func MTTypeToJSON(data *MTType) string { + req, _ := json.Marshal(data) + return string(req) +} + +func UnmarshalJSONToMTType(in []byte) *MTType { + var data MTType + _ = json.Unmarshal(in, &data) + return &data +} + +type ReqAnswer struct { + Answer uuid.UUID `json:"answer"` +} + +type ReqNull struct { + Answers string `json:"answers"` +} diff --git a/mtdown b/mtdown new file mode 100755 index 0000000..2d1a4fe Binary files /dev/null and b/mtdown differ diff --git a/main b/mtstep similarity index 58% rename from main rename to mtstep index 9747dd4..916aeeb 100755 Binary files a/main and b/mtstep differ diff --git a/pkg/util/download.go b/pkg/util/download.go new file mode 100644 index 0000000..73f18be --- /dev/null +++ b/pkg/util/download.go @@ -0,0 +1,34 @@ +package util + +import ( + "bytes" + "encoding/json" + "io/ioutil" + "net/http" + + "github.com/google/uuid" +) + +func ReqestToSiteJSON(req any, url string, uid uuid.UUID) ([]byte, error) { + + reqBodyBytes, err := json.Marshal(req) + if err != nil { + return nil, err + } + + urlr := url + uid.String() + resp, err := http.Post( + urlr, + "application/json", bytes.NewBuffer(reqBodyBytes)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + + return body, nil +} diff --git a/pkg/util/terminal.go b/pkg/util/terminal.go new file mode 100644 index 0000000..65fb2ae --- /dev/null +++ b/pkg/util/terminal.go @@ -0,0 +1,25 @@ +package util + +import ( + "bufio" + "fmt" + "os" + "strings" +) + +func InputTerminal(name string) string { + + fmt.Print(name + ": ") + reader := bufio.NewReader(os.Stdin) + ret, _ := reader.ReadString('\n') + splitedSlice := strings.Split(ret, " ") + + if len(splitedSlice) == 1 { + splSlice2 := strings.Split(splitedSlice[0], "\n") + ret = splSlice2[0] + } else { + ret = splitedSlice[0] + } + + return ret +}