func getFid(forumName string) uint64 {
	var fid uint64

	for i := 0; ; {
		_fid, err, pberr := apis.GetFid(forumName)
		if err != nil {
			continue
		} else if pberr != nil && pberr.ErrorCode != 0 {
			if i < 10 {
				i++
				continue
			}
			logs.Fatal("方案A未能获得到fid,进行下一步尝试.", pberr)
			break
		} else if _fid == 0 {
			logs.Warn("方案A未能获得到fid,进行下一步尝试.")
			break
		} else {
			fid = _fid
			break
		}
	}

	if fid == 0 {
		for i := 0; ; {
			results, err, pberr := apis.SearchForum(forumName)
			if err != nil {
				continue
			} else if pberr != nil && pberr.ErrorCode != 0 {
				if i < 10 {
					i++
					continue
				}
				logs.Fatal("方案B未能获得到fid,放弃.", pberr)
				return 0
			} else if len(results) == 0 {
				logs.Fatal("未找到该贴吧,放弃.", pberr)
				return 0
			} else {
				for _, result := range results {
					if result.ForumName == forumName {
						return result.ForumID
					}
				}
				logs.Fatal("未找到该贴吧,放弃.", pberr)
				return 0
			}
		}
	}

	return fid
}
Example #2
0
func NewPostFinder(accWin8, accAndr *postbar.Account, forumName string, yield func(*PostFinder), debug bool, logDir string) (*PostFinder, error) {
	var postFinder PostFinder
	postFinder.Debug.StartTime = time.Now()

	postFinder.AccWin8 = accWin8
	postFinder.AccAndr = accAndr
	postFinder.ForumName = forumName

	initLoggers(&postFinder, logDir)

	yield(&postFinder)
	if postFinder.ThreadFilter == nil || postFinder.NewThreadFirstAssessor == nil ||
		postFinder.NewThreadSecondAssessor == nil || postFinder.AdvSearchAssessor == nil ||
		postFinder.PostAssessor == nil || postFinder.CommentAssessor == nil {
		logger.Fatal("删贴机初始化错误,有函数未设置:", postFinder, ".")
		panic("删贴机初始化错误,有函数未设置: " + fmt.Sprintln(postFinder) + ".")
	}

	fid, err, pberr := apis.GetFid(forumName)
	if err != nil || pberr != nil {
		logger.Fatal("获取fid时出错: ", err, pberr)
		return nil, err
	}
	postFinder.Fid = fid

	postFinder.SearchTaskManager = NewSearchTaskManager(&postFinder, 0, time.Second,
		time.Second*10, time.Second*30, time.Minute, time.Minute*5, time.Minute*10,
		time.Minute*30, time.Hour, time.Hour*3)

	if debug {
		InitDebugger()
		postFinder.Debugger = NewDebugger(forumName, &postFinder, time.Second/4)
	}

	return &postFinder, nil

}