def query(cls, url, data): """Query the specified URL. The specified data should be in a dictionary and will be encoded into the GET URL. """ client = cls(url, data) encoded = urllib.urlencode(data) url += "?" + encoded request = urllib2.Request(url) try: response = urllib2.urlopen(request) except urllib2.HTTPError as err: client.error = True client.statusCode = err.code except urllib2.URLError as err: client.error = True client.errorReason = err.reason else: content = response.read() # Create tthe forecast object client.forecast = Forecast.buildFromJSON(content) return client
def queryWeather(cls, cityName): """Mock for querying the API to get the weather condition in a city.""" client = cls(None, {"q": cityName}) content = WEATHER_CONDITIONS[cityName] client.forecast = Forecast.buildFromJSON(content) return client