Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
watchdog on_modified
#1
I'm creating a desktop application that notifies the user whenever a file has been modified, I've only just started using all of these modules and going through the documentation. Here is my code so far:

import time
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler
from winotify import Notification, audio
import logging
import getpass


def on_modified(event):

    toast.set_audio(audio.Default, loop=False)
    toast.show()



if __name__ == '__main__':

    user = getpass.getuser()
    logging.basicConfig(filename='E:/DataLogging/log.log', filemode='a', level=logging.INFO,
                        format='%(asctime)s - %(message)s' + f' -  user: {user}',
                        datefmt='%Y-%m-%d %H:%M:%S')

    path = 'E:/Datalogging/'

    toast = Notification(app_id="Spreadsheet Notification",
                         title="Spreadsheet Updated",
                         msg=f'{user} has modified the spreadsheet',
                         icon=r'E:/download.jpg')

    event_handler = LoggingEventHandler()
    event_handler.on_modified = on_modified
    observer = Observer()
    observer.schedule(event_handler, path, recursive=True)
    observer.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
        observer.join()
But, I've noticed that the user is notified any time someone opens up, modifies, and closes the file, but I only want the user to be notified whenever it is only modified, and not opened or closed.

Also, I cannot use the path 'E:/DataLogging/test.xlsx' but I can use 'E:/DataLogging/', which is the directory, and not the specific file. I'm sure there is an easy fix for this, but I cannot find the fix yet.

Could someone help me with these 2 issues?

Edit: I've also just been told that the real spreadsheet that will be observed is on a sharepoint google spreadsheet.

Can I use the watchdog observer for an online spreadsheet, or will I need to use a different module?
Reply


Messages In This Thread
watchdog on_modified - by CAD79 - Apr-23-2024, 01:58 PM
RE: watchdog on_modified - by deanhystad - Apr-23-2024, 03:09 PM
RE: watchdog on_modified - by CAD79 - Apr-24-2024, 08:55 AM
RE: watchdog on_modified - by deanhystad - Apr-24-2024, 06:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error when using Watchdog and Qt to keep open a Queue before and after sending first pyhill00 0 1,637 Oct-28-2021, 09:10 AM
Last Post: pyhill00
  How would I use Watchdog to get triggered when DVD is inserted? Daring_T 12 4,896 Aug-17-2021, 01:49 PM
Last Post: Daring_T

Forum Jump:

User Panel Messages

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