State of the D&I (This is Not a Canon) Project:
: Deniz Aydin
Minutes: 10
The project repository is here.
Methods in src/pythonhtml/run_scripts.py
, which is the main script that is exercised by the build process:
copytree()
:
src
(type:str
): The source directory to copy from.dst
(type:str
): The destination directory to copy to.symlinks
(type:bool
, default:False
): Whether to copy symlinks as symlinks. IfFalse
, the actual files are copied.ignore
(type:function
orNone
, default:None
): A function that can be used to decide which files to ignore when copying.
main()
:
style
(type:str
, default:MLA
): The citation style to be used for formatting the bibliography. Available options are:MLA
(default): Format citations in MLA style.
Components in the main part of the script:
converter.Converter
:
convert()
: Converts raw bibliographic data into a standardized format for citation styling.
format_html.FormatHTML
:
stylize()
: Applies the selected citation style (i.e. at the moment, just MLA) to the bibliographic data.
generate_biblio.Biblio
:
make_biblio()
: Compiles the formatted citations into a complete bibliography.
Content Copying:
copytree()
: Copies files from thecontent/
directory to thetemp/
directory.
Note that this script is integrated into the build process, and needs additional steps to be able to run as a standalone.
Dependencies:
python3
needs to be the default Python interpreter, and a venv (a virtual environment) needs to be created at the project root directoryrequests
for API calls to Zoteropandas
for dataframe processingjinja2
for HTML templatingbeautifulsoup4
for HTML styling and prettifyingshutil
(for file copying operations)argparse
(for argument parsing, which specifies the citation style)src.pythonhtml.converter
(for bibliographic data conversion)src.pythonhtml.format_html
(for formatting citations)src.pythonhtml.generate_biblio
(for generating bibliographies)
Example Workflow:
- Execute
ant
at the root level. (Default: MLA style)
run_scripts.py
is called by the build process. This script makes calls to the three methods mentioned above in that order. The first call is to a converter, which has hard-coded API calls to KMLF’s two Zotero libraries, 25 Literary Works
and 25 Critical Works
(in src/pythonhtml/converter.py
). These Zotero libraries are still under works, in that they do not both have all of their 25 entries yet. That is to be expected. This particular Python file also deals with changing the Roman-numeral page numbers into Arabic numerals for standardization. create_webpage()
method calls out to a JSON-to-HTML converter which I’ve developed based on someone’s open source code. This is the crux of the code, and is also the part which makes use of the entry.html
Jinja template (Information on Jinja templating engine can be found here.). The second call is to src/pythonhtml/format_html.py
, which simply prettifies the individual entry HTMLs. Finally, there is a call out to src/pythonhtml/generate_biblio.py
, which compiles 25 Critical Works
and 25 Literary Works
bibliographies from individual entry pages, using a biblio.html
Jinja template.