0

I want to write script which writes stream/tweets to the file with 500Kb size. When it reaches certain size close that file and create new file (500Kb).

code is below which i wrote and it gives error:

import os
import tweepy
import Credentials


class streamo(tweepy.Stream):

    def __init(self):
        self._file_index = 0

    def on_data(self, data):
        
        tweets_file = 'C:\\Users\\xxxx\\PycharmProjects\\pythonProject2\\Raw_tweets{}.json'.format(self._file_index)


        while os.path.exists(tweets_file) and os.stat(tweets_file).st_size > 2 ** 10:
            self._file_index += 1
            tweets_file = 'C:\\Users\\xxxxx\\PycharmProjects\\pythonProject2\\Raw_tweets{}.json'.format(self._file_index)

streamer = streamo(
  Credentials.consumerKey, Credentials.consumerSecret,
  Credentials.accessToken, Credentials.accessTokenSecret
)

word = input("Enter stream object: ")
result = streamer.filter(track=[word])


File "C:/Users/xxxx/PycharmProjects/pythonProject2/Test Area.py", line 13, in on_data
    tweets_file = 'C:\\Users\\xxx\\PycharmProjects\\pythonProject2\\Raw_tweets{}.json'.format(self._file_index)

It gives error:

AttributeError: 'streamo' object has no attribute '_file_index'

Emturk
  • 1

0 Answers0