From 756daa6c0745d020dec6994ef7e1a6f26354976d Mon Sep 17 00:00:00 2001 From: Mikkel Munch Mortensen <3xm@detfalskested.dk> Date: Wed, 22 Mar 2023 10:33:49 +0100 Subject: [PATCH] Include additional request headers In order to make this look like a "real" browser request, hoping it will improve the reliability. --- frokostbot.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/frokostbot.py b/frokostbot.py index 1c05570..9e1ea5f 100644 --- a/frokostbot.py +++ b/frokostbot.py @@ -49,9 +49,22 @@ def get_photo_url(menu: str): sys.exit(1) token = json.loads(cookie)[0] headers = { - "Accept": "application/json;odata=verbose", - "Content-Type": "application/json;odata=verbose", + "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0", + "Accept": "application/json", + "Accept-Language": "en-US,en;q=0.5", + "Accept-Encoding": "gzip, deflate, br", + "Content-Type": "application/json", + "Origin": "https://www.craiyon.com", + "Connection": "keep-alive", + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-site", + "Sec-GPC": "1", + "Pragma": "no-cache", + "Cache-Control": "no-cache", + "TE": "trailers", } + request_data = { "prompt": translation, "version": "35s5hfwn9n78gb06", @@ -135,13 +148,14 @@ else: "flag-gr": ["græsk", "grækenland"], "fish": ["fisk", "laks", "rødspætte", "sej "], "shrimp": ["reje"], - "pig2": ["skinke", "gris"], + "pig2": ["skinke", "gris", "nakkefilet"], "cow": ["hakkebøf"], "cow2": ["kalv", "okse"], "chicken": ["kylling", "chicken"], "turkey": ["kalkun"], "rabbit2": [" hare"], "rooster": ["coq au vin"], + "egg": [" æg ", " ægge"], "falafel": ["falafel"], "hot_pepper": ["chili", "hot sauce"], "onion": ["løg"], @@ -157,7 +171,7 @@ else: "wine_glass": ["coq au vin"], "bowl_with_spoon": ["suppe"], "stew": ["gryde", "gullasch"], - "rice": [" ris", "ris "], + "rice": [" ris "], "ramen": ["nudler"], "cloud": ["sky"], "potato": ["kartoffel", "kartofler"], @@ -168,7 +182,7 @@ else: "gift_heart": ["valentines"], }.items(): for keyword in keywords: - if keyword in menu.lower(): + if keyword in f" {menu.lower()} ": emojis.append(emoji) break if emojis: @@ -214,7 +228,7 @@ if photo is not None: "type": "image", "image_url": photo[0], "alt_text": ( - f"En kunstig intelligens' fortolkning af dagens menu på engelsk: {photo[1]}" + "Et ukvalificeret bud på hvordan dagens menu kunne se ud" ), }