pythontwittertweepyfeedparser

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. 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"]])

Solution

  • Actually managed to do it quite easily. I just created:

    twitter_review = review["title"] + "\n" "Full review on: " + review["link"]
    

    And then used:

    tweet(api, twitter_review)
    

    Then it worked!