- Correct SWH id
- Remove the 000 DOI
- Add journal number
- Volume: 8, Issue: 2
- Accepted date: April 11, 2022
- Publication date: May 23, 2022
- Total Papers: 47 + 1 (for editorial)
Dependency: ruamel
from ruamel import yaml
import glob
import os
# print(os.chdir("2021/"))
metadata_files = glob.glob("**/journal/metadata.yaml")
metadata_files = [x for x in metadata_files if "template" not in x]
metadata_files = [x for x in metadata_files if "editorial" not in x]
print("Total projects: ", len(metadata_files))
issues = []
for mfile in metadata_files:
try:
paper = mfile.split("/")[0]
meta = yaml.safe_load(open(mfile))
code_items = {k: v for d in meta["code"] for k, v in d.items()}
print(paper, code_items["doi"])
except:
issues.append(paper)
print(f"Found {len(issues)}")
print(issues)
from ruamel import yaml
import glob
metadata_files = glob.glob("**/journal/metadata.yaml")
metadata_files = [x for x in metadata_files if "template" not in x]
metadata_files = [x for x in metadata_files if "editorial" not in x]
print(len(metadata_files))
issues = []
for mfile in metadata_files:
try:
paper = mfile.split("/")[0]
meta = yaml.safe_load(open(mfile))
code_items = {k: v for d in meta["code"] for k, v in d.items()}
print(paper, code_items["swh"])
print("------")
except:
issues.append(paper)
print(f"Found {len(issues)}")
print(issues)
Check if all teams submitted their projects.
pip install bibtexparser
import bibtexparser
with open('accepted.bib') as bibtex_file:
bib_database = bibtexparser.load(bibtex_file)
print(len(bib_database.entries))
bibkeys = set(bib_database.entries_dict.keys())
print(bibkeys - set(article_number.keys()))
So one guy decided to not submit a camera ready version!
Get access tokens from Zenodo, and then populate here.
export ZENODO_SANDBOX_TOKEN=""
export ZENODO_TOKEN=""
zenodo_tokens = {
'sandbox': "",
'production': ""
}
import json
import yaml
import requests
def reserve_doi(server, token):
""" Reserve a new DOI on Zenodo """
headers = { "Content-Type": "application/json" }
url = f'https://{server}/api/deposit/depositions'
response = requests.post(url, params={'access_token': token},
json={}, headers=headers)
if response.status_code != 201:
raise IOError("%s: " % response.status_code +
str(response))
data = response.json()
return data["id"], data["metadata"]["prereserve_doi"]["doi"]
zenodo_url = {
"sandbox": "sandbox.zenodo.org",
"production": "zenodo.org"
}
def reserve_zenodo_info(server="sandbox"):
server_url = zenodo_url[server]
token = zenodo_tokens[server]
article_id, article_doi = reserve_doi(server_url, token)
article_url = f"https://{server_url}/record/{article_id}/files/article.pdf"
return article_id, article_doi, article_url
print(reserve_zenodo_info("production"))
The following script automatically updates the metadata.yaml files with the publishing information, and reserves the DOI from Zenodo. Test this script first setting “zenodo_server” to “sandbox”.
import glob
import re
metadata_files = glob.glob("**/journal/metadata.yaml")
metadata_files = [x for x in metadata_files if "template" not in x]
metadata_files = [x for x in metadata_files if "editorial" not in x]
print(len(metadata_files))
def update_line(lines, search, dest):
dt_line = [i for i,line in enumerate(lines) if search in line]
assert len(dt_line) == 1, f"Found {len(dt_line)} matches"
lines[dt_line[0]] = dest
return lines
def update_article(lines, doi="", url=""):
article_start = [i for i, line in enumerate(lines) if line.startswith("article:")]
article_end = [i for i, line in enumerate(lines) if line.startswith("journal:")]
assert len(article_start) == 1
assert len(article_end) == 1
article_start = article_start[0]
article_end = article_end[0] - 2
doi_line = [i for i, line in enumerate(lines) if (i > article_start and i < article_end and "doi:" in line)]
assert len(doi_line) == 1
doi_line = doi_line[0]
url_line = [i for i, line in enumerate(lines) if (i > article_start and i < article_end and "url:" in line)]
assert len(url_line) == 1
url_line = url_line[0]
lines[doi_line] = f" - doi: {doi}\n"
lines[url_line] = f" - url: {url}\n"
return lines
issues = []
article_number = {}
metadata_files = list(sorted(metadata_files))
metadata_files.append("editorial/journal/metadata.yaml")
zenodo_server = "production"
# debug
# metadata_files = [metadata_files[0]]
for mfile in metadata_files:
try:
paper = mfile.split("/")[0]
## load the paper
lines = []
with open(mfile) as fp:
for line in fp:
lines.append(line)
## sequential updates
if paper != "editorial":
lines = update_line(lines, "received:", " - received: February 4, 2022\n")
lines = update_line(lines, "accepted:", " - accepted: April 11, 2022\n")
lines = update_line(lines, "published:", " - published: May 23, 2022\n")
# lines = update_line(lines, "- name: Koustuv Sinha", " - name: Koustuv Sinha,\\\\ Sharath Chandra Raparthy\n")
article_number[paper] = len(article_number) + 1
lines = update_line(lines, "number:", f" - number: {article_number[paper]}\n")
lines = update_line(lines, "volume:", " - volume: 8\n")
lines = update_line(lines, "issue:", " - issue: 2\n")
# Update DOI
## fetch from Zenodo
article_id, article_doi, article_url = reserve_zenodo_info(zenodo_server)
lines = update_article(lines, doi=article_doi, url=article_url)
# update file
with open(mfile, "w") as fp:
for line in lines:
fp.write(line)
except Exception as e:
issues.append(paper)
raise(e)
print(f"Found {len(issues)}")
print(issues)