Command line tool and library to parse and generate Canadian Common CV (CCV) files
Project description
CCV Generator
Helps import and generate CCVs (Canadian Common CV) by relying on an intermediary yaml format. The generated XML files can then be imported in the CCV website. In short, it helps you:
- Convert an XML CCV to a readable and editable yaml format
- Convert a yaml CCV to an XML CCV (so that it can be imported in the CCV website)
- Generate a new CCV from scratch using a yaml template
The code can also be used as an API to build CCV generators.
Installation
pip install ccv-generator
Usage (Command line)
ccv_generator -h
usage: ccv_generator [-h] [-i INPUT] [-f FILTER] [-q | --quiet | --no-quiet] output
Generate a CCV XML file from a YAML file. Or export a CCV XML file to a YAML file.
positional arguments:
output The output file. Can be either a CCV XML file or a YAML file.
options:
-h, --help show this help message and exit
-i INPUT, --input INPUT
The input file. Can be either a CCV XML file or a YAML file.
-f FILTER, --filter FILTER
Filter to parse only a subset of the CCV XML file. Should be a path of the section(s) to parse (e.g., "Contributions/Publications/Conference Publications" to export
only Conference Publications)
-q, --quiet, --no-quiet
Avoid adding comments to the generated yaml file (default: False)
Examples
Convert a CCV XML file to a YAML file
ccv_generator -i ccv.xml ccv.yaml
Convert a YAML file to a CCV XML file
ccv_generator -i ccv.yaml ccv.xml
Generate a CCV yaml template
ccv_generator ccv.yaml
This will generate a CCV yaml file with the default structure. You can then edit the file and use it to generate a CCV XML file. You can also only generate a specific section of the CCV (e.g., only conference publications) by using the -f option:
ccv_generator -f "Contributions/Publications/Conference Publications" ccv.yaml
Usage (API)
Two functions are exposed to read and generate CCV xml files from/to python dictionaries:
parse_xml_ccv, build_xml_ccv
parse_xml_ccv(tree_model, section_filter=[], add_comments=True) -> dict: Reads an XML structure and returns a dictionary representation of the CCV.build_xml_ccv(data) -> str: Builds an XML structure from a dictionary representation of the CCV. The dictionary should be in the format expected by the CCV XML schema.
Example
Converting a bibtex (.bib) to the publication section of the CCV that can be imported in the CCV website (requires pybtex):
from pybtex.database.input import bibtex
from ccv_generator import build_xml_ccv
import xml.etree.ElementTree as ET
MY_NAME = "John Doe"
publications = {
"Contributions": {
"Publications": {
"Journal Articles": [],
}
}
}
parser = bibtex.Parser()
bib_data = parser.parse_file('publications.bib')
def get_author(author):
return " ".join(author.first_names) + " " + " ".join(author.last_names)
def location_to_country(location):
location = location.split(",")[-1].strip()
if location == "USA": location = "United States of America"
return location
for entry in bib_data.entries:
entry_data = bib_data.entries[entry]
publication = {}
author_position = 1
if get_author(entry_data.persons["author"][0]) == MY_NAME:
author_position = 0
elif get_author(entry_data.persons["author"][-1]) == MY_NAME:
author_position = -1
publication["Contribution Role"] = "Co-Author"
if author_position == 0:
publication["Contribution Role"] = "First Listed Author"
elif author_position == -1:
publication["Contribution Role"] = "Last Listed Author"
publication["Contribution Percentage"] = "81-90" if author_position == 0 else "31-40"
publication["Number of Contributors"] = str(len(entry_data.persons["author"]))
publication["Authors"] = "; ".join([str(author) for author in entry_data.persons["author"]])
if "journal" in entry_data.fields:
publication["Article Title"] = entry_data.fields["title"]
publication["Journal"] = entry_data.fields["journal"]
publication["Volume"] = entry_data.fields["volume"]
#publication["Issue"] =
publication["Page Range"] = entry_data.fields["pages"] if "pages" in entry_data.fields else "1-" + entry_data.fields["numpages"]
publication["Publishing Status"] = "Published"
publication["Year"] = entry_data.fields["year"]
#publication["Publisher"] = entry_data.fields["publisher"]
#publication["Description / Contribution Value"] =
publication["URL"] = entry_data.fields["url"]
publication["Refereed?"] = "Yes"
#publication["Open Access"] = "Yes"
#publication["Synthesis?"] = "Yes"
publication["DOI"] = entry_data.fields["doi"]
publications["Contributions"]["Publications"]["Journal Articles"].append(publication)
output_root = build_xml_ccv(publications)
# write to file (idented)
ET.indent(output_root)
output_tree = ET.ElementTree(output_root)
output_tree.write("publications.xml", encoding="utf-8", xml_declaration=True, method="xml")
Note: some fields are required from the CCV but missing from the bibtex (e.g., contribution percentage, contribution value). In the example, some of thee fields are being reconstructed from the info we do have. The others are left blank.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ccv_generator-0.1.0.tar.gz.
File metadata
- Download URL: ccv_generator-0.1.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a20faed6aa2d4d70de3a5966a967a22d087dc6ea966a016e15c38566c5c9eb0d
|
|
| MD5 |
e9fc8faf9bbb1f35b6cf934d3ba1e570
|
|
| BLAKE2b-256 |
1e4493cf79c00a7c1999a8fe32d1a34de88f1a7f68920909c4b717d307437009
|
Provenance
The following attestation bundles were made for ccv_generator-0.1.0.tar.gz:
Publisher:
publish.yml on m-damien/CCV-Generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ccv_generator-0.1.0.tar.gz -
Subject digest:
a20faed6aa2d4d70de3a5966a967a22d087dc6ea966a016e15c38566c5c9eb0d - Sigstore transparency entry: 202338914
- Sigstore integration time:
-
Permalink:
m-damien/CCV-Generator@47e257864f017342540fd942a91d813bc41a7059 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/m-damien
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@47e257864f017342540fd942a91d813bc41a7059 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file ccv_generator-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ccv_generator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3fc696e8857f8c6ca19eb932472e9c2ceba47d586fa52fde4b0a652c6093868
|
|
| MD5 |
5f2e586ff03d4a5e7334398b35376272
|
|
| BLAKE2b-256 |
38002ba47d72b3d9b8a10e745d3a356a4f0ac8c0eda17cf00e274d12ed04a770
|
Provenance
The following attestation bundles were made for ccv_generator-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on m-damien/CCV-Generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ccv_generator-0.1.0-py3-none-any.whl -
Subject digest:
a3fc696e8857f8c6ca19eb932472e9c2ceba47d586fa52fde4b0a652c6093868 - Sigstore transparency entry: 202338924
- Sigstore integration time:
-
Permalink:
m-damien/CCV-Generator@47e257864f017342540fd942a91d813bc41a7059 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/m-damien
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@47e257864f017342540fd942a91d813bc41a7059 -
Trigger Event:
workflow_dispatch
-
Statement type: