3

I am doing some study about park evaluation, and I used twitter api to grab some tweets about parks in London. I can get the text, user id and followers etc., and cannot get the twitter_time. the error is ''Tweet' object has no attribute 'created_at''.(created_at actually existed in the list twitter returned)

I used python in jupyter notebook

load_credentials(filename="./search_tweets_creds_example.yaml",
             yaml_key="search_tweets_ent_example",
             env_overwrite=False)
{'username': '<MY_USERNAME>',
'password': '<MY_PASSWORD>',
'endpoint': '<MY_ENDPOINT>'}

premium_search_args = load_credentials("~/.twitter_keys.yaml",
                                   yaml_key="search_tweets_premium",
                                   env_overwrite=False)

rule = gen_rule_payload("#Regentpark", results_per_call=100) # testing with a sandbox account
 print(rule)
 from searchtweets import collect_results
 import numpy as np
 import pandas as pd
 import csv
 df = pd.DataFrame(columns = ['Tweets', 'User', 
                         'fav_count', 'rt_count'])

 def stream(file_name):
i = 0
for tweet in collect_results(rule,
                     max_results=1000,
                     result_stream_args=premium_search_args):
    print(i, end='\r')
    df.loc[i, 'Tweets'] = tweet.text
    df.loc[i, 'User'] = tweet.id
    df.loc[i, 'fav_count'] = tweet.favorite_count
    df.loc[i, 'rt_count'] = tweet.retweet_count
    df.loc[i,'tweet_data']=tweet.created_at
    df.to_excel('{}.xlsx'.format(file_name))
    i+=1
    if i == 1000:
        break
    else:
        pass
    stream(file_name='Regentpark')

AttributeError: 'Tweet' object has no attribute 'created_at'

TCAO
  • 31
  • 2

1 Answers1

1

In the API example notebook for the package they use:

tweet.created_at_datetime

which also works fine for me. Here is a link to the example: https://github.com/twitterdev/search-tweets-python/blob/master/examples/api_example.ipynb

Bomada
  • 21
  • 2