Skip to content

Commit

Permalink
Modify dump_entities_to_json method (#33) (#34)
Browse files Browse the repository at this point in the history
* Modify dump_entities_to_json method

* Minor version bump to v0.4.1

Co-authored-by: Kunal Tawatia <tawatia.1@iitj.ac.in>
  • Loading branch information
Gabriel Altay and kunaltawatia authored Mar 8, 2022
1 parent ca783ea commit bf4825d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion qwikidata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"""Metadata for this package."""

__package_name__ = "qwikidata"
__version__ = "0.4.0"
__version__ = "0.4.1"
15 changes: 9 additions & 6 deletions qwikidata/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ def dump_entities_to_json(entities: Iterable[WikidataEntity], out_fname: str) ->
Output file name
"""
with open(out_fname, "w") as fp:
fp.write("[\n")
for ent_lo, ent_hi in pairwise(entities):
ent_str = json.dumps(ent_lo._entity_dict)
fp.write("{},\n".format(ent_str))
ent_str = json.dumps(ent_hi._entity_dict)
fp.write("{}".format(ent_str))
fp.write("[")

ent = next(entities, None)
while ent:
ent_str = json.dumps(ent._entity_dict)
fp.write("\n{}".format(ent_str))
ent = next(entities, None)
if ent: fp.write(",")

fp.write("\n]")

0 comments on commit bf4825d

Please sign in to comment.