Skip to content

Commit

Permalink
Update release script
Browse files Browse the repository at this point in the history
  • Loading branch information
J535D165 committed Apr 4, 2023
1 parent c41f316 commit 4c8267c
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions scripts/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def package(dataset_name, output_folder):
x += PAGE_SIZE


def render_metadata(dataset_config, labels_path):
def render_metadata(dataset_config, output_path, labels_path):
# Add license info?

config = dataset_config.copy()
Expand All @@ -90,28 +90,41 @@ def render_metadata(dataset_config, labels_path):
except KeyError:
pass

try:
print("Metadata of", dataset["key"])

w = Works()["doi:" + dataset["publication"]["doi"]]
w_pub = Works()["doi:" + dataset["publication"]["doi"]]

except requests.exceptions.HTTPError as err:
print("ERROR with metadata of {}:".format(dataset["key"]), err)
with open(Path(output_path, "metadata_publication.json"), "w") as f:
json.dump(w_pub, f, indent=2)

# get the APA style citation
r = requests.get(
"https://doi.org/" + dataset["publication"]["doi"],
headers={"accept": "text/x-bibliography; style=apa; charset=utf-8"},
)
r.encoding = "utf-8"
dataset["publication"]["citation"] = {"apa": r.text}
with open(Path(output_path, "CITATION.txt"), "w") as f:
f.write(r.text)

if "collection" in dataset:
w_col = Works()["doi:" + dataset["collection"]["doi"]]
with open(Path(output_path, "metadata_collection.json"), "w") as f:
json.dump(w_col, f, indent=2)

# get the APA style citation
r = requests.get(
"https://doi.org/" + dataset["collection"]["doi"],
headers={"accept": "text/x-bibliography; style=apa; charset=utf-8"},
)
r.encoding = "utf-8"
with open(Path(output_path, "CITATION_collection.txt"), "w") as f:
f.write(r.text)

# add stats
n, n_included = stats(labels_path)
n, n_included = stats(Path(output_path, labels_path))
config["data"]["n_records"] = n
config["data"]["n_records_included"] = n_included

return config, dict(w)
with open(Path(output_path, "metadata.json"), "w") as f:
json.dump(config, f, indent=2)


if __name__ == "__main__":
Expand Down Expand Up @@ -140,14 +153,8 @@ def render_metadata(dataset_config, labels_path):
output_path = Path("..", "synergy-release", dataset["key"])
output_path.mkdir(exist_ok=True, parents=True)

if 1:
if 0:
package(dataset["key"], output_path)

if 1:
meta, works = render_metadata(dataset, Path(output_path, "labels.csv"))

with open(Path(output_path, "metadata.json"), "w") as f:
json.dump(meta, f, indent=2)

with open(Path(output_path, "publication_metadata.json"), "w") as f:
json.dump(works, f, indent=2)
render_metadata(dataset, output_path, "labels.csv")

0 comments on commit 4c8267c

Please sign in to comment.