Exemplo n.º 1
0
func (t ForumPageThread) TGetContentList() []postbar.Content {

	var originalContentList = append(t.Abstract, t.MediaList...)
	var contents = make([]postbar.Content, 0)

	for _, originalContent := range originalContentList {
		var contentMap map[string]interface{}
		var ok bool
		if contentMap, ok = originalContent.(map[string]interface{}); !ok {
			logs.Error("获取内容中的一项失败", originalContent)
			contents = append(contents, originalContent)
			continue
		}

		var content postbar.Content

		func() {
			defer func() {
				err := recover()
				if err != nil {
					logs.Error("获取内容中的一项的属性失败:", err, contentMap)
					content = contentMap
				}
			}()

			var contentType int32
			switch contentMap["type"].(type) {
			case (string):
				contentType_str, _ := strconv.Atoi(contentMap["type"].(string))
				contentType = int32(contentType_str)
			case (float64):
				contentType = int32((contentMap["type"].(float64)))
			}
			switch contentType {
			case 0:
				content = postbar.Text{contentMap["text"].(string)}
			case 3:
				content = postbar.Pic{contentMap["big_pic"].(string)}
			case 5:
				content = postbar.Video{contentMap["vhsrc"].(string)}
			case 6:
				content = postbar.Music{contentMap["vhsrc"].(string)}
			default:
				content = contentMap
			}

			contents = append(contents, content)
		}()
	}
	return contents

}
Exemplo n.º 2
0
func WriteNewFile(dir, fn, c string) {
	os.MkdirAll(dir, 0777)
	f, err := os.Create(dir + fn)
	if err != nil {
		logs.Error("创造文件时失败", err.Error())
	} else {
		f.WriteString(c)
	}
	if f != nil {
		f.WriteString(c)
	}

}
Exemplo n.º 3
0
func ParseAdvSearchDocument(doc *goquery.Document) []AdvSearchResult {
	posts := doc.Find(`div.s_post_list`).Eq(0).Find(`div.s_post`)
	results := make([]AdvSearchResult, posts.Length())
	posts.Each(func(index int, post *goquery.Selection) {
		result := &results[index]
		bluelink := post.Find(`a.bluelink`)
		title := bluelink.Text()
		oldLen := len(title)
		result.Title = strings.TrimPrefix(misc.FromGBK(title), `回复:`)
		result.IsReply = oldLen != len(result.Title)
		link, _ := bluelink.Attr(`href`)

		ids := idreg.FindStringSubmatch(link)

		if len(ids) != 3 {
			logs.Error("高级搜索结果链接异常,跳过:", link, ".")
			goto CONTINUE
		}
		{
			result.Tid, _ = strconv.ParseUint(ids[1], 10, 64)
			result.Pid, _ = strconv.ParseUint(ids[2], 10, 64)

			result.Content = misc.FromGBK(post.Find(`div.p_content`).Text())

			date := misc.FromGBK(post.Find(`font.p_date`).Text())
			var y, m, d, hour, min int
			fmt.Sscanf(date, "%d-%d-%d %d:%d", &y, &m, &d, &hour, &min)
			result.PostTime = time.Date(y, time.Month(m), d, hour, min, 0, 0, time.Local)

			x := post.Find(`font.p_violet`)
			result.Forum = misc.FromGBK(x.First().Text())
			result.Author.Name = misc.FromGBK(x.Next().Text())

		}

	CONTINUE:
	})

	return results
}
Exemplo n.º 4
0
func LoadExps(file *os.File, exps *[]RegexpKeyword, logger *logs.Logger) error {

	bytes, err := ReadAll(file)
	if err != nil {
		return err
	}

	lines := strings.Split(string(bytes), "\n")

	oldExps := make(map[string]RegexpKeyword)

	for _, exp := range *exps {
		if exp.BanFlag {
			oldExps["$ban "+exp.Rx.String()] = exp
		} else {
			oldExps[exp.Rx.String()] = exp
		}
	}

	newExps := make(map[string]RegexpKeyword)
	var addedExps []string

	for lineNo, line := range lines {
		line = strings.TrimRightFunc(line, func(r rune) bool {
			return r == '\n' || r == '\r'
		})
		if line == "" {
			continue
		}
		if exp, exist := oldExps[line]; exist {
			newExps[line] = exp
			delete(oldExps, line)
		} else {
			var banFlag bool
			var newExp *regexp.Regexp
			var err error
			if banFlag = strings.HasPrefix(line, "$ban "); banFlag {
				newExp, err = regexp.Compile(strings.TrimLeft(line, "$ban "))
			} else {
				newExp, err = regexp.Compile(line)
			}
			if err != nil {
				logs.Error(fmt.Sprintf("不正确的关键词(第%d行),跳过.", lineNo), err)
			} else {
				newExps[line] = RegexpKeyword{banFlag, newExp}
				addedExps = append(addedExps, line)
			}

		}
	}

	newExpSlice := make([]RegexpKeyword, 0, len(newExps))

	for _, exp := range newExps {
		newExpSlice = append(newExpSlice, exp)
	}

	*exps = newExpSlice

	var updateInfo string = fmt.Sprintf("更新关键词(%s):\n", file.Name())
	for _, exp := range addedExps {
		updateInfo = updateInfo + "[+] " + exp + "\n"
	}
	for _, exp := range oldExps {
		if exp.BanFlag {
			updateInfo = updateInfo + "[-] $ban" + exp.Rx.String() + "\n"
		} else {
			updateInfo = updateInfo + "[-] " + exp.Rx.String() + "\n"
		}
	}
	updateInfo = strings.TrimSuffix(updateInfo, "\n")
	logger.Info(updateInfo)

	//logger.Debug("现在的关键词:", newExpSlice, ".")

	return nil
}
Exemplo n.º 5
0
func ExtractContent(originalContentList []interface{}) []postbar.Content {

	var contents []postbar.Content = make([]postbar.Content, 0)

	for _, originalContent := range originalContentList {
		var contentMap map[string]interface{}
		var ok bool
		if contentMap, ok = originalContent.(map[string]interface{}); !ok {
			logs.Error("获取内容中的一项失败", originalContent)
			contents = append(contents, originalContent)
			continue
		}

		var content postbar.Content

		func() {
			defer func() {
				err := recover()
				if err != nil {
					logs.Error("获取内容中的一项的属性失败:", err, contentMap)
					content = contentMap
				}
			}()

			var contentType int32
			switch contentMap["type"].(type) {
			case (string):
				contentType_str, _ := strconv.Atoi(contentMap["type"].(string))
				contentType = int32(contentType_str)
			case (float64):
				contentType = int32((contentMap["type"].(float64)))
			}
			switch contentType {
			case 0: //文字,楼中楼会把所在楼层的图片也归为文字.
				content = postbar.Text{contentMap["text"].(string)}
			case 1: //链接
				content = postbar.Link{contentMap["link"].(string), contentMap["text"].(string)}
			case 2: //表情
				content = postbar.Emoticon{contentMap["text"].(string), contentMap["c"].(string)}
			case 3: //图片
				content = postbar.Pic{contentMap["src"].(string)}
			case 4: //@
				var uidStr = contentMap["uid"].(string)
				var uid, _ = strconv.ParseUint(uidStr, 10, 64)
				content = postbar.At{contentMap["text"].(string), uid}
			case 5: //音乐??视频??
				content = postbar.Video{contentMap["text"].(string)}
			case 6: //视频??
			case 10: //语音
				during_time, _ := strconv.Atoi(contentMap["during_time"].(string))
				content = postbar.Voice{int32(during_time), contentMap["voice_md5"].(string)}
			case 11: //表情商店里的表情 //没什么好搞的
				content = contentMap
			default:
				content = contentMap
			}
		}()

		contents = append(contents, content)

	}
	return contents

}