Re: Google Chart API, HTTP POST request format.

2011-01-06 Thread Chris Rebert
On Wed, Jan 5, 2011 at 11:21 PM, Garland Fulton stacks...@gmail.com wrote:
 On Wed, Jan 5, 2011 at 7:26 PM, Tim Harig user...@ilthio.net wrote:

 On 2011-01-06, Slie stacks...@gmail.com wrote:
 [reformated to 80 columns per RFC 1855 guidelines]
  I have read several examples on python post requests but I'm not sure
  mine needs to be that complicated.

 From the HTML example on the page you posted:

    form action='https://chart.googleapis.com/chart' method='POST'
        input type=hidden name=cht value=lc  /
        input type=hidden name=chtt value=This is | my chart  /
        input type='hidden' name='chs' value='600x200' /
        input type=hidden name=chxt value=x,y /
        input type='hidden' name='chd' value='t:40,20,50,20,100'/
        input type=submit  /
    /form

 you can retreive the same chart from Python:

    Python 3.1.2 (r312:79147, Oct  9 2010, 00:16:06)
    [GCC 4.4.4] on linux2
    Type help, copyright, credits or license for more information.
     import urllib.request, urllib.parse
     params = urllib.parse.urlencode({'cht':'lc', 'chtt':'This is | my
     chart',
    ...         'chs':'600x200', 'chxt':'x,y', 'chd':'t:40,20,50,20,100'})
     chart =
 urllib.request.urlopen('https://chart.googleapis.com/chart',
    ...         data = params).read()
     chartFile = open(chart.png, 'wb')
     chartFile.write(chart)
    10782
     chartFile.close()
 --
 http://mail.python.org/mailman/listinfo/python-list

 Hope this isn't to stupid,
 For the
 chart = urllib.request.urlopen('https://chart.googleapis.com/chart', data =
 params).read()
 Where would I find information on why and what the ).read() part does.

http://docs.python.org/py3k/library/urllib.request.html#urllib.request.urlopen
Specifically: This function returns a file-like object (representing
the stream of data received). Thus, .read() on the file-like object
returns the actual bytes obtained from the given URL.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Google Chart API, HTTP POST request format.

