2

How would you insert the ability to like the posts re-tweeted, along with follow the users that posted.

naughty_words = [" -RT"]
good_words = ["CSGO", "skins", "csgo giveaway" "csgogiveaway",      "CSGOGiveaway", "Giveaway"]
filter = " OR ".join(good_words)
blacklist = " -".join(naughty_words)
keywords = filter + blacklist

twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)

search_results = twitter.search(q=keywords, count=20)
try:
    for tweet in search_results["statuses"]:
        try:
            twitter.retweet(id = tweet["id_str"])

        except TwythonError as e:
            "print e"
except TwythonError as e:
    "print e"

1 Answers1

1

To like a tweet when you know its id, use:

twitter.create_favorite(id=tweet_id)

To follow the user that tweeted the tweet:

tweet = twitter.show_status(id=tweet_id)
twitter.create_friendship(user_id=tweet['user']['id'])

EDIT: You can follow the user in one line if you wish, by replacing 'tweet' with the code we used to retrieve the tweet. I've tested it and it does work:

twitter.create_friendship(user_id=twitter.show_status(id=tweet_id)['user']['id'])
James Vickery
  • 732
  • 3
  • 10
  • 23