File size: 1,352 Bytes
85cec0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Helper formatting functions
def format_local_map(result):
    html = (
        f"<div><strong>Local Map:</strong><br>"
        f"<a href='{result.get('link','')}' target='_blank'>View on Google Maps</a><br>"
        f"<img src='{result.get('image','')}' style='width:100%;'/></div>"
    )
    return html

def format_knowledge(result):
    html = (
        f"<div><strong>{result.get('title','Unknown')}</strong><br>"
        f"Type: {result.get('type','')}<br>"
        f"Born: {result.get('born','')}<br>"
        f"Died: {result.get('died','')}</div>"
    )
    return html

def format_images(result):
    # Extract 'original' URL from each image dict.
    urls = [item.get("original", "") for item in result]
    return urls

def format_videos(result):
    html = "<div>"
    for vid in result:
        html += (
            f"<div style='margin-bottom:10px;'>"
            f"<video controls style='width:100%;' src='{vid.get('link','')}'></video><br>"
            f"{vid.get('title','')}"
            f"</div>"
        )
    html += "</div>"
    return html

def format_links(result):
    html = "<div><ul>"
    for url in result:
        # Use the final part of the URL as the title.
        title = url.rstrip('/').split('/')[-1]
        html += f"<li><a href='{url}' target='_blank'>{title}</a></li>"
    html += "</ul></div>"
    return html