Python Forum
I cant find the location of my csv file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I cant find the location of my csv file
#1
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
Reply
#2
if this is your entire code, this is just class definition. you never instantiate it or call the method on_data()
Reply
#3
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'])
Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 1,594 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  Cannot find py credentials file standenman 5 1,666 Feb-25-2023, 08:30 PM
Last Post: Jeff900
  selenium can't find a file in my desk ? SouAmego22 0 751 Feb-14-2023, 03:21 PM
Last Post: SouAmego22
  Find (each) element from a list in a file tester_V 3 1,239 Nov-15-2022, 08:40 PM
Last Post: tester_V
  Changing file location azizrasul 6 1,315 Sep-28-2022, 01:01 AM
Last Post: azizrasul
  what will be the best way to find data in txt file? korenron 2 1,172 Jul-25-2022, 10:03 AM
Last Post: korenron
  find some word in text list file and a bit change to them RolanRoll 3 1,550 Jun-27-2022, 01:36 AM
Last Post: RolanRoll
  Find and delete above a certain line in text file cubangt 12 3,512 Mar-18-2022, 07:49 PM
Last Post: snippsat
Question Help to find the largest int number in a file directory SalzmannNicholas 1 1,644 Jan-13-2022, 05:22 PM
Last Post: ndc85430
Thumbs Up [SOLVED] Find last occurence of pattern in text file? Winfried 4 4,428 Aug-13-2021, 08:21 PM
Last Post: Winfried

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020