was able to get `email` via automation and discord...
# pacc-june-14-2023
k
was able to get
email
via automation and discord via code itself
Copy code
from prefect import flow,task,get_run_logger
import httpx
from prefect.tasks import task_input_hash
from datetime import timedelta
from prefect.blocks.webhook import Webhook
import json
webhook_url = "<https://discord.com/api/webhooks/1118608415695065140/3HM_Z9wtiruGWQhlXZFEYF7kZNP8Wh1qEk2E7HiEx5KblwCM8WVAsQQ_DgTPr8JwJFK7>"



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

@task(retries=2)
def get_windspeed_10m(lat,lon):
    logger = get_run_logger()
    r = httpx.get(f'<https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&hourly=windspeed_10m&forecast_days=1>')
    <http://logger.info|logger.info>('HEYYYIOO, the code is %s', r.status_code)
    if r.status_code >= 400:
        raise Exception("bad requw")
    wind_speed = r.json()['hourly']['windspeed_10m'][0]
    return wind_speed

@task(cache_key_fn=task_input_hash, cache_expiration=timedelta(seconds=30))
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)
    wind_speed_fasttt = wind_speed_80 * 2
    return {
        "wind_speed_80m" :wind_speed_80,
        "wind_speed_10m" :wind_speed,
        "wind_speed_fasttt" :wind_speed_fasttt,
    }


@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(log_prints=True, name='my_weather_flow_faster_no_cache_16')
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'],
        # "wind_speed_fasttt" :obj['wind_speed_fasttt'],
        "soil_temp" :soil_temp,
    })
    # webhook_block = Webhook.load("discord-hook")
    send_notif('flow is flown :P ')


def send_notif(text):
    message = {
    "content":text  # Message content
}
    payload = json.dumps(message)

# Set the headers for the request
    headers = {
        "Content-Type": "application/json"
    }

    # Send the POST request to the webhook URL with the payload and headers
    response = <http://httpx.post|httpx.post>(webhook_url, data=payload, headers=headers)

    # Check the response status code to see if the message was sent successfully
    if response.status_code == 204:
        print("Message sent successfully!")
    else:
        print("Failed to send message. Response status code:", response.status_code)
        
if __name__  == '__main__' :
    get_all(52,16)
I was not able to get it working through web hook tho 😕