This script is a simple Python 3 script that parses a tab-separated values file, puts the column data in a Jinja 2 template, saves each row as a temporary file, and concatenates all the temporary files into a single document.
Here is a flowchart of the script flow using Mermaid code:
graph TD;
A[Parse tsv file]-->B[Render template for each row];
B-->C[Save rendered template to tempfile];
C-->D[Concatenate tempfiles];
The following packages are required to use this script:
Jinja2
Before running the script, the end user needs to make the following changes:
Change the filepath variable to the location of the tab-separated values file they want to parse.
Change the template_string variable to fit the desired output format. The Jinja 2 template syntax can be found in the Jinja 2 documentation. The template should include placeholders for the data from each column, represented as {{ column_name }}. In this script, the column names are column1, column2, and column3.
To use this script with pipenv, follow these steps:
-
Install pipenv if you don't have it already:
pip install pipenv
-
Clone this repository to your local machine.
-
Change to the directory containing the repository and create a virtual environment with pipenv:
cd path/to/repository pipenv install
-
Activate the virtual environment:
pipenv shell python tsv2Jinja.py
To use this script with conda env, follow these steps:
-
Install conda if you don't have it already:
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o miniconda.sh chmod +x miniconda.sh ./miniconda.sh
-
Clone this repository to your local machine.
-
Change to the directory containing the repository and create a conda environment:
cd path/to/repository conda create --name myenv python=3
-
Activate the conda environment:
conda activate myenv
-
Install the required packages:
conda install jinja2
-
Run the script:
python tsv2jinja.py