示例#1
0
文件: action.go 项目: Pym/TwitterBot
func actionFavorite() {
	fmt.Println("Action fav")

	search, v := generateAPISearchValues(KEYWORDS[rand.Intn(len(KEYWORDS))])

	searchResult, err := api.GetSearch(search, v)
	if err != nil {
		fmt.Println("Error while querying twitter API", err)
		return
	}

	i := 0
	for _, tweet := range searchResult.Statuses {
		if i >= FAV_LIMIT_IN_A_ROW {
			return
		}

		if !isUserAcceptable(tweet) {
			fmt.Println("Ignoring user for favorite : @" + tweet.User.ScreenName)
			continue
		}

		if isMentionOrRT(tweet) {
			fmt.Println("Ignoring tweet for favorite, mention or RT")
			continue
		}

		if isMe(tweet) {
			fmt.Println("Ignoring my own tweet for favorite")
			continue
		}

		follow, err := db.AlreadyFollow(tweet.User.Id)
		if err == nil && follow {
			fmt.Println("Ignoring tweet for favorite, already follow @" + tweet.User.ScreenName)
			continue
		}

		alreadyFav, err := db.HasAlreadyFav(tweet.Id)
		if err != nil {
			fmt.Println("Error while checking already fav", err)
			return
		}

		if alreadyFav {
			fmt.Println("Ignoring tweet for favorite, already fav tweet from @" + tweet.User.ScreenName)
			continue
		}

		err = db.Favorite{UserId: tweet.User.Id, UserName: tweet.User.ScreenName, TweetId: tweet.Id, Status: tweet.Text, FavDate: time.Now()}.Persist()
		if err != nil {
			fmt.Println("Error while persisting fav", err)
			return
		}

		_, err = api.Favorite(tweet.Id)
		if err != nil {
			if strings.Contains(err.Error(), "139") { // Case of an already favorited tweet
				continue
			}

			fmt.Println("Error while favoriting tweet", err)
		} else {
			fmt.Println("Just favorited tweet : ", tweet.Text)
		}

		i++
	}
}
示例#2
0
文件: action.go 项目: Pym/TwitterBot
func actionFollow() {
	fmt.Println("Action follow")

	search, v := generateAPISearchValues(KEYWORDS[rand.Intn(len(KEYWORDS))])

	searchResult, err := api.GetSearch(search, v)
	if err != nil {
		fmt.Println("Error while querying twitter API", err)
		return
	}

	for _, tweet := range searchResult.Statuses {
		if !isUserAcceptable(tweet) {
			fmt.Println("Ignoring user for follow : @" + tweet.User.ScreenName)
			continue
		}

		if isMentionOrRT(tweet) {
			fmt.Println("Ignoring tweet for follow, mention or RT")
			continue
		}

		if isMe(tweet) {
			fmt.Println("Ignoring my own tweet for follow")
			continue
		}

		follow, err := db.AlreadyFollow(tweet.User.Id)
		if err != nil {
			fmt.Println("Error while checking if already follow")
			return
		}

		if follow {
			fmt.Println("Ignoring user for follow, already follow @" + tweet.User.ScreenName)
			continue
		}

		alreadyFollowMe, err := isUserFollowing(tweet.User.ScreenName)
		if err != nil {
			fmt.Println("Error while checking user already follow", err)
			return
		}

		if alreadyFollowMe {
			fmt.Println("Ignoring user @" + tweet.User.ScreenName + " for follow cause he already follow us")
			continue
		}

		err = db.Follow{UserId: tweet.User.Id, UserName: tweet.User.ScreenName, Status: tweet.Text, FollowDate: time.Now()}.Persist()
		if err != nil {
			fmt.Println("Error while persisting follow", err)
			return
		}

		_, err = api.FollowUser(tweet.User.ScreenName)
		if err != nil {
			fmt.Println("Error while following user "+tweet.User.ScreenName+" : ", err)
		}

		fmt.Println("Now follow ", tweet.User.ScreenName)
		return
	}
}