2021年4月2日星期五

Watchdog function to create new timestamped document every week?

Long time listener, first time poster. So I'm trying to use watchdog to monitor the downloads folder for changes, and whenever it detects two files that meet a certain set of conditions (conditions not included in the code below, I'll add that later), it'll create a new timestamped document that is a combination of the two files. The two documents will be downloaded once a week. The problem I'm having now is that when I run the code from the terminal or VScode, it creates one document per run. Instead of creating a new document every time the documents are uploaded (once a week), it will create a new one, and then update it with new incoming information once those documents are uploaded. The document's name stays the same, but the actual "date modified" time in windows explorer changes.

Here's what I have now:

downloads_folder = os.getcwd()    def on_created(event):      print('created')    if __name__ == '__main__':      event_handler = FileSystemEventHandler()        observer = Observer()      observer.schedule(event_handler, downloads_folder, recursive=True)        observer.start()            try:          print('Monitor')            # produce the relevant dataframe          dafr = pd.DataFrame({'A':[1,2,3]})            # define vars for naming convention          current = datetime.datetime.now()          date = str(current.month)+'-'+str(current.day)          name = str(current.month)+'-'+str(current.day)+' dafr.csv'                 # count the number of docs in cwd with that date            while True:              time.sleep(10)              dafr.to_csv(name, index=False)        finally:          observer.stop()          print('Done')      observer.join()```  
https://stackoverflow.com/questions/66860672/watchdog-function-to-create-new-timestamped-document-every-week March 30, 2021 at 03:46AM

没有评论:

发表评论