python返回响应作为字符串或未定义

发布于 2025-02-09 13:43:56 字数 1293 浏览 3 评论 0原文

在github 上找到。

试图调整用于将最近的推文作为新帖子发布到Subreddit的新帖子的代码,而是将最近推文的内容作为评论。

如果我使用Github的代码来发表帖子,这项工作。如果我适应了评论,我最终会得到一个字符串响应,该响应显示了replast> reams_template ='tweet',而不是显示被拉入的推文。

def get_last_tweet(self):
    tweet = self.user_timeline(user_id="XXXXXXXX", count=1, tweet_mode="extended")[0]
    print('tweet')
    return tweet

REPLY_TEMPLATE = tweet

def process_submission(submission):
    # Ignore titles for any thread with the same title that is not pinned
    if not submission.stickied:
        return

    normalized_title = submission.title.lower()
    for active_daily in POST:
        if active_daily in normalized_title:
            url_title = quote_plus(submission.title)
            reply_text = REPLY_TEMPLATE.format(url_title)
            print(f"Replying to: {submission.title}")
            submission.reply(body=reply_text)

我也在下面尝试了这一点。但是我得到name error:名称'tweet'未定义错误

def get_last_tweet(self):
    global tweet
    tweet = self.user_timeline(user_id="XXXXXXXX", count=1, tweet_mode="extended")[0]
print('tweet')


REPLY_TEMPLATE = tweet

Adapted below from this found on GitHub.

Trying to adapt the code meant for posting a recent tweet as a new post to a Subreddit to instead post the contents of the recent tweet as a comment.

This work if I use the code from GitHub to make a post. If I adapt for a comment I end up with a string response that says "tweet" like this REPLY_TEMPLATE = 'tweet' , instead of displaying the tweet that was pulled in.

def get_last_tweet(self):
    tweet = self.user_timeline(user_id="XXXXXXXX", count=1, tweet_mode="extended")[0]
    print('tweet')
    return tweet

REPLY_TEMPLATE = tweet

def process_submission(submission):
    # Ignore titles for any thread with the same title that is not pinned
    if not submission.stickied:
        return

    normalized_title = submission.title.lower()
    for active_daily in POST:
        if active_daily in normalized_title:
            url_title = quote_plus(submission.title)
            reply_text = REPLY_TEMPLATE.format(url_title)
            print(f"Replying to: {submission.title}")
            submission.reply(body=reply_text)

I tried this below as well, but I get a NameError: name 'tweet' is not defined error

def get_last_tweet(self):
    global tweet
    tweet = self.user_timeline(user_id="XXXXXXXX", count=1, tweet_mode="extended")[0]
print('tweet')


REPLY_TEMPLATE = tweet

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文