Ejemplo n.º 1
0
func processHandle(w http.ResponseWriter, r *http.Request, s *session.Session) {

	// Grab intervals since day start
	intervals := utils.Intervals()

	// Had some fancy math for peroidictiy. But
	// we could just brute force 100 per hour
	likes := int(utils.LIKES / utils.CALLS)
	utils.Limit(&likes, intervals, utils.LIKES)

	if !s.Usable() {
		fmt.Fprint(w, "Please set hashtags and authorize")
		return
	}

	// Follow ratio function where target is the desired
	// amount of followers.
	// e^(x*ln(magic)/target)
	// I wish could say there's some science behind why
	// we're doing this, but ultimately we just need a
	// decreasing function and some percentage of your
	// target feels right
	count := action.GetStatus(s)
	follows := int(utils.FollowerDecay(count.Followed_by, count.Follows, s.GetMagic(), s.GetTarget()))
	utils.Limit(&follows, intervals, utils.FOLLOWS)
	if follows < 0 {
		follows = 0
	}

	// Hang on channel otherwise jobs cut out
	done := make(chan bool)

	// Save status at midnight
	if intervals == 0 {
		go s.SetRecords(count.Followed_by, count.Follows)
	}
	if s.GetLearnt() {
		IntelligentDecision(s, follows, likes, intervals, done)
	} else {
		BasicDecision(s, follows, likes, intervals, done)
	}
	// Wait for finish. Defeats the purpose of aysnc, but only way to run in prod
	<-done
	fmt.Fprint(w, "Processing")
}