Hi all, I was interested in seeing how can I come ...
# pacc-june-14-2023
k
Hi all, I was interested in seeing how can I come over the limitation for task in task , thus I created flows
Copy code
from prefect import flow,task
import httpx

# API to hit - <https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=weathercode,windspeed_10m,soil_temperature_0cm>

@task
def get_windspeed_10m(lat,lon):
    r = httpx.get(f'<https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&hourly=windspeed_10m&forecast_days=1>')
    wind_speed = r.json()['hourly']['windspeed_10m'][0]
    return wind_speed

@task
def get_windspeed_80m(lat,lon):
    r = httpx.get(f'<https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&hourly=windspeed_80m&forecast_days=1>')
    wind_speed = r.json()['hourly']['windspeed_80m'][0]
    return wind_speed

@flow
def get_weather(lat,lon):
    wind_speed_80 = get_windspeed_80m(lat,lon)
    wind_speed = get_windspeed_10m(lat,lon)
    return {
        "wind_speed_80m" :wind_speed_80,
        "wind_speed_10m" :wind_speed
    }


@task
def get_soil_temperature_0cm(lat,lon):
    r = httpx.get(f'<https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&hourly=soil_temperature_0cm&forecast_days=1>')
    soil_temp = r.json()['hourly']['soil_temperature_0cm'][0]
    return soil_temp

@flow
def get_all(lat,lon):
    obj = get_weather(lat,lon)
    soil_temp = get_soil_temperature_0cm(lat,lon)
    print({
        "wind_10m" : obj['wind_speed_10m'],
        "wind_80m" :obj['wind_speed_80m'],
        "soil_temp" :soil_temp,
    })

if __name__  == '__main__' :
    get_all(52,17)
thank you 1
j
You are ahead of the game 🙂 Subflows coming in this unit.
🎯 1