예제 #1
0
def get_city_weather(city=None, lat=None, lon=None):

    data = YahooWeather(APP_ID=app_ID,
                        api_key=consumer_key,
                        api_secret=consumer_secret)
    if city:
        weather = data.get_yahoo_weather_by_city(city, Unit.celsius)
    else:
        weather = data.get_yahoo_weather_by_location(lat, lon, Unit.celsius)

    if weather:
        sunny = [32, 36]
        cloudy = [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
        snowy = [5, 6, 7, 8, 9, 10, 14, 15, 16, 41, 42, 43, 46]
        stormy = [
            0, 1, 2, 3, 4, 11, 12, 13, 17, 18, 35, 37, 38, 39, 40, 45, 47
        ]
        supermoon = [31, 33, 34, 44]

        # Get the location
        location = data.get_location().__dict__
        # print(condition)

        # Get the condition
        condition = data.get_condition().__dict__
        # print(condition)

        # Get the forecasts
        forecasts = []
        for day in data.get_forecasts():
            forecasts.append(day.__dict__)
        # print(forecasts)

        wind = data.get_wind()
        # print(wind.__dict__)

        humidity = data.get_atmosphere().__dict__['humidity']

        astronomy = data.get_astronomy().__dict__

        return {
            'location': location,
            'condition': condition,
            'forecasts': forecasts,
            'wind': wind,
            'humidity': humidity,
            'astronomy': astronomy,
            # icones
            'sunny': sunny,
            'cloudy': cloudy,
            'snowy': snowy,
            'stormy': stormy,
            'supermoon': supermoon,
            'today': datetime.datetime.now().strftime("%A"),
        }

    else:
        return {'error': True, 'city': city}
예제 #2
0
from yahoo_weather.weather import YahooWeather
from yahoo_weather.config.units import Unit
weather = YahooWeather(APP_ID="", api_key="", api_secret="")

weather.get_yahoo_weather_by_city("Vellore", Unit.celsius)
print(weather.condition.text)
print(weather.condition.temperature)
print(weather.condition.code)
'''
weather.get_yahoo_weather_by_location(35.67194, 51.424438)
print(weather.condition.text)
print(weather.condition.temperature)
'''
weather_code = [0, 0, 0, 0, 0, 0, 0]
temperature = [0, 0, 0, 0, 0, 0, 0]
new_weather = weather.get_forecasts()
for i in range(0, 7):
    weather_code[i] = new_weather[i].code
    temperature[i] = new_weather[i].high
    #print(new_weather[i].text,new_weather[i].code,new_weather[i].high)

for i in range(0, 7):
    print(weather_code[i], temperature[i])
예제 #3
0
from yahoo_weather.weather import YahooWeather
from yahoo_weather.config.units import Unit

data = YahooWeather(
    APP_ID="lMa5T450",
    api_key=
    "dj0yJmk9SE03emFqS3haUlREJmQ9WVdrOWJFMWhOVlEwTlRBbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PTEw",
    api_secret="f53bd8f7a002286ccf8b8a986426f6ecbf24bcb0")

data.get_yahoo_weather_by_city("vienna", Unit.celsius)
print(data.condition.text)
print(data.condition.temperature)

data.get_yahoo_weather_by_location(35.67194, 51.424438)
print(data.condition.text)
print(data.condition.temperature)

data.get_forecasts()[1]
print(data.get_forecasts()[1].as_dict())