【问题标题】:PRAW Get message author?PRAW 获取消息作者?
【发布时间】:2016-12-10 23:51:39
【问题描述】:

当我在 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 或 reddit 的文档中找到消息传递实用程序——这不是他们所做的
  • 所以我不能那样做。那我应该抓取数据吗?
  • 不,我是说通知栏。如果我误解了你的问题,那么你应该学习How to Ask 以及如何创建minimal reproducible example
  • Main() 不是一个类,所以不要大写它的名字。它违反了 Python 的官方风格指南 PEP 8。

标签: python reddit praw


【解决方案1】:

我不知道你怎么在 PRAW 文档中找不到它,因为快速谷歌搜索“praw author”给了我这个Stack Overflow 答案。

评论有一个author 属性,它是一个Redditor 对象。要从Redditor 对象中获取名称,请使用其name 属性。

编辑:所以你要做的是用msg.author.name替换'Author here'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-08
    • 2018-03-20
    • 2021-07-26
    • 2022-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-21
    相关资源
    最近更新 更多