Example #1
0
def start_like_bot(screen_name="",
                   text_to_match="",
                   message="This is a default message -- I am a bot"):

    ## Exiting if nothing is specified
    if screen_name == "" and text_to_match == "":
        print "Specify atleast one parameter.... exiting"
        exit()

## initializing the API keys
    api_key = TwitterAPI._get_api_auth_details()
    twitter_object_lookup = TwitterAPI._get_api_client(api_key)
    twitter_object = TwitterAPI._get_api_client_stream(api_key)

    track = text_to_match
    follow = screen_name

    ## Twitter Streaming API required user_id for 'follow'... So for the given screen_name, user_lookup end point is called to extract the user_id
    if follow != "":
        follow = TwitterAPI.bot_lookup(twitter_object_lookup,
                                       screen_name.lstrip('@'))

    while True:
        try:
            ## if screen_name and hence the user_id is invalid
            if follow == False:
                print "invalid screen_name...exiting.."
                break
            else:
                ## if both screen_name and text_to_search is specified
                if follow != "" and follow != None:
                    iterator = twitter_object.statuses.filter(follow=follow,
                                                              track=track)
                else:
                    ## for only text_to_search is given
                    iterator = twitter_object.statuses.filter(track=track)

                print "iterating through all the steaming tweets for the given params"
                for tweet in iterator:

                    TwitterAPI.bot_retweet(twitter_object_lookup, tweet['id'])
                    print "retweeted the tweet_id -> ", tweet['id']
                    TwitterAPI.bot_like(twitter_object_lookup, tweet['id'])
                    print "liked the tweet_id -> ", tweet['id']
                    TwitterAPI.bot_reply(
                        twitter_object_lookup,
                        '@' + tweet['user']['screen_name'] + ' ' + message,
                        tweet['id'])
                    print "replied to user -> ", tweet['user'][
                        'screen_name'], " with this message ->", message
                    TwitterAPI.bot_tweet(twitter_object_lookup, message)
                    print "tweeted with message -> ", message
                ## uncomment the below 2 calls if you want to use them
                # TwitterAPI.bot_follow(twitter_object_lookup,screen_name)
                ## chat will only work if the user is following you
                # TwitterAPI.bot_chat(twitter_object_lookup,message,screen_name)

        except Exception, e:
            print str(e)
            time.sleep(random.randint(0, 30))
Example #2
0
def start_like_bot(screen_name = "",text_to_match= "" ,message= "This is a default message -- I am a bot"):

## Exiting if nothing is specified
	if screen_name == "" and text_to_match == "":
		print "Specify atleast one parameter.... exiting"
		exit()

## initializing the API keys
	api_key = TwitterAPI._get_api_auth_details()
	twitter_object_lookup = TwitterAPI._get_api_client(api_key)
	twitter_object = TwitterAPI._get_api_client_stream(api_key)

	track     = text_to_match
	follow 	  = screen_name

## Twitter Streaming API required user_id for 'follow'... So for the given screen_name, user_lookup end point is called to extract the user_id
	if follow != "":
		follow = TwitterAPI.bot_lookup(twitter_object_lookup,screen_name.lstrip('@'))

	while True:
		try:
			## if screen_name and hence the user_id is invalid
			if follow == False:
				print "invalid screen_name...exiting.."
				break
			else:
				## if both screen_name and text_to_search is specified
				if follow != "" and follow != None:
					iterator       = twitter_object.statuses.filter(follow = follow,track = track)
				else:
				## for only text_to_search is given
					iterator       = twitter_object.statuses.filter(track = track)

				print "iterating through all the steaming tweets for the given params"
				for tweet in iterator:

					TwitterAPI.bot_retweet(twitter_object_lookup,tweet['id'])
					print "retweeted the tweet_id -> " , tweet['id']
					TwitterAPI.bot_like(twitter_object_lookup,tweet['id'])
					print "liked the tweet_id -> " , tweet['id']
					TwitterAPI.bot_reply(twitter_object_lookup,'@'+ tweet['user']['screen_name'] +' '+ message,tweet['id'])
					print "replied to user -> " , tweet['user']['screen_name'], " with this message ->", message
					TwitterAPI.bot_tweet(twitter_object_lookup,message)
					print "tweeted with message -> " , message
				## uncomment the below 2 calls if you want to use them
					# TwitterAPI.bot_follow(twitter_object_lookup,screen_name)
				## chat will only work if the user is following you
					# TwitterAPI.bot_chat(twitter_object_lookup,message,screen_name)

		except Exception, e:
			print str(e)
			time.sleep(random.randint(0,30))
Example #3
0
def start_conditional_bot(screen_name="",
                          text_to_match="",
                          message="This is a default message -- I am a bot"):

    ## Exiting if nothing is specified
    if screen_name == "" and text_to_match == "":
        print "Specify atleast one parameter.... exiting"
        exit()

