Update to use Craiyon v3
This commit is contained in:
parent
756daa6c07
commit
0e4f3f6151
|
@ -66,14 +66,17 @@ def get_photo_url(menu: str):
|
|||
}
|
||||
|
||||
request_data = {
|
||||
"model": "photo",
|
||||
"negative_prompt": "",
|
||||
"prompt": translation,
|
||||
"version": "35s5hfwn9n78gb06",
|
||||
"token": token,
|
||||
"version": "35s5hfwn9n78gb06",
|
||||
}
|
||||
sys.stdout.write("Asking Craiyon to generate images for the menu...\n")
|
||||
craiyon_start = datetime.datetime.now()
|
||||
try:
|
||||
response = requests.post(
|
||||
"https://api.craiyon.com/draw",
|
||||
"https://api.craiyon.com/v3",
|
||||
headers=headers,
|
||||
json=request_data,
|
||||
timeout=90,
|
||||
|
@ -87,6 +90,7 @@ def get_photo_url(menu: str):
|
|||
except JSONDecodeError:
|
||||
sys.stderr.write("Unable to parse JSON from Craiyon response:\n")
|
||||
sys.stderr.write(f"{response.text}\n")
|
||||
sys.stderr.write("Waited for {datetime.datetime.now() - craiyon_start}.")
|
||||
return None
|
||||
|
||||
return (f"https://img.craiyon.com/{image}", translation)
|
||||
|
@ -119,16 +123,22 @@ response = requests.post(
|
|||
)
|
||||
data = response.json()
|
||||
sys.stdout.write("Data retrieved from SharePoint.\n")
|
||||
|
||||
# Extract today's menu from the SharePoint data.
|
||||
today = datetime.date.today().strftime("%d-%m-%Y")
|
||||
menu = None
|
||||
if "error" in data:
|
||||
if response.status_code != 200:
|
||||
hook_url = SLACK_ERROR_HOOK
|
||||
photo = None
|
||||
message = plain_message = (
|
||||
f"SharePoint responded with status {response.status_code} :("
|
||||
)
|
||||
else:
|
||||
# Extract today's menu from the SharePoint data.
|
||||
today = datetime.date.today().strftime("%d-%m-%Y")
|
||||
menu = None
|
||||
if "error" in data:
|
||||
message = plain_message = f"Error: {data['error']['message']['value']}"
|
||||
photo = None
|
||||
hook_url = SLACK_ERROR_HOOK
|
||||
sys.stderr.write(f"SharePoint {message}\n")
|
||||
else:
|
||||
else:
|
||||
hook_url = SLACK_SUCCESS_HOOK
|
||||
for entry in data["ListData"]["Row"]:
|
||||
if entry.get("DAto") == today:
|
||||
|
@ -146,7 +156,7 @@ else:
|
|||
for emoji, keywords in {
|
||||
"flag-in": ["indisk", "indien"],
|
||||
"flag-gr": ["græsk", "grækenland"],
|
||||
"fish": ["fisk", "laks", "rødspætte", "sej "],
|
||||
"fish": ["fisk", "laks", "rødspætte", "sej ", "kulmule"],
|
||||
"shrimp": ["reje"],
|
||||
"pig2": ["skinke", "gris", "nakkefilet"],
|
||||
"cow": ["hakkebøf"],
|
||||
|
@ -162,7 +172,10 @@ else:
|
|||
"mango": ["mango"],
|
||||
"mushroom": ["svampe", "kantarel", "champignon"],
|
||||
"eggplant": ["moussaka", "mousakka"],
|
||||
"cheese_wedge": [" ost"],
|
||||
"beans": ["bønne"],
|
||||
"olive": ["oliven"],
|
||||
"spaghetti": ["spaghetti"],
|
||||
"hamburger": ["burger"],
|
||||
"sandwich": ["sandwich"],
|
||||
"stuffed_flatbread": ["pita"],
|
||||
|
@ -224,13 +237,19 @@ payload = {
|
|||
}
|
||||
|
||||
if photo is not None:
|
||||
payload["blocks"][0]["accessory"] = {
|
||||
photo_text = "Et ukvalificeret bud på hvordan dagens menu kunne se ud"
|
||||
payload["blocks"].insert(
|
||||
0,
|
||||
{
|
||||
"type": "image",
|
||||
"image_url": photo[0],
|
||||
"alt_text": (
|
||||
"Et ukvalificeret bud på hvordan dagens menu kunne se ud"
|
||||
),
|
||||
"alt_text": photo_text,
|
||||
"title": {
|
||||
"type": "plain_text",
|
||||
"text": photo_text,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
sys.stdout.write("Posting menu to Slack...\n")
|
||||
hook = request.Request(
|
||||
|
|
Loading…
Reference in a new issue