[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: anybody know about json + urllib2 ?
From: |
Reinhold Kainhofer |
Subject: |
Re: anybody know about json + urllib2 ? |
Date: |
Mon, 26 Sep 2011 13:41:26 +0200 |
User-agent: |
KMail/1.13.6 (Linux/2.6.38-11-generic; KDE/4.7.0; i686; ; ) |
Am Monday, 26. September 2011, 03:15:54 schrieb Graham Percival:
> Does anybody have a passing familiarity with json? I'm having
> trouble getting started with rietveld json api. I'm going to work
> on the code.google.com python interaction for the rest of today,
> but it would be great if somebody could get the json thing
> started.
You simply need to add the /api/<issue id> to the URL:
wget http://codereview.appspot.com/api/224052
{"description":"FiguredBass: Rewrite of the engraver to fix vertical
position\n\n-) use list<..> instead of vector<..>\n-) Don't reuse old figure
storage and no longer
simply fill in\n empty positions, which causes ordering to be lost in
some\n extender cases.\n-) Add description of engraver
logic","created":"2010-02-25 15:22:20
.668441","cc":["address@hidden"],"reviewers":
["address@hidden","address@hidden","address@hidden","address@hidden"],"owner_em
ail":"address@hidden","patchsets":
[1002,2001],"modified":"2011-09-24
09:51:54.987195","private":false,"base_url":"","closed":false,"owner":"Reinhold","is
sue":224052,"subject":"FiguredBass: Rewrite of the engraver to fix vertical
position"}
> Task: get a basic "hello world" with riteveld working. Once I've
> got that, the rest is (relatively) simple. The following python
> script gives me no joy; it just returns the main webpage.
>
>
> #!/usr/bin/env python
> import urllib2
> url = "http://codereview.appspot.com"
> data = "/api/5096046"
> request = urllib2.Request(url, data)
You are basically doing a request to
http://codereview.appspot.com/?/api/5096046
The correct code is:
request = urllib2.Request(url + data)
address@hidden:~$ python rv.py
{"description":"Doc: add a note about \\relative f to
notation","created":"2011-09-21 07:17:28.631011","cc":["lilypond-
address@hidden"],"reviewers":
["address@hidden","address@hidden","address@hidden"],"owner_email":"address@hidden","patchsets":
[1,6001],"modified":"2011-09-26
10:28:39.716188","private":false,"base_url":"","closed":true,"owner":"janek","issue":5096046,"subject":"Doc:
add a note about \\relative f to notation (issue 1909)"}
> Various help pages below, but I think I'm missing something
> fundamental about how json works.
Yes, it's much simpler than you thought: You simply construct an URL and
download that file. There's no particular data to sent, all arguments are
encoded in the URL already.
Cheers,
Reinhold
--
------------------------------------------------------------------
Reinhold Kainhofer, address@hidden, http://reinhold.kainhofer.com/
* Financial & Actuarial Math., Vienna Univ. of Technology, Austria
* http://www.fam.tuwien.ac.at/, DVR: 0005886
* LilyPond, Music typesetting, http://www.lilypond.org