2011-01-06 Thread Tim Harig
On 2011-01-06, Chris Rebert c...@rebertia.com wrote:
 On Wed, Jan 5, 2011 at 11:21 PM, Garland Fulton stacks...@gmail.com wrote:
 On Wed, Jan 5, 2011 at 7:26 PM, Tim Harig user...@ilthio.net wrote:
    Python 3.1.2 (r312:79147, Oct  9 2010, 00:16:06)
    [GCC 4.4.4] on linux2
    Type help, copyright, credits or license for more information.
     import urllib.request, urllib.parse
     params = urllib.parse.urlencode({'cht':'lc', 'chtt':'This is | my
     chart',

Sorry I didn't notice this got accidently wrapped when I pasted it.
 params = urllib.parse.urlencode({'cht':'lc', 'chtt':'This is | my 
chart',

    ...         'chs':'600x200', 'chxt':'x,y', 'chd':'t:40,20,50,20,100'})
     chart =
 urllib.request.urlopen('https://chart.googleapis.com/chart',
    ...         data = params).read()
     chartFile = open(chart.png, 'wb')
     chartFile.write(chart)
    10782
     chartFile.close()

 Hope this isn't to stupid,
 For the
 chart = urllib.request.urlopen('https://chart.googleapis.com/chart', data =
 params).read()
 Where would I find information on why and what the ).read() part does.

For some reason, posts from from this account don't seem to be making it
through the gateway to usenet so I am only seeing what Mr. Rebert has
replied to.  If you have asked anything else, I very well may have missed
it.

 http://docs.python.org/py3k/library/urllib.request.html#urllib.request.urlopen
 Specifically: This function returns a file-like object (representing
 the stream of data received). Thus, .read() on the file-like object
 returns the actual bytes obtained from the given URL.

Mr. Rebert already answed your question; but, I will expand on that a
little bit.  One of the great things about the Python language is that it
uses what is commonly known as duck typing.  That is anything object which
provides the same attributes as another object can be used as though it is
actually the second object.  It is kind of like an implicit form of
generics that doesn't require a template or an interface.

The Python standard library makes extensive use of duck typing for file
like objects.  Any object that provides the proper method attributes can be
given to functions that expect files even though the object is given might
not be the traditional concept of a file on the filesystem.  It might be a
stringIO object, a socket file object, or something new that you have
created that supports the required method attributes.

The semantics and documentation for file like objects have changed a
little for python2 vs. python3:

python2: http://docs.python.org/library/stdtypes.html#file-objects
python3: http://docs.python.org/py3k/library/io.html#io.IOBase

but they still basically work the same way.  Much of the Python 3
documentation still refers file objects.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Google Chart API, HTTP POST request format.

2011-01-05 Thread Tim Harig
On 2011-01-06, Slie stacks...@gmail.com wrote:
[reformated to 80 columns per RFC 1855 guidelines]
 I have read several examples on python post requests but I'm not sure
 mine needs to be that complicated.

From the HTML example on the page you posted:

form action='https://chart.googleapis.com/chart' method='POST'
input type=hidden name=cht value=lc  /
input type=hidden name=chtt value=This is | my chart  /
input type='hidden' name='chs' value='600x200' /
input type=hidden name=chxt value=x,y /
input type='hidden' name='chd' value='t:40,20,50,20,100'/
input type=submit  /
/form

you can retreive the same chart from Python:

Python 3.1.2 (r312:79147, Oct  9 2010, 00:16:06)
[GCC 4.4.4] on linux2
Type help, copyright, credits or license for more information.
 import urllib.request, urllib.parse
 params = urllib.parse.urlencode({'cht':'lc', 'chtt':'This is | my
 chart',
... 'chs':'600x200', 'chxt':'x,y', 'chd':'t:40,20,50,20,100'})
 chart = urllib.request.urlopen('https://chart.googleapis.com/chart',
... data = params).read()
 chartFile = open(chart.png, 'wb')
 chartFile.write(chart)
10782
 chartFile.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Google Chart API, HTTP POST request format.

2011-01-05 Thread Chris Rebert
On Wed, Jan 5, 2011 at 7:36 PM, Slie stacks...@gmail.com wrote:

 http://code.google.com/apis/chart/docs/post_requests.html

 Google will return a chart in your browser from a URL that you have built. If 
 your URL is bigger then 2K characters it will allow you to submit POST 
 requests.

 They gives examples of HTML, JavaScript, and PHP POST requests. Is there a 
 way I can submit a request with Python? Or possibly submit the HTML, 
 JavaScript or PHP using python?(That was a long shot thought). If I do that I 
 would need to find out what to do with the .PNG it gives me.

 Am I headed in the right direction, is the above paragraph about submitting 
 an HTML form from my program even logical?

You should probably first try one of the existing Python wrappers for
Google's chart API and see if that meets your needs:
http://code.google.com/p/google-chartwrapper/
http://pygooglechart.slowchop.com/

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Google Chart API, HTTP POST request format.

2011-01-05 Thread Garland Fulton
I tried to use pygooglechart.py and I have been trying to get it set up
all day actually along with several other graphing API's.

I just found out that there is a problem with numpy and python 3.1 that is
why I moved from the API's. Should I change version just for
these library's?

Should I be learning Python on 3.1?

Awesome!


On Wed, Jan 5, 2011 at 7:52 PM, Chris Rebert c...@rebertia.com wrote:

 On Wed, Jan 5, 2011 at 7:36 PM, Slie stacks...@gmail.com wrote:
 
  http://code.google.com/apis/chart/docs/post_requests.html
 
  Google will return a chart in your browser from a URL that you have
 built. If your URL is bigger then 2K characters it will allow you to submit
 POST requests.
 
  They gives examples of HTML, JavaScript, and PHP POST requests. Is there
 a way I can submit a request with Python? Or possibly submit the HTML,
 JavaScript or PHP using python?(That was a long shot thought). If I do that
 I would need to find out what to do with the .PNG it gives me.
 
  Am I headed in the right direction, is the above paragraph about
 submitting an HTML form from my program even logical?

 You should probably first try one of the existing Python wrappers for
 Google's chart API and see if that meets your needs:
 http://code.google.com/p/google-chartwrapper/
 http://pygooglechart.slowchop.com/

 Cheers,
 Chris
 --
 http://blog.rebertia.com

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Google Chart API, HTTP POST request format.

2011-01-05 Thread Garland Fulton
Thank you for showing me the POST request, I will defiantly learn a lot from
that.

On Wed, Jan 5, 2011 at 7:26 PM, Tim Harig user...@ilthio.net wrote:

 On 2011-01-06, Slie stacks...@gmail.com wrote:
 [reformated to 80 columns per RFC 1855 guidelines]
  I have read several examples on python post requests but I'm not sure
  mine needs to be that complicated.

 From the HTML example on the page you posted:

form action='https://chart.googleapis.com/chart' method='POST'
input type=hidden name=cht value=lc  /
input type=hidden name=chtt value=This is | my chart  /
input type='hidden' name='chs' value='600x200' /
input type=hidden name=chxt value=x,y /
input type='hidden' name='chd' value='t:40,20,50,20,100'/
input type=submit  /
/form

 you can retreive the same chart from Python:

Python 3.1.2 (r312:79147, Oct  9 2010, 00:16:06)
[GCC 4.4.4] on linux2
Type help, copyright, credits or license for more information.
 import urllib.request, urllib.parse
 params = urllib.parse.urlencode({'cht':'lc', 'chtt':'This is | my
 chart',
... 'chs':'600x200', 'chxt':'x,y', 'chd':'t:40,20,50,20,100'})
 chart = urllib.request.urlopen('https://chart.googleapis.com/chart
 ',
... data = params).read()
 chartFile = open(chart.png, 'wb')
 chartFile.write(chart)
10782
 chartFile.close()
 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Google Chart API, HTTP POST request format.

2011-01-05 Thread Corey Richardson
On 01/06/2011 12:16 AM, Garland Fulton wrote:
 I tried to use pygooglechart.py and I have been trying to get it set
 up all day actually along with several other graphing API's.
 
 I just found out that there is a problem with numpy and python 3.1 that
 is why I moved from the API's. Should I change version just for
 these library's?
 
 Should I be learning Python on 3.1?
 
 Awesome!
 
 [snip]

I swapped from 3 to 2.6 a while back, better support for modules, and
not really losing much in the way of features.

~Corey Richardson

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Google Chart API, HTTP POST request format.

2011-01-05 Thread Chris Rebert
 On Wed, Jan 5, 2011 at 7:52 PM, Chris Rebert c...@rebertia.com wrote:
 On Wed, Jan 5, 2011 at 7:36 PM, Slie stacks...@gmail.com wrote:
 
  http://code.google.com/apis/chart/docs/post_requests.html
 
  Google will return a chart in your browser from a URL that you have
  built. If your URL is bigger then 2K characters it will allow you to submit
  POST requests.
 
  They gives examples of HTML, JavaScript, and PHP POST requests. Is there
  a way I can submit a request with Python? Or possibly submit the HTML,
  JavaScript or PHP using python?(That was a long shot thought). If I do that
  I would need to find out what to do with the .PNG it gives me.
 
  Am I headed in the right direction, is the above paragraph about
  submitting an HTML form from my program even logical?

 You should probably first try one of the existing Python wrappers for
 Google's chart API and see if that meets your needs:
 http://code.google.com/p/google-chartwrapper/
 http://pygooglechart.slowchop.com/

On Wed, Jan 5, 2011 at 9:16 PM, Garland Fulton stacks...@gmail.com wrote:
 I tried to use pygooglechart.py and I have been trying to get it set up
 all day actually along with several other graphing API's.
 I just found out that there is a problem with numpy and python 3.1 that is
 why I moved from the API's. Should I change version just for
 these library's?
 Should I be learning Python on 3.1?

Most third-party libraries have yet to be ported to Python 3.1 (with a
few notable exceptions). If you actually want to write
non-(toy/demo/trivial) programs, you should probably use Python 2.x.
Python 3.1 is fine for learning the basics of the language; once
you've done that, learning the Python 2.x differences and wart
workarounds is not hard.

(Also, in the future, please don't top-post.)

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Google Chart API, HTTP POST request format.

2011-01-05 Thread Garland Fulton
On Wed, Jan 5, 2011 at 7:52 PM, Chris Rebert c...@rebertia.com wrote:

 On Wed, Jan 5, 2011 at 7:36 PM, Slie stacks...@gmail.com wrote:
 
  http://code.google.com/apis/chart/docs/post_requests.html
 
  Google will return a chart in your browser from a URL that you have
 built. If your URL is bigger then 2K characters it will allow you to submit
 POST requests.
 
  They gives examples of HTML, JavaScript, and PHP POST requests. Is there
 a way I can submit a request with Python? Or possibly submit the HTML,
 JavaScript or PHP using python?(That was a long shot thought). If I do that
 I would need to find out what to do with the .PNG it gives me.
 
  Am I headed in the right direction, is the above paragraph about
 submitting an HTML form from my program even logical?

 You should probably first try one of the existing Python wrappers for
 Google's chart API and see if that meets your needs:
 http://code.google.com/p/google-chartwrapper/
 http://pygooglechart.slowchop.com/

 Cheers,
 Chris
 --
 http://blog.rebertia.com

Google Chart Wrapper is compatible with 3.1 and i have been looking all day
for something like this. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Google Chart API, HTTP POST request format.

2011-01-05 Thread Garland Fulton
On Wed, Jan 5, 2011 at 7:26 PM, Tim Harig user...@ilthio.net wrote:

 On 2011-01-06, Slie stacks...@gmail.com wrote:
 [reformated to 80 columns per RFC 1855 guidelines]
  I have read several examples on python post requests but I'm not sure
  mine needs to be that complicated.

 From the HTML example on the page you posted:

form action='https://chart.googleapis.com/chart' method='POST'
input type=hidden name=cht value=lc  /
input type=hidden name=chtt value=This is | my chart  /
input type='hidden' name='chs' value='600x200' /
input type=hidden name=chxt value=x,y /
input type='hidden' name='chd' value='t:40,20,50,20,100'/
input type=submit  /
/form

 you can retreive the same chart from Python:

Python 3.1.2 (r312:79147, Oct  9 2010, 00:16:06)
[GCC 4.4.4] on linux2
Type help, copyright, credits or license for more information.
 import urllib.request, urllib.parse
 params = urllib.parse.urlencode({'cht':'lc', 'chtt':'This is | my
 chart',
... 'chs':'600x200', 'chxt':'x,y', 'chd':'t:40,20,50,20,100'})
 chart = urllib.request.urlopen('https://chart.googleapis.com/chart
 ',
... data = params).read()
 chartFile = open(chart.png, 'wb')
 chartFile.write(chart)
10782
 chartFile.close()
 --
 http://mail.python.org/mailman/listinfo/python-list


Hope this isn't to stupid,

For the
chart = urllib.request.urlopen('https://chart.googleapis.com/chart', data =
params).read()

Where would I find information on why and what the ).read() part does.

Thank you,
-- 
http://mail.python.org/mailman/listinfo/python-list