Accessing enterprise search API #519

Open
opened 2019-07-14 18:07:39 -07:00 by tolgaouz · 0 comments
tolgaouz commented 2019-07-14 18:07:39 -07:00 (Migrated from github.com)

I want to use enterprise search api for this because I want to define fromDate and toDate parameters.

I couldn't find any way to do it though, and when I try to cursor tweets from this date, It only returns the tweets about 14 days ago from now.

twitter = Twython(consumer_token, access_token=ACCESS_TOKEN)

Search parameters

def search_query(QUERY_TO_BE_SEARCHED):
"""
QUERY_TO_BE_SEARCHED : text you want to search for
"""
df_dict=[]

results = twitter.cursor(twitter.search, q=QUERY_TO_BE_SEARCHED,fromDate='2019071200',toDate='2019071400',count=100)
for q in results:
    retweet_count = q['retweet_count']
    favs_count = q['favorite_count']
    date_created = q['created_at']
    text = q['text']
    hashtags = q['entities']['hashtags']
    user_name = '@'+str(q['user']['screen_name'])
    user_mentions = []
    if(len(q['entities']['user_mentions'])!=0):
        for n in q['entities']['user_mentions']:
            user_mentions.append(n['screen_name']) # Mentioned profile names in the tweet
    temp_dict = {'User ID':user_name,'Date':date_created,'Text':text,'Favorites':favs_count,'RTs':retweet_count,
                'Hashtags':hashtags,'Mentions':user_mentions}
    df_dict.append(temp_dict)

return pd.DataFrame(df_dict)

that is my code, can you help me improve this ?

I want to use enterprise search api for this because I want to define fromDate and toDate parameters. I couldn't find any way to do it though, and when I try to cursor tweets from this date, It only returns the tweets about 14 days ago from now. > > twitter = Twython(consumer_token, access_token=ACCESS_TOKEN) > # Search parameters > def search_query(QUERY_TO_BE_SEARCHED): > """ > QUERY_TO_BE_SEARCHED : text you want to search for > """ > df_dict=[] > > results = twitter.cursor(twitter.search, q=QUERY_TO_BE_SEARCHED,fromDate='2019071200',toDate='2019071400',count=100) > for q in results: > retweet_count = q['retweet_count'] > favs_count = q['favorite_count'] > date_created = q['created_at'] > text = q['text'] > hashtags = q['entities']['hashtags'] > user_name = '@'+str(q['user']['screen_name']) > user_mentions = [] > if(len(q['entities']['user_mentions'])!=0): > for n in q['entities']['user_mentions']: > user_mentions.append(n['screen_name']) # Mentioned profile names in the tweet > temp_dict = {'User ID':user_name,'Date':date_created,'Text':text,'Favorites':favs_count,'RTs':retweet_count, > 'Hashtags':hashtags,'Mentions':user_mentions} > df_dict.append(temp_dict) > > return pd.DataFrame(df_dict) that is my code, can you help me improve this ?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: code/twython#519
No description provided.