En Reddit, podemos publicar un comentario en cualquier envío, también podemos comentar un comentario para crear un hilo de comentarios. Aquí veremos cómo obtener la hora exacta en que se publicó un comentario usando PRAW. Usaremos el created_utc
atributo de la Comment
clase para obtener la hora de Unix cuando se publicó el comentario.
Ejemplo 1: Considere el siguiente comentario:
El ID del comentario es: fvib7aw
# 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 ID of the comment comment_id = "fvib7aw" # instantiating the Comment class comment = reddit.comment(comment_id) # fetching the Unix time unix_time = comment.created_utc print("The comment was posted on Unix time : " + str(unix_time)) # converting the Unix time print("The comment was posted on : " + str(datetime.fromtimestamp(unix_time)))
Producción :
The comment was posted on Unix time : 1592712950.0 The comment was posted on : 2020-06-21 09:45:50
Ejemplo 2: Considere el siguiente comentario:
El ID del comentario es: fv9qvgo
# 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 ID of the comment comment_id = "fv9qvgo" # instantiating the Comment class comment = reddit.comment(comment_id) # fetching the Unix time unix_time = comment.created_utc print("The comment was posted on Unix time : " + str(unix_time)) # converting the Unix time print("The comment was posted on : " + str(datetime.fromtimestamp(unix_time)))
Producción :
The comment was posted on Unix time : 1592513850.0 The comment was posted on : 2020-06-19 02:27:30