Skip to main content

A tool to manipulate csv file with headers

Project description

csvformatmail: A tool to format mails from csv and to send them

Installing

From pypi (not yet on pypi):

pip3 install csvformatmail

Or developer version:

git clone <this repo>
cd csvformatmail
pip3 install -e .

Enable completion (for bash or other shells using bash-completion)

mkdir -p ~/.local/share/bash-completion/completions
register-python-argcomplete csvformatmail > ~/.local/share/bash-completion/completions/csvformatmail

Python module

All methods and functions are accessible in the python module.

Example

Write a mail template:

From: My name <my-mail-address@example.org>
To: {mail}
Subject: Result of the last test

Dear {firstname} {lastname.capitalize()},

Your results of the last test are:

 - Part A: {a:.1f}
 - Part B: {b:.1f}

Therefore you {"pass" if a+b>50 else "fail"} the test.

-- 
signature

Use a csv file with (at least) the columns firstname, lastname, mail, a and b:

firstname,lastname,mail,a,b,c
Jacques,MARTIN,jacques.martin@example.org,12.54441,14,1111.221
…

And the command:

csvformatmail template.txt -t a:float -t b:float listing.csv

Complex example

The template file can contain python definition, and all the column is accessible by the names cols (default name, can be changed with arg --colsname). See the following template file:

# python preamble begin
import numpy as np
def quartiles(list_values):
    q1, q2, q3 = np.percentile(list_values, (25,50,75))
    return f"{q1:.1f}, {q2:.1f}, {q3:.1f}"
# python preamble end

From: My name <my-mail-address@example.org>
To: {mail}
Subject: Result of the last test

Dear {firstname} {lastname.capitalize()},

Your results of the last test are:

 - Part A: {a:.1f}
 - Part B: {b:.1f}

For all the class, the mean of part A is {np.mean(cols['a']):.1}, and the
quartiles are {quartiles(cols['a'])}.

Therefore you {"pass" if a+b>50 else "fail"} the test.

-- 
signature

Misc

Consider use function fill and indent of textwrap module. For this you need use -b "import textwrap" or add a python preamble in you template file. e.g. in a template to rewrap to 72 chars:

{textwrap.fill(somevalue, width=72)}

Or, for rewrap and indent by > :

{textwrap.indent(textwrap.fill(somevalue, width=70), "> ")}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csvformatmail-0.2.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

csvformatmail-0.2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file csvformatmail-0.2.tar.gz.

File metadata

  • Download URL: csvformatmail-0.2.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1+

File hashes

Hashes for csvformatmail-0.2.tar.gz
Algorithm Hash digest
SHA256 8efdcbb28d8f67e084adce47e0ee1d25b379bcbde4efdc601976c078fb497200
MD5 28c8d7b0f95ea3acd016ec37c86f69af
BLAKE2b-256 f0cc756fadc213bff665755f47491e7790523bda5a5bf591b087f15fcdeffb18

See more details on using hashes here.

File details

Details for the file csvformatmail-0.2-py3-none-any.whl.

File metadata

  • Download URL: csvformatmail-0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1+

File hashes

Hashes for csvformatmail-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9caf9413ad2e37381db2f5bf481a1b4f5e15f24d7419916b30f53501cd956070
MD5 228b4bc29a2ce181e970426d84d67037
BLAKE2b-256 fac9a8419431215e965f49a01dab1e003b119a6840020cf0c21c863bc63750c0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page