File size: 1,200 Bytes
0b51cd7
 
 
 
 
 
 
 
 
 
 
 
2441327
7ce7422
 
 
 
 
0b51cd7
7ce7422
 
 
0b51cd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
06018df
 
 
 
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
import html, sqlite3
from db import get_conn

def render_rows(rows):
    """
    Render rows as HTML.

    Example:
    render_rows(rows_by_tag("diffusion models"))
    """
    blocks = []
    for t, a, txt, pub in rows:
        #Handle None values by converting to empty strings
        title = html.escape(t) if t is not None else ""
        authors = html.escape(a) if a is not None else ""
        summary = html.escape(txt) if txt is not None else ""
        published = pub[:10] if pub is not None else ""
        
        blocks += [
            f"<h3>{title}</h3>",
            f"<p><b>Authors:</b> {authors} <br><i>{published}</i></p>",
            f"<pre style='white-space:pre-wrap'>{summary}</pre>",
            "<hr>"
        ]
    return "\n".join(blocks) or "<p>No matching papers found.</p>"

def rows_by_tag(keyword: str, limit: int = 25):
    """
    Get rows in databaseby tag.

    Example:
    rows_by_tag("diffusion models")
    """
    conn = get_conn()
    q = f"%{keyword.lower()}%"
    return conn.execute(
        "SELECT title, authors, summary, published FROM papers "
        "WHERE LOWER(tags) LIKE ? ORDER BY published DESC LIMIT ?", (q, limit)
    ).fetchall()