Beispiel #1
0
def get_people_to_follow(
    twitter_api: tweepy.API, list_to_follow: Optional[str] = None
) -> Tuple[List[User], int]:
    """
    This will access the Twitter API. It takes the Twitter list we'll be following and draws down the users in that list.
    It then filters out those that the user already follows, and then enqueues each request. If we've made 1,000
    requests today, or 400 for this user, the request will have to be added to the 'do later' queue.
    """
    if list_to_follow is None:
        raise ValueError()
        # hard-coding the list for the data collective
    to_follow: List[User] = [
        member
        for member in cursor(twitter_api.list_members, list_id=list_to_follow).items()
    ]
    count_requests_to_make = len(to_follow)

    all_requests_today = get_app_db().get_item("twitter-api").get("count", 0)
    user_requests_today = get_app_db().get_item(twitter_api.me().id_str).get("count", 0)
    if user_requests_today >= USER_LIMIT or all_requests_today >= TWITTER_LIMIT:
        requests_to_process_now = 0
    else:
        requests_left_today = (
            (TWITTER_LIMIT - all_requests_today),
            (USER_LIMIT - user_requests_today),
            count_requests_to_make,
        )
        requests_to_process_now = min(requests_left_today)
        get_app_db().update_item("twitter-api", "count", requests_to_process_now)
        get_app_db().update_item(
            twitter_api.me().id_str, "count", requests_to_process_now
        )
    return to_follow, requests_to_process_now
Beispiel #2
0
 def get_user_timeline_tweets(self, num_tweets):
     tweets = []
     for tweet in cursor(
             self.twitter_client.user_timeline).items(num_tweets):
         tweets.append(tweet)
     return tweets
import tweepy
import.time


auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

user=api.me

def limit_handler(cursor):
    try:
        while True:
            yeield cursor.next()
    except:
        time.sleep(300)


search_string="python"
numberofTweets= 2

for tweet in tweepy.cursor(api.search,search_string).items(numberofTweets):
    try:
        tweet.favorite()
        print("I liked that tweet")
    except tweepy.TweepError as e:
        print(e.reason)
    except stopIteration:
        break
Beispiel #4
0
    for follower in the_followers:
        try:
            api.create_friendship(follower)
            counter+=1
        except tweepy.error.TweepError:
            pass
    print("You've just followed (or requested to follow) %d new people" %counter)
    
    
#Follow back people who have retweeted a specific tweet
def follow_rtrs(tweet_id, api):
	"""
	This function follows users that have retweeted a tweet, you just need to 
	put the tweet id in. The idea is that you can target tweets similar
	to yours and if you follow people who follow that account, they will
	be more likely to follow you back. You can also target tweets that 
	connect follow backs as a quick way to build your follower count.
	"""
    rtrs = tweepy.cursor(api.retweeters, id =tweet_id, max_follows = 75)
    user_ids =[]
    counter = 0
    tweets = tweepy.Cursor(api.search, q='follow all rt OR retweet').items(2)
    
    while counter < max_follows:
        for user_id in rtrs:
            user_ids.append(user_id)
        counter+=1
        
        
        
        
Beispiel #5
0
access_token_secret = ""

auth = tweepy.OAuthHandler(consumer_key,consumer_key_secret)

auth.set_access_token(access_token,access_token_secret)

api = tweepy.API(auth)

def percentage(part,whole):
    return 100 * float(part)/float(whole)

x = str(input("Enter Keyword"))
n = int(input("Enter number of tweets to be analyzed"))


tweets = tweepy.cursor(api.search,q=x).items(n)

positive,negative,neutral,polarity = 0


for tweet in tweets:
    
    print(tweet.text)
    
    analysis = TextBlob(tweet.text)
    pol = analysis.sentiment.polarity
    
    polarity + = pol

    
    if(pol>0):
Beispiel #6
0
import tweepy
import time
import os
# print(os.environ.get('consumer_key'))

auth = tweepy.OAuthHandler("", "")
auth.set_access_token("", "")

api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)

user = api.me()

search = "Python"
nrTweets = 100

for tweet in tweepy.cursor(api.search, search).items(nrTweets):
    try:
        print('tweet liked')
        tweet.favorite()
        time.sleep(5)
    except tweepy.TweepError as e:
        print(e.reason)
    except StopAsyncIteration:
        break
Beispiel #7
0
import tweepy
import time

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)
user = api.me()

def limit_handler(cursor):
    try:
        while True:
            yield cursor.next()
    except tweepy.RateLimitError:
        time.sleep(1)
for follower in limit_handler(tweepy.cursor(api.followers).items()):
    if follower.name == 'username':
        follower.follow()
        break