Python Forum

Full Version: I cant find the location of my csv file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all, I wrote and saved a program using tweepy to stream the twitter api,I used csv file in saving but cant find the location anywhere on my computer. Below is the code.

class Listener(StreamListener):
    def on_data(self,data):
        try:
            print(data)
#cleaning up tweets to get only the time and text
            tweet=data.split(',"text":"')[1].split('","source')[0]
            print (tweet)
            saveThis=str(time.time())+"::"+tweet
#saving stream data to csv file
            saveFile=open('twitDB2.csv', 'a')
            saveFile.write(saveThis)
            saveFile.write('\n')
            saveFile.close()
            return (True)
        except BaseException as e:
            print ('failed ondata,',str(e))
            time.sleep(5)
.
The program does not indicate any error but is not splitting the tweets as expected, secondly I cant find the location of TwitDB2.Am using python 3.6.

Thanks in advanced
if this is your entire code, this is just class definition. you never instantiate it or call the method on_data()
Thanks buran,I will do that next time. The compete code is as follows:

from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
Import time

ckey=''
csecret=''
atoken=''
asecret=''

#This is the basic listener that just prints the received tweets. 
class Listener(StreamListener):
    def on_data(self,data):
        try:
         print(data)
#cleaning up tweets to get only the time and text
 tweet=data.split(',"text":"')[1].split('","source')[0]
         print (tweet)
         saveThis=str(time.time())+"::"+tweet
#saving stream data to csv file
         saveFile=open('twitDB2.csv', 'a')
         saveFile.write(saveThis)
         saveFile.write('\n')
         saveFile.close()
         return (True)
        except BaseException as e:
            print ('failed ondata,',str(e))
            time.sleep(5)
    
    def on_error(self,status):
        print (status)
auth=OAuthHandler(ckey,csecret)
auth.set_access_token(atoken, asecret)
twitterStream= Stream(auth, Listener())
twitterStream.filter(track=['car'])
it should be in your current working directory - i.e. where you have started the script from.
you better use with context manager to handle open/close file operations