Skip to content

Commit

Permalink
CSV Data retrieval: only write fields present in the first item (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgonnav committed May 5, 2023
1 parent b5a8041 commit 29e226a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions estela_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ def save_data(filename, tmp_filename, format):
data = json.load(F)
with open(filename, "w", encoding="utf-8") as F:
keys = data[0].keys()
writer = csv.DictWriter(F, keys)
writer = csv.DictWriter(F, fieldnames=keys)
writer.writeheader()
writer.writerows(data)
for row in data:
writer.writerow({k: v for k, v in row.items() if k in keys})
os.remove(tmp_filename)


Expand Down

0 comments on commit 29e226a

Please sign in to comment.