File size: 601 Bytes
5830944
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import zipfile, json, os, time

def journalist_export(results, out_path):
    index = []
    with zipfile.ZipFile(out_path, "w", zipfile.ZIP_DEFLATED) as z:
        for i,r in enumerate(results):
            meta = {
                "source": r.get("source"),
                "url": r.get("url"),
                "snippet": r.get("snippet"),
                "timestamp": time.time()
            }
            name = f"doc_{i}.json"
            z.writestr(name, json.dumps(meta, indent=2))
            index.append(meta)
        z.writestr("INDEX.json", json.dumps(index, indent=2))
    return out_path