Include additional request headers

In order to make this look like a "real" browser request, hoping it will
improve the reliability.
This commit is contained in:
Mikkel Munch Mortensen 2023-03-22 10:33:49 +01:00
parent 925e896991
commit 756daa6c07

View file

@ -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"
),
}