Python PRAW – 获取 redditor 创建帐户的时间
在 Reddit 中,redditor 是给予用户的术语。在这里,我们将看到如何获取 redditor 创建帐户的确切时间。我们将使用Redditor
类的created_utc
属性来获取 Redditor 创建帐户时的 Unix 时间。
示例 1:考虑以下 redditor:
redditor 的用户名是:spez。
# importing the module
import praw
from datetime import datetime
# initialize with appropriate values
client_id = ""
client_secret = ""
username = ""
password = ""
user_agent = ""
# creating an authorized reddit instance
reddit = praw.Reddit(client_id = client_id,
client_secret = client_secret,
username = username,
password = password,
user_agent = user_agent)
# the name of the redditor
redditor_name = "spez"
# instantiating the Redditor class
redditor = reddit.redditor(redditor_name)
# fetching the Unix time of creation
unix_time = redditor.created_utc
print("The " + redditor_name + " account was created on Unix time : " +
str(unix_time))
# converting the Unix time
print("The " + redditor_name + " account was created on : " +
str(datetime.fromtimestamp(unix_time)))
输出 :
The spez account was created on Unix time : 1118030400.0
The spez account was created on : 2005-06-06 09:30:00
示例 2:考虑以下 redditor:
redditor 的用户名是:AutoModerator
# importing the module
import praw
from datetime import datetime
# initialize with appropriate values
client_id = ""
client_secret = ""
username = ""
password = ""
user_agent = ""
# creating an authorized reddit instance
reddit = praw.Reddit(client_id = client_id,
client_secret = client_secret,
username = username,
password = password,
user_agent = user_agent)
# the name of the redditor
redditor_name = "AutoModerator"
# instantiating the Redditor class
redditor = reddit.redditor(redditor_name)
# fetching the Unix time of creation
unix_time = redditor.created_utc
print("The " + redditor_name + " account was created on Unix time : " +
str(unix_time))
# converting the Unix time
print("The " + redditor_name + " account was created on : " +
str(datetime.fromtimestamp(unix_time)))
输出 :
The AutoModerator account was created on Unix time : 1325741068.0
The AutoModerator account was created on : 2012-01-05 10:54:28