PRAW 获取消息作者?
PRAW Get message author?
我正在尝试构建一个当我在 Reddit 上收到消息时在我的设备上显示警报并告诉它作者的消息。像这样:
我尝试搜索 Reddit 的文档,但我没有找到任何关于此事的信息,包括 PRAW 的文档、Reddit 的 API 文档以及他们的 Subreddit。我什至尝试了 messages.author
但这也没有成功。我想要得到的是: 到目前为止,代码如下所示:
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 如何使用 PRAW 获取消息作者
编辑:图片仅用于显示目前的进度
谢谢!
我不知道您是如何在 PRAW 文档中找不到它的,因为快速 google 搜索 "praw author" 给了我这个 Stack Overflow 答案。
一条评论有一个author
属性,它是一个Redditor
对象。要从 Redditor
对象获取名称,请使用其 name
属性。
编辑:所以你要做的是用 msg.author.name
替换 'Author here'
我正在尝试构建一个当我在 Reddit 上收到消息时在我的设备上显示警报并告诉它作者的消息。像这样:
我尝试搜索 Reddit 的文档,但我没有找到任何关于此事的信息,包括 PRAW 的文档、Reddit 的 API 文档以及他们的 Subreddit。我什至尝试了 messages.author
但这也没有成功。我想要得到的是:
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 如何使用 PRAW 获取消息作者
编辑:图片仅用于显示目前的进度 谢谢!
我不知道您是如何在 PRAW 文档中找不到它的,因为快速 google 搜索 "praw author" 给了我这个 Stack Overflow 答案。
一条评论有一个author
属性,它是一个Redditor
对象。要从 Redditor
对象获取名称,请使用其 name
属性。
编辑:所以你要做的是用 msg.author.name
'Author here'