# Generate a weather report for a given city import telnetlib city = "NYC" HOST = "rainmaker.wunderground.com" tn = telnetlib.Telnet(HOST) # Skip the welcome screen tn.read_until(b"Press Return to continue:") tn.write(b"\n") # We are prompted for a city code. tn.read_until(b"city code-- ") tn.write(city.encode('ascii') + b"\n") # Exit the host. # The connection will be closed, so read_all() won't block. tn.write(b"X\n") report = tn.read_all().decode('ascii') print( report )