Skip to content

Commit 56d74d2

Browse files
committed
refactor: improve file handling in transform_publisso_to_publisso_schemaorg function
1 parent 1e3bef4 commit 56d74d2

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

middleware/main.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,12 @@ def transform_publisso_to_publisso_schemaorg():
223223
p1 = subprocess.Popen(
224224
["jq", "-f", str(jq_script), str(input_file)], stdout=subprocess.PIPE
225225
)
226-
p2 = subprocess.Popen(
227-
["jq", "-s", "."], stdin=p1.stdout, stdout=open(tmp_path, "w")
228-
)
229-
p1.stdout.close() # Permite que p1 reciba SIGPIPE si p2 falla
230-
p2.communicate() # Espera a que termine
226+
with open(tmp_path, "w", encoding="utf-8") as outfile:
227+
p2 = subprocess.Popen(
228+
["jq", "-s", "."], stdin=p1.stdout, stdout=outfile
229+
)
230+
p1.stdout.close() # Permite que p1 reciba SIGPIPE si p2 falla
231+
p2.communicate() # Espera a que termine
231232

232233
# Reemplazar archivo original
233234
os.remove(input_file) # Eliminar input original

0 commit comments

Comments
 (0)