I am getting data from Twitter with Tweepy and using Stream API… Here is my t_stream.py file:
access_token = "my token"
access_token_secret = "my t_secret"
consumer_key = "my key"
consumer_secret = "my c_secret"
class StdOutListener(StreamListener):
def on_data(self, raw_data):
data = json.loads(raw_data)
print(json.dumps(data, ensure_ascii=False))
def on_error(self, status):
print (status)
if __name__ == '__main__':
dinle = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, dinle)
I have a file called veri.txt when i use code:
python3 t_stream.py > veri.txt
Here is a part of result data: https://paste.pound-python.org/show/SiUalejehr6T8BEvYOpw/
From this veri.txt file, i want to get information like:
retweet_count:
followers_count:
name:
text:
and i want to store these coloumns as an output csv file…
I tried some codes but it didnt work. So i am asking a python code for reading a text file line by line, getting the information which i mentioned above from the line and storing them as coloumn in data file as a csv file. Can someone help me about this subject? Thank you.
2
Answers
some example from the python3 docs:
Not a python example, but you can do this with jq filters pretty easy piping the output of the stream.