简体   繁体   English

使用 tweepy 格式化来自 python 的推文

[英]Formatting a tweet from python using tweepy

I'm trying to tweet my movie reviews from Letterboxd using python's tweepy but I can't format the tweet.我正在尝试使用 python 的 tweepy 从 Letterboxd 发布我的电影评论,但我无法格式化推文。 I tried printing the tweet without the square brackets or printing the title and link to the full review in different lines, but couldn't achieve either.我尝试在不带方括号的情况下打印推文,或在不同行中打印标题和完整评论的链接,但都无法实现。 Is it possible to do either thing?有可能做任何一件事吗?

Here's the code I'm using:这是我正在使用的代码:

import tweepy
import xxxx_keys
import feedparser

feed = feedparser.parse("https://example.rss")


def api():
    auth = tweepy.OAuth1UserHandler(xxxx.api_key, xxxx.api_key_secret)
    auth.set_access_token(xxxx.access_token, xxxx.access_token_secret)

    return tweepy.API(auth)


review = {
    "title": feed.entries[0].title,
    "summary": feed.entries[0].summary,
    "link": feed.entries[0].link,
    "description": feed.entries[0].description,
}


def tweet(api: tweepy.API, message: str, image_path=None):
    if image_path:
        api.update_status_with_media(message, image_path)
    else:
        api.update_status(message)

    print("Tweet sent successfully")


if __name__ == "__main__":
    api = api()
    tweet(api, [review["title"], "Full review on: ", review["link"]])

Actually managed to do it quite easily, just created twitter_review = review["title"] + "\n" "Full review on: " + review["link"], and then used the tweet(api, twitter_review).实际上很容易做到,只需创建 twitter_review = review["title"] + "\n" "Full review on: " + review["link"],然后使用 tweet(api, twitter_review)。 It worked!有效!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM