def get_weather(location="SanAntonio TX"):

    # Query weather from Yahoo Weather using mYQL
    weather = Weather(unit='f', format='json')
    req_obj = json.loads(weather.get_weather_in(location).text)
    req_obj = req_obj['query']['results']['channel']

    # Create dictionary object to return
    ret_obj = {}
    try:
        ret_obj['temp'] = req_obj['item']['condition']['temp']
        ret_obj['high'] = req_obj['item']['forecast'][0]['high']
        ret_obj['low'] = req_obj['item']['forecast'][0]['low']
        ret_obj['condition'] = req_obj['item']['condition']['text']
        ret_obj['humidity'] = req_obj['atmosphere']['humidity']
        ret_obj['city'] = req_obj['location']['city']
    except KeyError:
        print("Failed to fetch weather conditions.")
        return False
    
    return ret_obj
Beispiel #2
0
class TestWeather(unittest.TestCase):
    """Weather module unit test
    """
    def setUp(self, ):
        self.weather = Weather(unit='c', format='json')

    def test_get_weather_in(self):
        data = self.weather.get_weather_in('choisy-le-roi')
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_get_weather_in_with_unit(self):
        data = self.weather.get_weather_in(
            'choisy-le-roi', 'c', ['location', 'units', 'item.condition'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_get_weather_forecast(self, ):
        data = self.weather.get_weather_forecast('choisy-le-roi')
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_get_weather_description(self, ):
        data = self.weather.get_weather_description('dolisie')
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_get_current_condition(self, ):
        data = self.weather.get_current_condition('Nantes')
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_get_current_atmosphere(self, ):
        data = self.weather.get_current_atmosphere('Scotland')
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_get_current_wind(self, ):
        data = self.weather.get_current_wind('Barcelona')
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_get_astronomy(self, ):
        data = self.weather.get_astronomy('Congo')
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)
Beispiel #3
0
class TestWeather(unittest.TestCase):
    """Weather module unit test
    """
    def setUp(self,):
        self.weather = Weather(unit='c', format='json')

    def test_get_weather_in(self):
        data = self.weather.get_weather_in('choisy-le-roi')
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_get_weather_in_with_unit(self):
        data = self.weather.get_weather_in('choisy-le-roi', 'c',['location', 'units', 'item.condition'])
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)
    
    def test_get_weather_forecast(self,):
        data = self.weather.get_weather_forecast('choisy-le-roi')
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)
    
    def test_get_weather_description(self,):
        data = self.weather.get_weather_description('dolisie')
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_get_current_condition(self,):
        data = self.weather.get_current_condition('Nantes')
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_get_current_atmosphere(self,):
        data = self.weather.get_current_atmosphere('Scotland')
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)

    def test_get_current_wind(self,):
        data = self.weather.get_current_wind('Barcelona')
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)
 
    def test_get_astronomy(self,):
        data = self.weather.get_astronomy('Congo')
        logging.debug(pretty_json(data.content))
        self.assertEqual(data.status_code, 200)
Beispiel #4
0
 def setUp(self,):
     self.weather = Weather(unit='c', format='json')
Beispiel #5
0
 def setUp(self, ):
     self.weather = Weather(unit='c', format='json')