-
Notifications
You must be signed in to change notification settings - Fork 3
/
util.py
33 lines (28 loc) · 850 Bytes
/
util.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
"""
Utitility methods
"""
import csv
from datetime import (
datetime
)
def load_choices(path, reversed=False):
""" Load choices from a CSV file.
The choices are expected to be a list of CSV pairs `v,k` where `k` is the
short symbol value of the choice, and `v` is the human-readable value of
choice.
:param path: Path of the CSV file to load.
:param reversed: key and value are reversed.
:optional reversed: True
:return: List of tuples containing the choices.
"""
choices = []
with open(path) as csv_file:
reader = csv.reader(csv_file)
for (symbol, value) in reader:
if reversed:
choices.append((value, symbol))
else:
choices.append((symbol, value))
return choices
def get_current_year():
return datetime.now().year