From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Thu, 18 Apr 2013 10:27:21 +0000 (+0200) Subject: Re: Python analogous for the CLI command X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7a0bfef50aeddcefa528d59986a8645a85553641;p=notmuch-archives.git Re: Python analogous for the CLI command --- diff --git a/bc/921a4faad542c411c9ac3cd3877b068970c783 b/bc/921a4faad542c411c9ac3cd3877b068970c783 new file mode 100644 index 000000000..e70e44139 --- /dev/null +++ b/bc/921a4faad542c411c9ac3cd3877b068970c783 @@ -0,0 +1,115 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id C4FBA431FBC + for ; Thu, 18 Apr 2013 03:28:36 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id PUmn7IoD0ivt for ; + Thu, 18 Apr 2013 03:28:32 -0700 (PDT) +Received: from mail.cryptobitch.de (cryptobitch.de [88.198.7.68]) + (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 0DFB9431FBF + for ; Thu, 18 Apr 2013 03:28:32 -0700 (PDT) +Received: from mail.jade-hamburg.de (mail.jade-hamburg.de [85.183.11.228]) + (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) + (No client certificate requested) + by mail.cryptobitch.de (Postfix) with ESMTPSA id 5ED6B6211B9 + for ; Thu, 18 Apr 2013 12:28:27 +0200 (CEST) +Received: by mail.jade-hamburg.de (Postfix, from userid 401) + id C0E0EDF2A3; Thu, 18 Apr 2013 12:28:26 +0200 (CEST) +Received: from thinkbox.jade-hamburg.de (thinkbox.jadE-Hamburg.de + [10.1.1.109]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No + client certificate requested) (Authenticated sender: teythoon) by + mail.jade-hamburg.de (Postfix) with ESMTPSA id 24BA7DF28B; Thu, 18 Apr 2013 + 12:28:25 +0200 (CEST) +Received: from teythoon by thinkbox.jade-hamburg.de with local (Exim 4.80) + (envelope-from ) + id 1USm3l-0003HZ-GK; Thu, 18 Apr 2013 12:27:21 +0200 +Content-Type: text/plain; charset="utf-8" +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +From: Justus Winter <4winter@informatik.uni-hamburg.de> +User-Agent: alot/0.3.3+ +To: Flavius Aspra , notmuch@notmuchmail.org +References: <20130418081137.GA598@evolution> +In-Reply-To: <20130418081137.GA598@evolution> +Message-ID: <20130418102721.10489.1439@thinkbox.jade-hamburg.de> +Subject: Re: Python analogous for the CLI command +Date: Thu, 18 Apr 2013 12:27:21 +0200 +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Thu, 18 Apr 2013 10:28:37 -0000 + +Hi Flavius :) + +welcome to notmuch :) + +Quoting Flavius Aspra (2013-04-18 10:11:37) +> Can you give me some pointers on how to use the python module to get the = +JSON +> data with notmuch effort, equivalent to the command: + ^^^^^^^ hehe :) + +Ok, here it is: + +teythoon@thinkbox ~/tmp % cat flavius.py +import notmuch + +db =3D notmuch.Database() +q =3D db.create_query('from:Flavius') + +for m in q.search_messages(): + print(m) + +for t in q.search_threads(): + for m in t.get_toplevel_messages(): + print(m) +teythoon@thinkbox ~/tmp % python3 flavius.py +Flavius Aspra (inbox lists notmuch signed) (2013-04-= +18) +Flavius Aspra (inbox lists notmuch signed) (2013-04-= +18) + +There once was a json encoder that produced something similar to +notmuch show --format=3Djson, but that was there only to be used by a +python version of the notmuch cli binary. That was unmaintained and +apparently unused, I removed it and the json encoder some time ago. + +If you absolutely need json, put the result in some suitable data +structure and use pythons json module to encode it. + +> Some key classes and methods would be helpful. From the documentation of = +the +> python code, I couldn't find indications about any of the parameters like +> --entire-thread and --format. + +Have you seen http://notmuch.readthedocs.org ? + +Also, if you want to see some code that uses the python bindings, go +to github.com/pazz/alot (nice MUA written in python, but it's huge) or +github.com/teythoon/afew (tagging solution, tiny codebase compared to +alot). + +Good luck :) +Justus + +btw: cool name ;)