0

I understand that there are ways to listen for a local [on the same computer] file being modified, moved, or deleted in python. However, there doesn't seem to be any easy way of telling if an html file has been opened by the browser, because javascript and html aren't capable of editing or locking files by themselves, as far as I can tell.

The only solution seems to be opening a websocket connected to the python application (even though python is running on the same computer) in javascript every-time the web page is opened, but I'm wondering if there is a better way, preferably one that doesn't "poll" and instead is event based since I have a large amount of files.

Community
  • 1
  • 1
Phylliida
  • 4,217
  • 3
  • 22
  • 34
  • If you are only interested in detecting read-access, how about scraping your HTTP service's logs to see what requests have been served? (unless you're trying to detect local access via `file://` or something like that) – rchang Dec 19 '14 at 00:05
  • Yes it is local access, sorry I should have clarified that. – Phylliida Dec 19 '14 at 01:03

1 Answers1

1

I believe that you can send an ajax request to python when the page loads. If you are using a PHP backend, you can have PHP edit a file every time the page is loaded and you can then view this file using python.

Eric E
  • 572
  • 1
  • 4
  • 16
  • That actually works pretty well, PHP ended up being a good answer to a lot of problems (since it can write to files), thanks :) – Phylliida Dec 19 '14 at 01:04
  • Glad to see it helped you out. – Eric E Dec 19 '14 at 01:04
  • Is there a way of doing this without using any server hosting, however? (just javascript and html) – Phylliida Dec 19 '14 at 02:23
  • Not really... I assume your website is hosted and does not provide back end support? If that is the case, then you can simply run a webserver on your computer and allow cross domain requests. – Eric E Dec 19 '14 at 02:27