## initializing the API keys
    api_key = TwitterAPI._get_api_auth_details()
    twitter_object_lookup = TwitterAPI._get_api_client(api_key)
    twitter_object = TwitterAPI._get_api_client_stream(api_key)
    track = text_to_match
    follow = screen_name

    ## Twitter Streaming API required user_id for 'follow'... So for the given screen_name, user_lookup end point is called to extract the user_id
    if follow != "":
        follow = TwitterAPI.bot_lookup(twitter_object_lookup,
                                       screen_name.lstrip('@'))

    print "Starting streaming!!"
    while True:
        try:
            iterator = twitter_object.statuses.sample()

            for tweet in iterator:
                ## Checking if the tweet is not deleted
                if 'delete' not in tweet:
                    ## if the author of the tweets matches the given screen_name then like the tweet
                    if tweet['user']['screen_name'] == str(
                            screen_name.lstrip('@')):
                        TwitterAPI.bot_like(twitter_object_lookup, tweet['id'])
                        print "liked the tweet_id -> ", tweet['id']

                    ## if the text of the tweets contains the given text then reply and retweet and follow
                    if text_to_match in tweet['text']:
                        TwitterAPI.bot_reply(
                            twitter_object_lookup,
                            '@' + tweet['user']['screen_name'] + ' ' + message,
                            tweet['id'])
                        print "replied to user -> ", tweet['user'][
                            'screen_name'], " with this message ->", message

                        TwitterAPI.bot_retweet(twitter_object_lookup,
                                               tweet['id'])
                        print "retweeted the tweet_id -> ", tweet['id']

                        TwitterAPI.bot_follow(twitter_object_lookup,
                                              screen_name)
                        print "followed the user -> ", tweet['user'][
                            'screen_name']

                    ## will work only if the user is following you
                    # TwitterAPI.bot_chat(twitter_object_lookup,message,tweet['user']['screen_name'])

                ## if the user is tweeting with the word 'hate' then reply 'please don't spread hate
                    if 'hate' in tweet['text']:
                        TwitterAPI.bot_reply(
                            twitter_object_lookup,
                            '@' + tweet['user']['screen_name'] +
                            ' Please dont spread hate', tweet['id'])
                        print "replied to user -> ", tweet['user'][
                            'screen_name'], " with this message ->", message
                        # TwitterAPI.bot_unlike(twitter_object_lookup,tweet['id'])

                ## if there are more than 1 hashtags, then takes the 1st hashtag and tweet with the given message
                    if len(tweet['entities']['hashtags']) > 0:
                        hashtags = tweet['entities']['hashtags'][0]['text']
                        TwitterAPI.bot_tweet(twitter_object_lookup,
                                             '#' + hashtags + ' ' + message)
                        print "tweeted with message -> ", '#' + hashtags + ' ' + message

                        TwitterAPI.bot_retweet(twitter_object_lookup,
                                               tweet['id'])
                        print "retweeted the tweet_id -> ", tweet['id']

        except Exception, e:
            print str(e)
            traceback.print_exc()
            print 'gooing to sleep'
            time.sleep(10)
            print 'woke up!!'


# start_conditional_bot('yathshar','pokemon','pokemonGo!!')
Example #4
0
def start_conditional_bot(screen_name = "",text_to_match = "",message = "This is a default message -- I am a bot"):

## Exiting if nothing is specified
	if screen_name == "" and text_to_match == "":
		print "Specify atleast one parameter.... exiting"
		exit()

## initializing the API keys
	api_key = TwitterAPI._get_api_auth_details()
	twitter_object_lookup = TwitterAPI._get_api_client(api_key)
	twitter_object = TwitterAPI._get_api_client_stream(api_key)
	track     = text_to_match
	follow 	  = screen_name

## Twitter Streaming API required user_id for 'follow'... So for the given screen_name, user_lookup end point is called to extract the user_id
	if follow != "":
		follow = TwitterAPI.bot_lookup(twitter_object_lookup,screen_name.lstrip('@'))

	print "Starting streaming!!"
	while True:
		try:
			iterator = twitter_object.statuses.sample()


			for tweet in iterator:
## Checking if the tweet is not deleted
				if 'delete' not in tweet:
				## if the author of the tweets matches the given screen_name then like the tweet
					if tweet['user']['screen_name'] == str(screen_name.lstrip('@')):
						TwitterAPI.bot_like(twitter_object_lookup,tweet['id'])
						print "liked the tweet_id -> " , tweet['id']

					## if the text of the tweets contains the given text then reply and retweet and follow
					if text_to_match in tweet['text']:
						TwitterAPI.bot_reply(twitter_object_lookup,'@'+tweet['user']['screen_name']+' '+message,tweet['id'])
						print "replied to user -> " , tweet['user']['screen_name'], " with this message ->", message

						TwitterAPI.bot_retweet(twitter_object_lookup,tweet['id'])
						print "retweeted the tweet_id -> " , tweet['id']

						TwitterAPI.bot_follow(twitter_object_lookup,screen_name)
						print "followed the user -> " , tweet['user']['screen_name']

					## will work only if the user is following you
						# TwitterAPI.bot_chat(twitter_object_lookup,message,tweet['user']['screen_name'])

				## if the user is tweeting with the word 'hate' then reply 'please don't spread hate
					if 'hate' in tweet['text']:
						TwitterAPI.bot_reply(twitter_object_lookup,'@'+tweet['user']['screen_name']+' Please dont spread hate',tweet['id'])
						print "replied to user -> " , tweet['user']['screen_name'], " with this message ->", message
						# TwitterAPI.bot_unlike(twitter_object_lookup,tweet['id'])

				## if there are more than 1 hashtags, then takes the 1st hashtag and tweet with the given message
					if len(tweet['entities']['hashtags']) > 0:
						hashtags = tweet['entities']['hashtags'][0]['text']
						TwitterAPI.bot_tweet(twitter_object_lookup,'#'+hashtags + ' '+ message)
						print "tweeted with message -> " , '#'+hashtags + ' '+ message

						TwitterAPI.bot_retweet(twitter_object_lookup,tweet['id'])
						print "retweeted the tweet_id -> " , tweet['id']


		except Exception, e:
			print str(e)
			traceback.print_exc()
			print 'gooing to sleep'
			time.sleep(10)
			print 'woke up!!'


# start_conditional_bot('yathshar','pokemon','pokemonGo!!')