📜  Python Tweepy – 获取推文发布的日期和时间

📅  最后修改于: 2022-05-13 01:55:27.923000             🧑  作者: Mango

Python Tweepy – 获取推文发布的日期和时间

在本文中,我们将了解如何获取发布/发布状态/推文的日期和时间。 Status 对象的 created_at 属性为我们提供了一个 datetime 对象,它告诉我们状态何时发布。

识别在 GUI 中发布状态的日期:

在上述状态中,状态发布于:6月11日

示例 1:考虑以下状态:

我们将使用状态 ID 来获取状态。上述状态的状态 ID 为 1272771459249844224。

# import the module
import tweepy
  
# assign the values accordingly
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
  
# authorization of consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  
# set access to user's access key and access secret 
auth.set_access_token(access_token, access_token_secret)
  
# calling the api 
api = tweepy.API(auth)
  
# the ID of the status
id = 1272771459249844224
  
# fetching the status
user = api.get_status(id)
  
# fetching the created_at attribute
created_at = status.created_at 
  
print("The status was created at : " + str(created_at))

输出 :

The status was created at : 2020-06-16 06:02:17

示例 2:考虑以下状态:

我们将使用状态 ID 来获取状态。上述状态的状态 ID 为 1272479136133627905。

# the ID of the status
id = 1272479136133627905
  
# fetching the status
user = api.get_status(id)
  
# fetching the created_at attribute
created_at = status.created_at 
  
print("The status was created at : " + str(created_at))

输出 :

The status was created at : 2020-06-15 10:40:42