python返回响应作为字符串或未定义
从在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论