def load_tweets(**kwargs):
    args = dict(count=20, q=Search_key)
    args.update(**kwargs)
    url = 'https://api.twitter.com/1.1/search/tweets.json?' + urlencode(args)
    user_timeline = TweetOuth.tweet_req(url) 
    tweets=json.loads(user_timeline.decode('utf-8'))
    if type(tweets) == dict and u'errors' in tweets:
        if repeat and tweets[u'errors'][0]["code"]==88:
            print(tweets[u'errors'][0]["message"],file=sys.stderr)
            time.sleep(1000)
            return load_tweets(**kwargs)
        if tweets[u'errors'][0]["code"] in (32,89,99):
            raise InvalidTokenError(tweets[u'errors'][0]['message'])
        if tweets[u'errors'][0]["code"]==88:
            raise OverflowError(tweets[u'errors'][0]['message'])
        raise Exception(tweets[u'errors'][0]['message'])
    for twit in tweets[u'statuses']:
        c.execute('INSERT INTO tweet (user, tweet_id, created, text, source, screan_name, description) VALUES (?, ?, ?, ?, ?, ?, ?)',
            (twit[u'user'][u'name'],
             twit['id'],
            time.mktime(rfc822.parsedate(twit['created_at'])),
            twit['text'],
            twit['source'],
            twit[u'user'][u'screen_name'],
            twit[u'user'][u'description']))
    c.commit()
    return len(tweets[u'statuses'])
Exemple #2
0
def getSearchTweet(Search_key, **kwargs):
    """
    Search twiiter with with specified key
    getSearchTweet(Search_key,,count=100,since_id='twitter id',max_id='twitter id')
    """
    args = dict(count=100, q=Search_key)
    args.update(**kwargs)
    url = 'https://api.twitter.com/1.1/search/tweets.json?' + urlencode(args)
    user_timeline = TweetOuth.tweet_req(url)
    return json.loads(user_timeline)
def tweet_follower():
    global FollowersList,screen_name
    follow=TweetOuth.tweet_req('https://api.twitter.com/1.1/followers/ids.json?'+urlencode_utf8({'cursor':-1,'screen_name':screen_name,'count':5000}))
    result=json.loads(follow)
    follow_ids=result[u'ids']
    while result[u'next_cursor']:
        follow=TweetOuth.tweet_req('https://api.twitter.com/1.1/followers/ids.json?'+urlencode_utf8({'cursor':result[u'next_cursor'],'screen_name':screen_name,'count':5000}))
        result=json.loads(follow)
        follow_ids+=result[u'ids']
    follow_list=follow_ids
    while follow_list:
        req_list=str(follow_list[0])
        for i in follow_list[1:100]:
            req_list+=','+str(i)
        lookup=TweetOuth.tweet_req('https://api.twitter.com/1.1/users/lookup.json?user_id='+req_list)
        lookup_result=json.loads(lookup)
        for i in lookup_result:
            FollowersList.append([str(i[u'id']),i[u'name'],i[u'screen_name'],str(i[u'followers_count']),str(i[u'friends_count'])])
        follow_list=follow_list[100:]
def getTweetFromList(screen_name,slug,**kwargs):
    """
    Get tweet from a specific twitter list
    getTweetFromList(screen_name,slug,count=100,since_id='twitter id',max_id='twitter id')
    """
    args = dict(count=180, slug=slug,owner_screen_name=screan_name)
    args.update(**kwargs)
    url = 'https://api.twitter.com/1.1/lists/statuses.json?' + urlencode(args)
    user_timeline = TweetOuth.tweet_req(url) 
    return json.loads(user_timeline)
def getUserTweet(screen_name,**kwargs):
    """
    Get tweets from specific user time line
    getUserTweet(screen_name,count=100,since_id='twitter id',max_id='twitter id')
    """
    args = dict(count=100, trim_user=1, screen_name=screen_name)
    args.update(**kwargs)
    url = 'https://api.twitter.com/1.1/statuses/user_timeline.json?' + urlencode(args)
    user_timeline = TweetOuth.tweet_req(url) 
    return json.loads(user_timeline)
def getSearchTweet(Search_key,**kwargs):
    """
    Search twiiter with with specified key
    getSearchTweet(Search_key,,count=100,since_id='twitter id',max_id='twitter id')
    """
    args = dict(count=100, q=Search_key)
    args.update(**kwargs)
    url = 'https://api.twitter.com/1.1/search/tweets.json?' + urlencode(args)
    user_timeline = TweetOuth.tweet_req(url) 
    return json.loads(user_timeline)
