|
@@ -1115,6 +1115,40 @@ type CourseModule struct {
|
|
|
ModuleId string
|
|
|
}
|
|
|
|
|
|
+func getUploadIds(moduleId string, cookie string) ([]int64, error) {
|
|
|
+ url := fmt.Sprintf("https://lms.ouchn.cn/api/activities/%s", moduleId)
|
|
|
+ request, err := http.NewRequest("GET", url, nil)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
+ request.Header.Set("Cookie", cookie)
|
|
|
+ request.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36")
|
|
|
+ //request.Header.Set("Host", "chengdu.ouchn.cn")
|
|
|
+
|
|
|
+ client := http.Client{}
|
|
|
+ resp, err := client.Do(request)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+
|
|
|
+ respBytes, err := ioutil.ReadAll(resp.Body)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ ret := []int64{}
|
|
|
+ uploads := gjson.GetBytes(respBytes, "uploads").Array()
|
|
|
+ for _, upload := range uploads {
|
|
|
+ id := upload.Get("id").Int()
|
|
|
+ ret = append(ret, id)
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret, nil
|
|
|
+}
|
|
|
+
|
|
|
func getCourseModules(courceId string, cookie string, specialCourse bool) ([]CourseModule, error) {
|
|
|
url := fmt.Sprintf("https://lms.ouchn.cn/api/courses/%s/modules", courceId)
|
|
|
request, err := http.NewRequest("GET", url, nil)
|
|
@@ -1228,7 +1262,7 @@ func GetModuleInfo(courseId string, moduleId string, cookie string) (*ModuleInfo
|
|
|
item.Id = array[1]
|
|
|
if stype == "page" {
|
|
|
texts = append(texts, item)
|
|
|
- } else if stype == "online_video" || (stype == "web_link" && strings.Contains(item.Name, "视频")) {
|
|
|
+ } else if stype == "online_video" || (stype == "web_link" && strings.Contains(item.Name, "视频")) || stype == "material" {
|
|
|
index := -1
|
|
|
for i := len(vedios) - 1; i >= 0; i-- {
|
|
|
if item.SyllabusId == vedios[i].SyllabusId {
|
|
@@ -1263,6 +1297,7 @@ func MakeExamUrl(courseId string, moduleId string, id string) string {
|
|
|
}
|
|
|
|
|
|
func VedioCompleteHandle(cookie string, id string) error {
|
|
|
+
|
|
|
count := 0
|
|
|
start, end := int64(0), int64(1000)
|
|
|
for count < 5 {
|
|
@@ -1961,6 +1996,53 @@ func isSpecialCourse(title string) bool {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
+func finishUploadId(uploadId int64, moduleId string, cookie string) error {
|
|
|
+ rBody := make(map[string]int64)
|
|
|
+ rBody["upload_id"] = uploadId
|
|
|
+ rByte, _ := json.Marshal(rBody)
|
|
|
+ url := fmt.Sprintf("https://lms.ouchn.cn/api/course/activities-read/%s", moduleId)
|
|
|
+ request, err := http.NewRequest("POST", url, bytes.NewBuffer(rByte))
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ request.Header.Set("Content-Type", "application/json")
|
|
|
+ request.Header.Set("Cookie", cookie)
|
|
|
+ request.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36")
|
|
|
+ //request.Header.Set("Host", "chengdu.ouchn.cn")
|
|
|
+
|
|
|
+ client := http.Client{}
|
|
|
+ resp, err := client.Do(request)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+
|
|
|
+ respBytes, err := ioutil.ReadAll(resp.Body)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if true {
|
|
|
+ fmt.Println("do material resp:", string(respBytes))
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func finishMaterial(uploadIds []int64, moduleId string, cookie string) {
|
|
|
+ for _, v := range uploadIds {
|
|
|
+ finishUploadId(v, moduleId, cookie)
|
|
|
+ time.Sleep(1 * time.Second)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func doMaterial(moduleId string, cookie string) {
|
|
|
+ uploadIds, _ := getUploadIds(moduleId, cookie)
|
|
|
+ if len(uploadIds) > 0 {
|
|
|
+ finishMaterial(uploadIds, moduleId, cookie)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func CourseHandle(wd selenium.WebDriver, username string) error {
|
|
|
|
|
|
title, err := wd.Title()
|
|
@@ -1999,13 +2081,15 @@ func CourseHandle(wd selenium.WebDriver, username string) error {
|
|
|
examCount := 0
|
|
|
for _, module := range modules {
|
|
|
fmt.Printf("***课程:%s 栏目:%s\n", title, module.Name)
|
|
|
- if specialCourse && (config.Conf.Target == 1 || config.Conf.Target == 3) && (!strings.Contains(module.Name, "形考任务") &&
|
|
|
+ /*if specialCourse && (config.Conf.Target == 1 || config.Conf.Target == 3) && (!strings.Contains(module.Name, "形考任务") &&
|
|
|
!strings.Contains(module.Name, "形成性考核") &&
|
|
|
!strings.Contains(module.Name, "形考作业") &&
|
|
|
!strings.Contains(module.Name, "课程考核") &&
|
|
|
+ !strings.Contains(module.Name, "大作业") &&
|
|
|
!strings.Contains(module.Name, "考试考核")) {
|
|
|
+ fmt.Println("module name:", module.Name)
|
|
|
continue
|
|
|
- }
|
|
|
+ }*/
|
|
|
if strings.Contains(module.Name, "专题一") ||
|
|
|
strings.Contains(module.Name, "专题二") ||
|
|
|
strings.Contains(module.Name, "专题三") ||
|
|
@@ -2014,12 +2098,22 @@ func CourseHandle(wd selenium.WebDriver, username string) error {
|
|
|
strings.Contains(module.Name, "总论 ") {
|
|
|
//continue
|
|
|
}
|
|
|
+
|
|
|
+ if false {
|
|
|
+ if !strings.Contains(module.Name, "专题三") {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 获取某栏目下的试题和视频数据
|
|
|
+ //fmt.Println("111111111111111111:", courseId, module.ModuleId)
|
|
|
moduleInfo, err := GetModuleInfo(courseId, module.ModuleId, cookie)
|
|
|
if err != nil {
|
|
|
return errors.New(fmt.Sprintf("获取module(%s)详细信息失败:%s", module.Name, err.Error()))
|
|
|
}
|
|
|
|
|
|
+ //fmt.Println("2222222222222:", moduleInfo)
|
|
|
+
|
|
|
// 处理网页数据
|
|
|
if false {
|
|
|
for _, info := range moduleInfo.TxtInfos {
|
|
@@ -2045,6 +2139,12 @@ func CourseHandle(wd selenium.WebDriver, username string) error {
|
|
|
for _, info := range moduleInfo.VedioInfos {
|
|
|
|
|
|
fmt.Printf("*****正在处理视频数据:%s\n", info.Name)
|
|
|
+
|
|
|
+ if info.Stype == "material" {
|
|
|
+ doMaterial(info.Id, cookie)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
url := MakeTxtUrl(courseId, module.ModuleId, info.Id)
|
|
|
wd.Get(url)
|
|
|
cookie, _ := getCookies(wd)
|