Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: [pyinotify] help required to send only one mail for chunk of events Date: Tue, 24 May 2016 10:09:36 +1000 Lines: 45 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de uSsHw6PdHSUa//JPL33KQQYZVkwCW2LBzXfKmwzjdejw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.03; 'finally:': 0.05; 'chunk': 0.07; 'except:': 0.07; 'exit': 0.07; 'formatting': 0.07; 'subject:help': 0.07; 'cc:addr:python-list': 0.09; 'ignoring': 0.09; 'oh,': 0.09; 'python': 0.10; 'exception': 0.13; 'size,': 0.13; '2016': 0.16; '24,': 0.16; 'bit.': 0.16; 'duplicating': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:required': 0.16; 'subject:send': 0.16; 'sys.exit(1)': 0.16; 'wrote:': 0.16; 'directory.': 0.18; 'try:': 0.18; 'subject:] ': 0.19; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'work,': 0.21; '(the': 0.22; 'exists.': 0.22; 'interpret': 0.22; 'am,': 0.23; 'appears': 0.23; 'code,': 0.23; 'import': 0.24; 'header:In- Reply-To:1': 0.24; 'script': 0.25; "doesn't": 0.26; 'figure': 0.27; 'error': 0.27; 'message-id:@mail.gmail.com': 0.27; 'change,': 0.27; 'idea': 0.28; 'this.': 0.28; 'actual': 0.28; "i'm": 0.30; 'print': 0.30; 'that.': 0.30; 'code': 0.30; 'guess': 0.31; 'primary': 0.31; 'though,': 0.32; 'doubt': 0.33; 'extract': 0.33; 'tue,': 0.34; 'file': 0.34; 'received:google.com': 0.35; 'received:74.125.82': 0.35; 'but': 0.36; 'there': 0.36; 'two': 0.37; 'client': 0.37; 'wanted': 0.37; 'doing': 0.38; 'anything': 0.38; 'sure': 0.39; 'some': 0.40; 'your': 0.60; 'default': 0.61; 'further': 0.62; 'more': 0.63; 'information': 0.63; 'here:': 0.63; 'minutes': 0.64; 'worth': 0.67; 'email,': 0.69; 'upgrading': 0.72; 'emails,': 0.72; 'chrisa': 0.84; 'ever.': 0.84; 'intending': 0.84; 'messed': 0.84; 'mins': 0.84; 'subject:events': 0.84; 'to:none': 0.91; 'do:': 0.91; 'watched': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=ZfNpJDMUmBjgKqo0dQXEYD1mQ7lCakOPv4VFPWrCGr4=; b=Wwo0f88u5qItPjVntC89QZRFljdqBPLKa9BffjvbOCgV2ceewqQFjfew1gLLuTzvfw vE6OAn+Wu8hYPEcpyNgcBhPGWkCyU5dUdtSiIgfiOvUfyBkGVOv9hoPsLiLeW8RPFRzN p5I/85QGmUImdh8uqaYZRXYWkusUX2igwn9LNeIZBD/f1OjjIgBTeq12fFh+P8jlWnuf Cp2/2v7NFDp6Xu0ruENSGHT7La0W+iUnrrn97RdDIYw4pLRdMDefoUKiur/2hitgm/f1 +qESfWPT5RaJ44CITfs4pawldAGLBB8swOfRcJuYleoB+iIw2wgkjzN4cAy+/JbNGQGK 0CtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=ZfNpJDMUmBjgKqo0dQXEYD1mQ7lCakOPv4VFPWrCGr4=; b=CY3nbxLlUTxSsBlllaSqnE12DR61k2cnYSbtuBxfgtPVCYnjuaFbW9VqlQhcvtGTmx dIkL4Obs0P42FzoYqYNwUf4J+oxTDI4WKS6fe/YeEbbUJpXZEZzhKCjb/q7xc6JgUUg6 Zt8CJtvxhSe8H+IJrFqwuimWriVWxfn/T3dGmhZICkaCXzVk9hJfHq78/lsM6E7RDHYR yTDPjqYADkTYLFwzywuk/c3DAXfSdY0pMt70w6w8lYN9+sksKMNpK8og5bif6jQ1HQ6O gmfdInrhxXHqglobqGJeC7EpvUfFwVpvikwoto4YtU4784zvt25duMcHFJrx4hJYTXhW RRTg== X-Gm-Message-State: ALyK8tJNnvXwN8kL3ynueE6aLdBzqL7mDzQDuP+A/t5SSeNrGjimhLBTWWtoaNVM8zIwMqf1VGcGw+7nAK7INw== X-Received: by 10.194.110.234 with SMTP id id10mr1242923wjb.30.1464048576162; Mon, 23 May 2016 17:09:36 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: Xref: csiph.com comp.lang.python:109033 On Tue, May 24, 2016 at 6:20 AM, Mohan L wrote: > I wanted to send an email notification with content of logfile after 15 > mins on any change. The idea is I want to send only one mail for chunk of > events.Say for example, I want to send only one email when some one extract > a tar.gz file in watched directory. I'm ignoring your actual code, because the formatting is all messed up - your mail/news client appears to have destroyed your indentation. But there are two straight-forward ways of doing what you want here: 1) Whenever there's a change, wait fifteen minutes, then send an email with all the recent changes. 2) Whenever there's a change, check to see when you last sent an email, and if it's more than fifteen minutes ago, send one immediately. I'm not entirely sure how to interpret your "after 15 mins", but my guess is that it's one of the above. Oh, I lied. I am looking at your code, just a bit. > try: > import pyinotify > except: > print "pyinotify not installed" > sys.exit(1) Don't do this. Ever. If you want to use pyinotify, there's one thing to do: import pyinotify If that doesn't work, Python will print an error message and then exit 1, so having code like this is at best just duplicating what already exists. The default message is far more helpful, though, so you're destroying information - a lot of it. You use a bare 'except:' further down, too; again, don't. Figure out _exactly_ what exception you're intending to catch, and catch that. Finally: Consider upgrading to Python 3. With a script this size, I doubt there's anything holding you on Python 2 (the two primary dependencies are pyinotify and the sending of emails, both of which are available on Py3), so this would be well worth porting. ChrisA