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.parse_script(script);
	else:
		if cmd == 'flush' and is_user:
			alias_engine.flush();

	alias_engine.parse(is_user, words, cmd, argv);

def strip_r(line):
	t = list(line);
	if line.find('\r') != -1:
		t.pop(line.find('\r'))
		line = string.join(t, '');

	return line;

sock = ClientSocket(config['server'], int(config['port']));

sock.send("NICK %s\r\n" % config['nick']);
sock.send("USER %s * * :%s\r\n" % (config['usern'], config['useri']));

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);