Example #1
0
def get_weather(zipcode):
	http = ClientSocket('www.weather.com', 80);
	http.send('GET /weather/local/%s HTTP/1.0\r\n' % zipcode);
	http.send('Host: www.weather.com\r\n');
	http.send('Referer: http://www.weather.com/\r\n');
	http.send('Accept: */*\r\n\r\n');

	city = zipcode;

	while True:
		try:
			(iw, ow, ew) = select.select([http], [], [], 1);
		except ValueError:
			break;

		if iw is None:
			break;

		html = str(http.read());

		t_index = html.find('<TITLE>Local Weather Forecast for ');
		if t_index != -1:
			city_i = html.find('(%s)' % zipcode);
			city = html[t_index + 34:city_i];

		temp_i = html.find('<B CLASS=obsTempTextA>');
		temp_i2 = html.find('&deg;F</B>');

		if temp_i != -1 and temp_i2 != -1:
			temp = html[temp_i + 22:temp_i2];
			break;

	http.close();
	return "It is currently %sF in %s" % (temp, city);
Example #2
0
alias_engine = pbAlias.AliasEngine(parse_vars, parse_func, sock);

try:
	scr = open('default.scr', 'r');
	init_a = scr.read().split(':unload=')[0];
	scr.close();
except IOError:
	pass;

script = init_a.split('\n');
alias_engine.parse_script(script);

while True:
	try:
		(iw, ow, ew) = select.select([sock], [], [], 60);
	except ValueError:
		break;

	if iw is None:
		continue;

	data = sock.read();
	lines = data.split('\n');
	for line in lines:
		if line == '':
			continue;

		line = strip_r(line);
		parse_line(sock, line);