def fetch_tweets()

in social-media/gather-data.py [0:0]


def fetch_tweets(twitter_handle):
    with codecs.open(output_file_name, 'w', 'utf-8') as output_file_handle:
        global sleep_before_get_search
        max_id = -1
        count = 0
        search_query = '@' + twitter_handle + ' -from:' + twitter_handle
        while count < max_tweets:
            if sleep_before_get_search:
                sleep_then_update_flags()
            if max_id == -1:
                statuses = twitter_api.GetSearch(
                    term=search_query, count=100, result_type='recent')
            else:
                statuses = twitter_api.GetSearch(
                    term=search_query, count=100, result_type='recent', max_id=max_id - 1)
            sleep_before_get_search = True
            if len(statuses) == 0:
                print("No more search results found.")
                break
            for status in statuses:
                # print a '.' for each tweet that is downloaded
                sys.stdout.write(".")
                sys.stdout.flush()
                if max_id == -1:
                    max_id = status.id
                else:
                    max_id = min(max_id, status.id)
                if process_status(status, output_file_handle):
                    count = count + 1
        print("{0} tweets downloaded.".format(count))
        print("See file {0} for tweets".format(output_file_name))