I'm beginner with python. I'm using the twitter API with tweepy for a school project that aims to retrieve information from users whose username I enter. Moreover I want to calculate the age of the account by subtracting the current date from the date of creation of the twitter account that I get via the API. However I have the error message : TypeError: can't subtract offset-naive and offset-aware datetimes
tweets = item.statuses_count
account_created_date = item.created_at
delta = datetime.utcnow() - account_created_date
account_age_days = delta.days
print("Account age (in days): " + str(account_age_days))
if account_age_days > 0:
print("Average tweets per day: " + "%.2f"%(float(tweets)/float(account_age_days)))
The format of the creation date of the account that I retrieve is as follows:
Created_account_date : 2009-06-02 20:12:29+00:00
I suppose the problem comes from the timezone but I'm not sure at all and I don't know how to do it. I thought of using replace() to delete the timezone but I can't perform any action on the variable of the account creation date.
I found a lot of answers on the internet but they don't work/or I don't understand them
Would you have a solution please?