Coverage for src/ensae_teaching_cs/automation_students/quick_tasks.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2023-01-27 05:44 +0100

1# -*- coding: utf-8 -*- 

2""" 

3@file 

4@brief Some automation helpers to grab mails from students about projects. 

5""" 

6 

7 

8def build_mailing_list(names, domain, format="{first}.{last}@{domain}"): 

9 """ 

10 Infers mails from a list of names. 

11 

12 @param names list of strings 

13 @param domain something like ``ensae.fr``. 

14 @param format mail format 

15 @return list of mails 

16 

17 Examples : 

18 

19 :: 

20 

21 DUPRE Xavier 

22 

23 Everything upper case is the last name, 

24 everything lower case is the first name. 

25 """ 

26 mails = [] 

27 for name in names: 

28 words = name.split() 

29 first = [] 

30 last = [] 

31 for w in words: 

32 if w.upper() == w: 

33 last.append(w) 

34 else: 

35 first.append(w) 

36 first = ".".join(s.lower() for s in first) 

37 last = ".".join(s.lower() for s in last) 

38 mail = format.format(first=first, last=last, domain=domain) 

39 mails.append(mail) 

40 return mails