File size: 1,566 Bytes
7a6fa31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
from supabase import Client, create_client

SUPABASE_URL: str = "https://cfivdlyedzbcvjsztebc.supabase.co"
SUPABASE_SECRET_KEY: str = os.environ["SUPABASE_SECRET_KEY"]


def get_client() -> Client:
    return create_client(SUPABASE_URL, SUPABASE_SECRET_KEY)


def get_recipes(urls: list):
    supabase_client = get_client()
    response = (
        supabase_client.table("recipes")
        .select("url, metadata, features, md_ingredients, md_preparation, md_nutrition, md_description, time")
        .in_("url", urls)
        .limit(10)
        .execute()
    )

    return [
        {
            "title": r["metadata"]["title"],
            "thumbnail": r["metadata"].get("thumbnail"),
            "url": r["url"],
            "text": f"""
            TITLE: \n
            {r['metadata']['title']}
            \n\n
            ESTIMATED COOKING / PREPARATION TIME: {r['time']} minutes
            \n\n
            DESCRIPTION: \n
            {r['md_description']}
            \n\n
            INGREDIENTS: \n
            {r['md_ingredients']}
            NUTRITIONAL INFORMATION: \n
            {r['md_nutrition']}
            \n\n
            PREP INSTRUCTIONS: \n
            {r['md_preparation']}

            Source URL: {r['url']}
            \n\n
        """,
        }
        for r in response.data
    ]


def shortlisted_recipes_to_string(recipes):
    output = ""
    if recipes and isinstance(recipes, list):
        for index, r in enumerate(recipes):
            output += f"""Suggestion #{index+1}: {r['text']} \n\n"""
    return output