nil.enroll(aetheric_username, quantum_class_id) (adric) wrote,
nil.enroll(aetheric_username, quantum_class_id)

  • Mood:
  • Music:

more fun with Python

I started fiddling around with some python in the general direction of an LJ client while trying to stay off the phone the last hour.

I was waiting for a phone interview call which has not yet come. The nice, helpful Catbert (fourth) managed to determine that the fellow had got caught up in a meeting, which he admitted happens from time to time...I am to catch up with them tomorrow morning.

I had looked at the dev pages to see what I would need, (and they say it better ) so I knew I really just needed some simple web client code (HTTP GET, PUT) at the base of it. From wandering around in the Python Library Reference before, I knew it was really easy to get into any common internet protocols (Awhile back I hacked up a 7 line email client to see if I could..) so I started poking around their url and http libraries (urllib and httplib, respectively :) This is what I came up with in less than an hour:

 def fetch0(bone, meat):
	"""v0 Fetches file string meat from host bone by http"""
	import httplib
	h1 = httplib.HTTP(host=bone)
	h1.putrequest('GET', meat)
	h1.putheader('ACCEPT', 'text/html')
	h1.putheader('ACCEPT', 'text/plain')
	errcode, errmsg, headers = h1.getreply()
	if errcode == 200:
		f = h1.getfile()
		data =
		print data
		print errcode, errmsg

Drop this into a python interpreter or type it in, feed in a string pair, like so:


and it will merrily dump the HTML of the file to screen, or report the error code.

So simple it hurts.


  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded