En Reddit, un redditor es el término dado a un usuario. Reddit nos brinda la funcionalidad de agregar un redditor como amigo del usuario autenticado. Aquí veremos cómo hacerse amigo de un redditor. Usaremos el friend()
método de la Redditor
clase para hacernos amigos de un redditor.
amigo()
Sintaxis: Redditor.friend (nota)
Parámetro:
- nota: agrega una nota a la amistad, requiere Reddit Premium, es opcional
Devoluciones: Nada
Ejemplo 1: Considere el siguiente redditor:
El nombre de usuario del redditor es: spez
# importing the module import praw # 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) # before using the friend() method print("Are the authenticated user and " + redditor.name + " friends? : " + str(redditor.is_friend)) # befriending the redditor redditor.friend() # after using the friend() method print("Are the authenticated user and " + redditor.name + " friends? : " + str(redditor.is_friend))
Producción :
Are the authenticated user and spez friends? : False Are the authenticated user and spez friends? : True
Ejemplo 2: Considere el siguiente redditor:
El nombre de usuario del redditor es: AutoModerador
# importing the module import praw # 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) # before using the friend() method print("Are the authenticated user and " + redditor.name + " friends? : " + str(redditor.is_friend)) # befriending the redditor redditor.friend() # after using the friend() method print("Are the authenticated user and " + redditor.name + " friends? : " + str(redditor.is_friend))
Producción :
Are the authenticated user and AutoModerator friends? : False Are the authenticated user and AutoModerator friends? : True