|
10 | 10 | import json |
11 | 11 | import mimetypes |
12 | 12 | import os |
13 | | -import tempfile |
14 | 13 | from datetime import datetime |
15 | 14 | from glob import glob |
16 | 15 |
|
@@ -43,33 +42,23 @@ def index_events(project, bucket, debug=False, dry_run=False): |
43 | 42 | } |
44 | 43 | ) |
45 | 44 |
|
46 | | - with tempfile.TemporaryFile(mode="w+") as htmlfile, tempfile.TemporaryFile( |
47 | | - mode="w+" |
48 | | - ) as jsonlfile: |
49 | | - html_index = html_template.render( |
50 | | - archives=sorted( |
51 | | - archives, key=lambda archive: archive["date"], reverse=True |
52 | | - ), |
53 | | - generated_time=datetime.utcnow().isoformat() + "Z", |
54 | | - ) |
55 | | - |
56 | | - if debug: |
57 | | - print(html_index) |
58 | | - |
59 | | - htmlfile.write(html_index) |
| 45 | + html_index = html_template.render( |
| 46 | + archives=sorted(archives, key=lambda archive: archive["date"], reverse=True), |
| 47 | + generated_time=datetime.utcnow().isoformat() + "Z", |
| 48 | + ) |
60 | 49 |
|
61 | | - for archive in archives: |
62 | | - jsonlfile.write(json.dumps(archive) + "\n") |
| 50 | + if debug: |
| 51 | + print(html_index) |
63 | 52 |
|
64 | | - htmlfile.seek(0) |
65 | | - jsonlfile.seek(0) |
| 53 | + for archive in archives: |
| 54 | + jsonl_index = json.dumps(archive) + "\n" |
66 | 55 |
|
67 | | - if not dry_run: |
68 | | - html_blob = bucket.blob("index.html") |
69 | | - html_blob.upload_from_file(htmlfile, content_type="text/html") |
70 | | - print("Uploaded index.html") |
71 | | - bucket.blob("index.jsonl").upload_from_file(jsonlfile) |
72 | | - print("Uploaded index.jsonl") |
| 56 | + if not dry_run: |
| 57 | + html_blob = bucket.blob("index.html") |
| 58 | + html_blob.upload_from_string(html_index, content_type="text/html") |
| 59 | + print("Uploaded index.html") |
| 60 | + bucket.blob("index.jsonl").upload_from_string(jsonl_index) |
| 61 | + print("Uploaded index.jsonl") |
73 | 62 |
|
74 | 63 | # Upload static assets |
75 | 64 | for static_file in STATIC_FILES: |
|
0 commit comments