DOI Utilities¶
- append_line(path: str | Path, line: str) → None[source]¶
Append a single line (with newline) to a text file.
Creates the file if it does not exist.
- Parameters:
path – Destination file path.
line – Text to append (newline is added automatically).
- doi_to_filename(doi: str, suffix: str = '.xml') → str[source]¶
Convert a DOI to a safe filename.
Replaces every character that is not word-safe, a hyphen, underscore, or dot with
_.- Parameters:
doi – Raw DOI string, e.g.
"10.1016/j.actamat.2020.01.001".suffix – File extension (default
".xml").
- Returns:
e.g.
"10.1016_j.actamat.2020.01.001.xml"- Return type:
str
- filename_to_doi(filename: str | Path) → str[source]¶
Reverse
doi_to_filename: convert a stem back to a DOI.Handles the Springer convention where the first
_after the registrant prefix (10.XXXX) maps back to/.- Parameters:
filename – File path or bare filename, e.g.
"10.1007_s42114-026-01633-w.xml".- Returns:
DOI string, e.g.
"10.1007/s42114-026-01633-w", or""if the stem does not look like a DOI.- Return type:
str