Taylor Curran
06/14/2023, 5:15 PMlisa fang
06/14/2023, 5:16 PMJeff Hale
06/14/2023, 5:34 PMTim A
06/14/2023, 5:41 PMJeff Hale
06/14/2023, 5:42 PMRun the flow a few times from the CLI
Jennifer Lauv
06/14/2023, 5:49 PMTim A
06/14/2023, 5:51 PMSanthosh Solomon (Fluffy)
06/14/2023, 5:54 PMCody
06/14/2023, 5:54 PMCody
06/14/2023, 5:55 PMVipul Mascarenhas
06/14/2023, 5:57 PMSahil Rangwala
06/14/2023, 5:58 PMKrishna Lodha
06/14/2023, 6:01 PMKrishna Lodha
06/14/2023, 6:01 PMwebhook_block = Webhook.load("discord-hook")
but not sure how to go furtherKrishna Lodha
06/14/2023, 6:01 PMJeff Hale
06/14/2023, 6:04 PMKrishna Lodha
06/14/2023, 6:31 PMemail
via automation and discord via code itself
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)
brittany bennett
06/14/2023, 6:33 PMbrittany bennett
06/14/2023, 7:07 PMKrishna Lodha
06/14/2023, 7:10 PMprefect deploy flowtest.py:get_all
command , where get_all
is my flow and it needs paramsTaylor Curran
06/14/2023, 7:13 PMJeff Hale
06/14/2023, 7:28 PMTim A
06/14/2023, 7:31 PMFile "D:\Packages\Miniconda\envs\prefect\lib\site-packages\prefect\cli\deploy.py", line 391, in _run_single_deploy
flow_name = flow.name
AttributeError: 'NoneType' object has no attribute 'name'
An exception occurred.
Cody
06/14/2023, 7:35 PMCody
06/14/2023, 7:35 PMprefect deploy .\flow.py:my_flow
kiran
06/14/2023, 7:45 PMJeff Hale
06/14/2023, 7:55 PMJeff Hale
06/14/2023, 7:55 PMTim A
06/14/2023, 7:58 PMbrittany bennett
06/14/2023, 8:11 PMlate
?