-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_holidays_fr.py
executable file
·71 lines (61 loc) · 2.03 KB
/
generate_holidays_fr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import datetime
import sys
from calendra.europe import France
long_ = {
'New year': 'nouvel an',
'Easter Monday': 'lundi de Pâques',
'Labour Day': 'fête du travail',
'Victory in Europe Day': 'victoire 1945',
'Ascension Thursday': 'Ascension',
'Whit Monday': 'Pentecôte',
'Bastille Day': 'fête nationale',
'Assumption of Mary to Heaven': 'Assomption',
'All Saints Day': 'Toussaint',
'Armistice Day': 'armistice 1918',
'Christmas Day': 'Noël',
'Good Friday': 'vendredi saint',
}
short_ = {
'New year': 'nouv. an',
'Easter Monday': 'l. Pâques',
'Labour Day': 'f. travail',
'Victory in Europe Day': 'vict. 1945',
'Ascension Thursday': 'Ascension',
'Whit Monday': 'Pentecôte',
'Bastille Day': 'fête nat.',
'Assumption of Mary to Heaven': 'Assomption',
'All Saints Day': 'Toussaint',
'Armistice Day': 'arm. 1918',
'Christmas Day': 'Noël',
'Good Friday': 'ven. saint',
}
def generate_holidays(start_year, end_year, length):
cal = France()
for year in range(start_year, end_year + 1):
for holiday in cal.holidays(year):
if length == 'long':
print('{},{}'.format(holiday.isoformat(), long_[holiday.name]))
else:
print('{},{}'.format(holiday.isoformat(), short_[holiday.name]))
if __name__ == '__main__':
if len(sys.argv) < 2:
this_year = datetime.datetime.now().year
generate_holidays(this_year, this_year + 1, 'long')
else:
try:
start_year = int(sys.argv[1])
end_year = start_year
try:
end_year = int(sys.argv[2])
except IndexError:
pass
length = 'long'
try:
length = sys.argv[3]
except IndexError:
pass
generate_holidays(start_year, end_year, length)
except ValueError:
print(f'Usage: {sys.argv[0]} start_year [end_year] [{long|short}]')