Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53380

How do I process this using Python?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <papillion@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.06; 'json': 0.07; 'subject:process': 0.09; 'subject:using': 0.09; 'subject:How': 0.10; 'api': 0.11; 'skip:j 30': 0.16; 'skip:u 50': 0.16; 'skip:u 60': 0.16; 'string:': 0.16; 'thanks,': 0.17; 'trying': 0.19; 'everyone,': 0.19; 'working.': 0.19; 'print': 0.22; 'header:User-Agent:1': 0.23; 'parse': 0.24; 'processor': 0.24; 'code:': 0.26; 'tried': 0.27; 'returned': 0.30; "i'm": 0.30; 'anyone': 0.31; 'skip:u 20': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'message-id:@gmail.com': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'offer': 0.62; 'needing': 0.65; 'obvious': 0.74; 'subject:this': 0.83; '(probably': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=BeBy4V8/A819W/WrwMzXvR1See0nMnpFkn7yMh9gkoI=; b=xqOx0wNXCXSVQgm/nJY35PRDQJQUmn0dgbpQSQk4aHjxC4rpVJzmJsgFihirAWsjwz I4xkDOTXTjKUfByd93LjjsiSn5/KLWT4LOVIaDDS/7IdbzAbTRrveWt0gUdMStjIEQqG WGda9/3mdobzCf27PCiEcMjjg3LrSk5khAAfxNpx3lxlbe4tdj3MTJZw4MEEdPrdlcaG U2be2EpsDza7dvUf0nOtYLRkTRgZkkrvgyFV7b7XupJzHhI19ZlUsbsa/rbbO8OCb44B 2FqlOE6MNgzKwa/jmBH+xTzyIjfU1ow88hLsj5W1qSfzSijeZsuKzGdQWaS1fZ7CVRPz O/og==
X-Received by 10.182.106.114 with SMTP id gt18mr11949195obb.77.1377992647486; Sat, 31 Aug 2013 16:44:07 -0700 (PDT)
Date Sat, 31 Aug 2013 18:44:04 -0500
From Anthony Papillion <papillion@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130804 Thunderbird/17.0.8
MIME-Version 1.0
To python-list@python.org
Subject How do I process this using Python?
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.426.1377992650.19984.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1377992650 news.xs4all.nl 15939 [2001:888:2000:d::a6]:43728
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:53380

Show key headers only | View raw


Hello Everyone,

I'm writing a processor for Bitmessage messages and I am needing to
parse the following returned JSON string:

{u'inboxMessages': [{u'fromAddress':
u'BM-2DBYkhiBZCyrBa8J7gFRGrFRSGqtHgPtMvwQ', u'toAddress':
u'BM-2DC7SCTj2gzgrGgMvUCARdrfrsgLyz3iMyN3', u'read': 0, u'msgid':
u'36659a4453e12a085d8fbfeefc58da8fb23f38bfb0984c2983e0ddc31c776038',
u'receivedTime': u'1377986524', u'message':
u'dGVzdGluZyAxIDIgMw0KDQotLQ0KSm9obiBQZXJyeQ0KDQo=\n', u'encodingType':
2, u'subject': u'bWVzc2FnZSAx\n'}, {u'fromAddress':
u'BM-2DBYkhiBZCyrBa8J7gNBrngtgttHgPtMvwQ', u'toAddress':
u'BM-2DC7SCTj2gzgrGgMvUCARdCrfthyz3iMyN3', u'read': 0, u'msgid':
u'2ebe10c788ed47c6c122e3b43ae6642cb15077536c7056ed5088ab2d339c4630',
u'receivedTime': u'1377986557', u'message':
u'VGhpcyBpcyB0aGUgbmV4dCB0ZXN0DQoNCi0tDQpKb2huIFBlcnJ5DQoNCg==\n',
u'encodingType': 2, u'subject': u'dGVzdGluZyAzIDQgNQ==\n'},
{u'fromAddress': u'BM-2DBYkhithgyhyrBa8J7gNBrnSGqtHgPtMvwQ',
u'toAddress': u'BM-2DC7SCTj2gzgrtgtgMvUCARdCogLyz3iMyN3', u'read': 0,
u'msgid':
u'91dffd421c898aab0ffc43a363869a580abec6fa851aa6cf7cefe98263f96c81',
u'receivedTime': u'1377986599', u'message':
u'VGhpcyBpcyB0aGUgM3JkIHRlc3QNCg0hjj0NCkpvaG4gUGVycnkNCg0K\n',
u'encodingType': 2, u'subject': u'dGhpcyBpcyB0aGUgM3Jk\n'}]}

I tried using the following code:

data = json.loads(api.getAllInboxMessages) # This is the API call

for messageSender in data['inboxMessages']['fromAddress']
    print messageSender

For some reason (probably obvious reasons) isn't working. I'm trying to
loop through the JSON and return all of the fromAddress fields.

Can anyone offer suggestions?

Thanks,
Anthony

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

How do I process this using Python? Anthony Papillion <papillion@gmail.com> - 2013-08-31 18:44 -0500
  Re: How do I process this using Python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-01 01:15 +0000

csiph-web