Python PRAW: obtener la hora en que un redditor creó su cuenta

En Reddit, un redditor es el término dado a un usuario. Aquí veremos cómo obtener la hora exacta en que un redditor creó su cuenta. Usaremos el created_utcatributo de la Redditorclase para obtener la hora de Unix cuando el redditor creó su cuenta.

Ejemplo 1: Considere el siguiente redditor:

El nombre de usuario del redditor es: 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)))

Producción :

The spez account was created on Unix time : 1118030400.0
The spez account was created on : 2005-06-06 09:30:00

Ejemplo 2: Considere el siguiente redditor:

El nombre de usuario del redditor es: AutoModerador

# 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)))

Producción :

The AutoModerator account was created on Unix time : 1325741068.0
The AutoModerator account was created on : 2012-01-05 10:54:28

Publicación traducida automáticamente

Artículo escrito por Yash_R y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *