1

I have a bot that searches and retweets tweets. But I do not want to retweet it is written from Turkey.

I can't figure out how to do this, I've been dealing with this for a week. We have code that search in a specific country, but no code that excludes a specific country.

First of all, it is necessary to find the user's country and check whether it is Turkey. This is all I can think of. I don't know how and where to start, can anyone help?

api = tweepy.API(auth)
places = api.geo_search(query="Turkey",granularity="country")
place_id = places[0].id
tweets = api.search(q="place:%s" % place_id)

If I use this code can only find tweets in Turkey.

This is my code:

import tweepy
import time

auth = tweepy.OAuthHandler('','')
auth.set_access_token('','')


api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
user = api.me()

import time
time_limit_sec = 600
start_time = time.time()


for tweet in tweepy.Cursor(api.search, q="books", result_type="recent").items(120):
    if (time.time()-start_time) > time_limit_sec:
        break
    print (tweet.id)
    status = api.get_status(tweet.id)
    favorited = status.retweeted
    if favorited == True: 
        print("tweet is favorited")
        time.sleep(5)
    else:
        print("tweet is not favorited") 
        try: 
            print('favorite')
            tweet.retweet()
            time.sleep(10)
        except tweepy.TweepError as e:
            print(e.reason)
        except StopIteration:
            break
Alex Aka
  • 11
  • 2

0 Answers0