Spaces:
Sleeping
Sleeping
Create ingest/export.py
Browse files- ingest/export.py +5 -10
ingest/export.py
CHANGED
|
@@ -2,20 +2,15 @@ import io
|
|
| 2 |
import zipfile
|
| 3 |
|
| 4 |
def export_results_zip(results):
|
| 5 |
-
"""
|
| 6 |
-
results: list[dict]
|
| 7 |
-
returns: BytesIO zip
|
| 8 |
-
"""
|
| 9 |
buffer = io.BytesIO()
|
| 10 |
with zipfile.ZipFile(buffer, "w", zipfile.ZIP_DEFLATED) as zf:
|
| 11 |
for i, r in enumerate(results, start=1):
|
| 12 |
content = (
|
| 13 |
-
f"Source: {r
|
| 14 |
-
f"Title: {r
|
| 15 |
-
f"URL: {r
|
| 16 |
-
f"Snippet:\n{r
|
| 17 |
)
|
| 18 |
-
zf.writestr(f"{i:03d}_{r
|
| 19 |
-
|
| 20 |
buffer.seek(0)
|
| 21 |
return buffer
|
|
|
|
| 2 |
import zipfile
|
| 3 |
|
| 4 |
def export_results_zip(results):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
buffer = io.BytesIO()
|
| 6 |
with zipfile.ZipFile(buffer, "w", zipfile.ZIP_DEFLATED) as zf:
|
| 7 |
for i, r in enumerate(results, start=1):
|
| 8 |
content = (
|
| 9 |
+
f"Source: {r['source']}\n"
|
| 10 |
+
f"Title: {r['title']}\n"
|
| 11 |
+
f"URL: {r['url']}\n\n"
|
| 12 |
+
f"Snippet:\n{r['snippet']}"
|
| 13 |
)
|
| 14 |
+
zf.writestr(f"{i:03d}_{r['source']}.txt", content)
|
|
|
|
| 15 |
buffer.seek(0)
|
| 16 |
return buffer
|