File size: 742 Bytes
e9d7f7e
 
a8198ca
e9d7f7e
ceb63d6
5dee603
e9d7f7e
a8198ca
 
e9d7f7e
 
 
 
a8198ca
 
 
 
918191f
 
 
 
 
 
 
a8198ca
918191f
a8198ca
918191f
 
 
ceb63d6
e9d7f7e
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
from fastapi import FastAPI
import os
import duckdb

data_dir = os.environ.get("DATA_DIR", "./data")
db_path = data_dir + "/db/cc_explorer.db"

print("db_path", db_path)

app = FastAPI()

@app.get("/")
def greet_json():

    con = duckdb.connect()
    con.execute("INSTALL sqlite; LOAD sqlite;")

    try: 
        row = con.execute("""
            SELECT crawl_id
            FROM sqlite_scan(?, 'crawls')
            ORDER BY crawl_date DESC
            LIMIT 1
        """, [db_path]).fetchone()

        latest_crawl_id = row[0]

    except Exception:
        latest_crawl_id = "n/a"

    return {"Hello": "World!", "latest_crawl": latest_crawl_id, "exists": os.path.exists(db_path), "data_ls": os.listdir(data_dir), "db_path": db_path}