14 March 2001

adric: books icon (c) 2004 adric.net (Default)

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')
	h1.endheaders()
	errcode, errmsg, headers = h1.getreply()
	if errcode == 200:
		f = h1.getfile()
		data = f.read()
		f.close()
		print data
	else:
		print errcode, errmsg

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

fetch0('www.livejournal.com','/~adric/')

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

So simple it hurts.

adric: books icon (c) 2004 adric.net (Default)
 I don't ope snail when I know what it says, do you?

Profile

adric: books icon (c) 2004 adric.net (Default)
adric

November 2025

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526 2728 29
30      

Links

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated 10 January 2026 06:08 am
Powered by Dreamwidth Studios