Exemple #7
0
def tweet_follower():
    global FollowersList,screen_name
    follow=TweetOuth.tweet_req('https://api.twitter.com/1.1/followers/ids.json?'+urlencode_utf8({'cursor':-1,'screen_name':screen_name,'count':5000}))
    result=json.loads(follow)
    follow_ids=result[u'ids']
    while result[u'next_cursor']:
        follow=TweetOuth.tweet_req('https://api.twitter.com/1.1/followers/ids.json?'+urlencode_utf8({'cursor':result[u'next_cursor'],'screen_name':screen_name,'count':5000}))
        result=json.loads(follow)
        follow_ids+=result[u'ids']
    follow_list=follow_ids
    while follow_list:
        req_list=str(follow_list[0])
        for i in follow_list[1:100]:
            req_list+=','+str(i)
        lookup=TweetOuth.tweet_req('https://api.twitter.com/1.1/users/lookup.json?user_id='+req_list)
        lookup_result=json.loads(lookup)
        for i in lookup_result:
            FollowersList.append([str(i[u'id']),i[u'name'],i[u'screen_name'],str(i[u'followers_count']),str(i[u'friends_count'])])
        follow_list=follow_list[100:]
Exemple #8
0
def getTweetFromList(screen_name, slug, **kwargs):
    """
    Get tweet from a specific twitter list
    getTweetFromList(screen_name,slug,count=100,since_id='twitter id',max_id='twitter id')
    """
    args = dict(count=180, slug=slug, owner_screen_name=screan_name)
    args.update(**kwargs)
    url = 'https://api.twitter.com/1.1/lists/statuses.json?' + urlencode(args)
    user_timeline = TweetOuth.tweet_req(url)
    return json.loads(user_timeline)
Exemple #9
0
def getUserTweet(screen_name, **kwargs):
    """
    Get tweets from specific user time line
    getUserTweet(screen_name,count=100,since_id='twitter id',max_id='twitter id')
    """
    args = dict(count=100, trim_user=1, screen_name=screen_name)
    args.update(**kwargs)
    url = 'https://api.twitter.com/1.1/statuses/user_timeline.json?' + urlencode(
        args)
    user_timeline = TweetOuth.tweet_req(url)
    return json.loads(user_timeline)
def load_tweets(**kwargs):
    global reTweetCount,favoriteCount,tweet_max_id
    args = dict( count=100,trim_user=1,include_rts=False, screen_name=screen_name)
    args.update(**kwargs)
    url = 'https://api.twitter.com/1.1/statuses/user_timeline.json?' + urlencode(args)
    user_timeline = TweetOuth.tweet_req(url)
    tweets=json.loads(user_timeline)
    if len(tweets)>0:        
        for twit in tweets:
            reTweetCount+=twit['retweet_count']
            favoriteCount+=twit['favorite_count']
            tweet_max_id=twit['id']
    return len(tweets)-1
Exemple #11
0
def load_tweets(**kwargs):
    args = dict(count=20, trim_user=1, screen_name=screen_name)
    args.update(**kwargs)
    url = 'https://api.twitter.com/1.1/statuses/user_timeline.json?' + urlencode(
        args)
    user_timeline = TweetOuth.tweet_req(url)
    tweets = json.loads(user_timeline)
    if type(tweets) == dict and tweets.has_key(u'errors'):
        raise Exception(tweets[u'errors'])
    for twit in tweets:
        c.execute(
            'INSERT INTO tweet (tweet_id, created, text, source) VALUES (?, ?, ?, ?)',
            (twit['id'], time.mktime(rfc822.parsedate(
                twit['created_at'])), twit['text'], twit['source']))
    c.commit()
    return len(tweets)
Exemple #12
0
def load_tweets(**kwargs):
    args = dict(count=20, trim_user=1, screen_name=screen_name)
    args.update(**kwargs)
    url = 'https://api.twitter.com/1.1/statuses/user_timeline.json?' + urlencode(args)
    user_timeline = TweetOuth.tweet_req(url) 
    tweets=json.loads(user_timeline)
    if type(tweets) == dict and tweets.has_key(u'errors'):
        raise Exception(tweets[u'errors'])
    for twit in tweets:
        c.execute('INSERT INTO tweet (tweet_id, created, text, source) VALUES (?, ?, ?, ?)',
            (twit['id'],
            time.mktime(rfc822.parsedate(twit['created_at'])),
            twit['text'],
            twit['source']))
    c.commit()
    return len(tweets)
def load_tweets(**kwargs):
    args = dict(trim_user=1)
    args.update(**kwargs)
    url = 'https://api.twitter.com/1.1/statuses/show.json?' + urlencode(args)
    user_timeline = TweetOuth.tweet_req(url)
    tweet=json.loads(user_timeline)    
    if type(tweet) == dict and tweet.has_key(u'errors'):
        raise Exception(tweet[u'errors'])         
    print "text: ",tweet[u'text']
    print "hashtags: "
    for twit in range(len(tweet['entities']['hashtags'])):
        print tweet['entities']['hashtags'][twit][u'text']
    print "references: "
    for twit in range(len(tweet['entities']['user_mentions'])):
        print tweet['entities']['user_mentions'][twit][u'screen_name']
    print "Favorite Count: ", tweet['favorite_count']
    print "Retweet Count: ", tweet['retweet_count']
def load_tweets(**kwargs):
    args = dict(trim_user=1)
    args.update(**kwargs)
    url = 'https://api.twitter.com/1.1/statuses/show.json?' + urlencode(args)
    user_timeline = TweetOuth.tweet_req(url)
    tweet = json.loads(user_timeline)
    if type(tweet) == dict and tweet.has_key(u'errors'):
        raise Exception(tweet[u'errors'])
    print "text: ", tweet[u'text']
    print "hashtags: "
    for twit in range(len(tweet['entities']['hashtags'])):
        print tweet['entities']['hashtags'][twit][u'text']
    print "references: "
    for twit in range(len(tweet['entities']['user_mentions'])):
        print tweet['entities']['user_mentions'][twit][u'screen_name']
    print "Favorite Count: ", tweet['favorite_count']
    print "Retweet Count: ", tweet['retweet_count']
Exemple #15
0
def load_tweets(**kwargs):
    global reTweetCount, favoriteCount, tweet_max_id
    args = dict(count=100,
                trim_user=1,
                include_rts=False,
                screen_name=screen_name)
    args.update(**kwargs)
    url = 'https://api.twitter.com/1.1/statuses/user_timeline.json?' + urlencode(
        args)
    user_timeline = TweetOuth.tweet_req(url)
    tweets = json.loads(user_timeline)
    if len(tweets) > 0:
        for twit in tweets:
            reTweetCount += twit['retweet_count']
            favoriteCount += twit['favorite_count']
            tweet_max_id = twit['id']
    return len(tweets) - 1
def load_tweets(**kwargs):
    args = dict(count=20, slug=Slug, owner_screen_name=Screan_name)
    args.update(**kwargs)
    url = 'https://api.twitter.com/1.1/lists/statuses.json?' + urlencode(args)
    user_timeline = TweetOuth.tweet_req(url)
    tweets = json.loads(user_timeline.decode('utf-8'))
    if type(tweets) == dict and u'errors' in tweets:
        raise Exception(tweets[u'errors'])
    for twit in tweets:
        c.execute(
            'INSERT INTO `%s` (user, tweet_id, created, text, source, screan_name, description) VALUES (?, ?, ?, ?, ?, ?, ?)'
            % Slug,
            (twit[u'user'][u'name'], twit['id'],
             time.mktime(rfc822.parsedate(
                 twit['created_at'])), twit['text'], twit['source'],
             twit[u'user'][u'screen_name'], twit[u'user'][u'description']))
    c.commit()
    return len(tweets)
def load_tweets(**kwargs):
    args = dict(count=20, slug=Slug,owner_screen_name=Screan_name)
    args.update(**kwargs)
    url = 'https://api.twitter.com/1.1/lists/statuses.json?' + urlencode(args)
    user_timeline = TweetOuth.tweet_req(url) 
    tweets=json.loads(user_timeline)
    if type(tweets) == dict and tweets.has_key(u'errors'):
        raise Exception(tweets[u'errors'])
    for twit in tweets:
        c.execute('INSERT INTO `%s` (user, tweet_id, created, text, source, screan_name, description) VALUES (?, ?, ?, ?, ?, ?, ?)' % Slug,
            (twit[u'user'][u'name'],
             twit['id'],
            time.mktime(rfc822.parsedate(twit['created_at'])),
            twit['text'],
            twit['source'],
            twit[u'user'][u'screen_name'],
            twit[u'user'][u'description']))
    c.commit()
    return len(tweets)
def load_tweets(**kwargs):
    args = dict(count=20, trim_user=1, screen_name=screen_name)
    args.update(**kwargs)
    url = 'https://api.twitter.com/1.1/statuses/user_timeline.json?' + urlencode(
        args)
    user_timeline = TweetOuth.tweet_req(url)
    tweets = json.loads(user_timeline)
    if type(tweets) == dict and tweets.has_key(u'errors'):
        raise Exception(tweets[u'errors'])
    for twit in tweets:
        if len(twit['entities']['hashtags']) > 0:
            for n in range(len(twit['entities']['hashtags'])):
                c.execute(
                    'INSERT INTO hashtag (tweet_id,tags) VALUES (?,?)',
                    (twit['id'], twit['entities']['hashtags'][n][u'text']))
        else:
            c.execute('INSERT INTO hashtag (tweet_id,tags) VALUES (?,?)',
                      (twit['id'], ""))
    c.commit()
    return len(tweets)