Python Forum
I cant find the location of my csv file - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: I cant find the location of my csv file (/thread-7267.html)



I cant find the location of my csv file - Ummusabbar - Jan-01-2018

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


RE: I cant find the location of my csv file - buran - Jan-01-2018

if this is your entire code, this is just class definition. you never instantiate it or call the method on_data()


RE: I cant find the location of my csv file - Ummusabbar - Jan-04-2018

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'])



RE: I cant find the location of my csv file - buran - Jan-04-2018

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