File size: 971 Bytes
0b51cd7
 
 
 
c1d68a4
0b51cd7
 
 
 
 
2441327
0b51cd7
c1d68a4
0b51cd7
 
 
 
c1d68a4
0b51cd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import datetime, html
from db import get_conn

"""
Build an HTML digest of the latest papers on a specific topic   .

Example:
build_html(lookback_hours=48)
"""

def build_html():
    today = datetime.date.today().isoformat()
    
    conn = get_conn()
    rows = conn.execute(
        "SELECT title, authors, summary, published "
        "FROM papers WHERE published >= ? "
        "ORDER BY published DESC"
    )

    out = [
        "<!DOCTYPE html>",
        "<meta charset='utf-8'>",
        f"<h1>Literature Digest — {today}</h1>",
        "<style>body{font-family:Arial,Helvetica,sans-serif;max-width:760px;margin:0 auto}</style>"
    ]
    for title, authors, summary, pub in rows:
        out += [
            f"<h2>{html.escape(title)}</h2>",
            f"<p><b>Authors:</b> {html.escape(authors)}<br><i>{pub[:10]}</i></p>",
            f"<pre style='white-space:pre-wrap'>{html.escape(summary)}</pre>",
            "<hr>"
        ]
    return "\n".join(out)