Exemple #1
0
def do_i_need_umbrella(location: Location = fastapi.Depends()):

    output = UmbrellaStatus(weather_category='unknown',
                            bring_umbrella=False,
                            temp=0.0)

    return output
Exemple #2
0
async def needUmbrella(location: Location = fastapi.Depends()):
    url = f'https://weather.talkpython.fm/api/weather?city={location.city}&country={location.country}&units=imperial'
    if location.state:
        url += f'&state={location.state}'

    async with httpx.AsyncClient() as client:
        response = await client.get(url)
        response.raise_for_status()

        data = response.json()

    print(data)

    weather = data.get('weather', {})
    category = weather.get('category', 'UNKNOWN')

    forecast = data.get('forecast', {})

    temp = forecast.get('temp', 0.0)

    bring = category.lower().strip() in {'rain', 'mist'}

    umbrella = UmbrellaStatus(bring_umbrella=bring, temp=temp)

    #print(data)
    return umbrella
async def do_i_need_an_umbrella(location: Location = fastapi.Depends()):
    data = await live_weather_service.get_live_report(location)
    weather = data.get("weather", {})
    category = weather.get("category", "UNKNOWN")
    forecast = data.get("forecast", {})
    temp = forecast.get("temp", 0.0)
    bring = category.lower().strip() in {"rain", "mist"}
    umbrella = UmbrellaStatus(bring_umbrella=bring, temp=temp, weather=category)
    return umbrella
Exemple #4
0
async def do_i_need_an_umbrella(location: Location = fastapi.Depends()):
    data = await live_weather_service.get_live_report(location)

    weather = data.get('weather', {})
    category = weather.get('category', 'UNKNOWN')

    forecast = data.get('forecast', {})
    temp = forecast.get('temp', 0.0)
    bring = category.lower().strip() in {'rain', 'mist'}

    return UmbrellaStatus(bring_umbrella=bring, temp=temp, weather=category)
Exemple #5
0
def do_i_need_umbrella(location: Location = fastapi.Depends()):

    url = f"https://weather.talkpython.fm/api/weather?city={location.city}&country={location.country}"

    response = requests.get(url)

    if response.status_code == 200:
        data = response.json()

    forecast = data.get('forecast', {})
    temp = forecast.get('temp', {})

    umbrella = UmbrellaStatus(bring_umbrella=False,
                              temp=temp,
                              weather_category='unknown')

    return umbrella
Exemple #6
0
async def do_i_need_umbrella(location: Location = fastapi.Depends()):

    data = await live_weather_service.get_live_data(location)

    weather = data.get('weather', {})
    category = weather.get('category', 'unknown')

    forecast = data.get('forecast', {})
    temp = forecast.get('temp', -100)

    bring = category.lower() == 'clouds'

    umbrella = UmbrellaStatus(weather_category=category,
                              bring_umbrella=bring,
                              temp=temp)

    return umbrella
async def do_i_need_an_umbrella(location: Location = fastapi.Depends()):
    url = f"https://weather.talkpython.fm/api/weather?city={location.city}&country={location.country}"
    if location.state:
        url += f"&state={location.state}"

    async with httpx.AsyncClient() as client:
        res = await client.get(url)
        res.raise_for_status()

        data = res.json()

        weather = data.get("weather", {})
        forecast = data.get("forecast", {})

        cat = weather.get("category", "UNKNOWN")
        temp = forecast.get('temp', 0.0)

        bring = cat.lower().strip() in {'rain', 'mist'}

        print("*****************:::")
        print(temp)
    return UmbrellaStatus(bring_umbrella=bring, temp=temp)