I'm trying to build a when I get a message on Reddit to display an alert on my device and tell it the author. Something like this:
I tried searching for Reddit's documentation but I didn't find anything on the matter including the PRAW's docs, Reddit's API docs, and on their Subreddit. I even tried messages.author
but that didn't work out either. What I want to get is this: So far the code looks like this:
import praw
import time
import os
import pync
from pync import Notifier
print "Booting up..."
def Main():
print "Searching for messages..."
r = praw.Reddit(user_agent='RedditNotifier version 0.0.1')
r.login('username', 'pass')
for msg in r.get_unread(limit=None):
if not msg:
print "True"
else:
Notifier.notify('From:' + 'Author here', title='Reddit: New Message!', open='https://www.reddit.com/message/unread/')
print msg
while True:
Main()
time.sleep(5)
TL;DR How to get message author using PRAW
EDIT: Image only serves to show progress so far Thanks!
I don't know how you couldn't find it in the PRAW docs because a quick google search "praw author" gave me this Stack Overflow answer.
A comment has an author
attribute, which is a Redditor
object. And to get the name from the Redditor
object, use its name
attribute.
EDIT: So what you to do is replace'Author here'
with msg.author.name