addressalign-toparrow-leftarrow-leftarrow-right-10x10arrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcredit-cardcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobe--smallglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1languagelaunch-new-window--smalllight-bulblightning-boltlinklocation-pinlockm-swarmSearchmailmediummessagesminusmobilemoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstar-shapestartickettrashtriangle-downtriangle-uptwitteruserwarningyahooyoutube

Re: [DCPython] Strategy/Feedback on the Following Problem Statement

From: Saran A
Sent on: Tuesday, March 31, 2015, 7:16 AM
@Mark Scott Wright: I did review the documentation for WatchDog, but was confused with how to integrate this library. Here is my initial commit:

https://github.com/ahlusar1989/IntroToPython/blob/master/Project1WG_with_assumptions_and_comments.py 

I am curious to know how I would integrate this into WatchDog's system. I am concerned that there may be unnecessary side-effects. I welcome any snippet or exemplar for how to use this. I know that, as of now:

1. My present code is assuming all filenames come directly from the commandline.  No searching of a directory. 

2) My present code does not move any files to success or failure directories 

3) My present code doesn't calculate or write to a text file any statistics. 

4) My present code runs once through the names, and terminates.  It doesn't "monitor" anything. 

5) My present code doesn't check for zero-length files 

How would I address this with WatchDog. As someone who is not familiar (I have only been programming for 8 months) with best practice for writing to files, appending to folders and searching a directory. Is it possible that you could provide me with some snippets or guidance on where to place your suggestions. 

Sincerely,

Saran



On Tue, Mar 31, 2015 at 6:51 AM, Mark wright <[address removed]> wrote:
I'm assuming it's the directory monitoring that is your main concern (checking a file for length 0, moving a file to another directory, etc are all relatively easy problems).  I'd recommend watchmedo - a python package that monitors the filesystem for changes.  https://pypi.python.org/pypi/watchdog.  Install with "pip install watchmedo"

A simple (python 2.7) program that does what you're looking for (put your file-scanning logic in on_created() - right now it just prints out the new file's name) is below.  Watchmedo is cross platform, and it uses native filesystem monitoring facilities when available, so it should be pretty performant.

from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

class FileEventHandler(FileSystemEventHandler):

    def on_created(self, event):
        print "process", event.src_path, "here"

if __name__ == "__main__":
    path_to_monitor = "."
    event_handler = FileEventHandler()
    observer = Observer()
    observer.schedule(event_handler, path=path_to_monitor, recursive=False)
    observer.start()
    raw_input("press enter to stop monitoring")
    observer.stop()
    observer.join()



On Mon, Mar 30, 2015 at 1:47 PM, Kevin Sheppard <[address removed]> wrote:
If you require a binary module that [this is important] provides all required binary code, either in the from of  C/C++ source files or Cython code*, then you should be able to do the following.

1. Install Python for Windows
2. Install pip, if it isn't installed
3. Install Microsoft Compiler for Python http://www.microsoft.com/en-us/download/details.aspx?id=44266
4. Install Cython using pip install cython

Personally I find the Anaconda distribution far simpler to use than the official Python for Windows since many binary packages are pre-built.  It is a free download https://store.continuum.io/cshop/anaconda/

* Some python modules require not-included libraries, e.g. NumPy, and are extremely difficult to build on Windows.





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Kevin Sheppard ([address removed]) from DC Python.
To learn more about Kevin Sheppard, visit his/her member profile
To report this message or block the sender, please click here
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]



--
Mark Wright
[address removed]




--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Mark wright ([address removed]) from DC Python.
To learn more about Mark wright, visit his/her member profile
To report this message or block the sender, please click here
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]