Skip to content

Commit 9ae0679

Browse files
authored
Merge pull request #3462 from yuvipanda/simplify-publisher
Stop using intermediate files in analytics publisher
2 parents ce3ef6e + 77c2a65 commit 9ae0679

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

images/analytics-publisher/indexer.py

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import json
1111
import mimetypes
1212
import os
13-
import tempfile
1413
from datetime import datetime
1514
from glob import glob
1615

@@ -43,33 +42,23 @@ def index_events(project, bucket, debug=False, dry_run=False):
4342
}
4443
)
4544

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+
)
6049

61-
for archive in archives:
62-
jsonlfile.write(json.dumps(archive) + "\n")
50+
if debug:
51+
print(html_index)
6352

64-
htmlfile.seek(0)
65-
jsonlfile.seek(0)
53+
for archive in archives:
54+
jsonl_index = json.dumps(archive) + "\n"
6655

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")
7362

7463
# Upload static assets
7564
for static_file in STATIC_FILES:

0 commit comments

Comments
 (0)