forked from conniejmiller/SSW555tm092017Fall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.py
68 lines (57 loc) · 2.32 KB
/
display.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
from prettytable import PrettyTable
from operator import itemgetter
from helpers import get_name
from validate import valid_tag
def print_line(level, tag, args):
""" Print the formatted line of level, tag, and arguments """
print("<-- %s|%s|%s|%s" % (level, tag, valid_tag(level, tag), args))
def print_indi(individual):
""" Print individuals """
for row in sorted(individual, key=itemgetter("ID")):
print("%s : %s" % (row["ID"], row["NAME"]))
def print_fam(individual, family):
""" Print families """
for row in sorted(family, key=itemgetter("ID")):
print("%s : %s:%s and %s:%s" %
(row["ID"],
row["HUSB"],
get_name(individual, row["HUSB"]),
row["WIFE"],
get_name(individual, row["WIFE"])))
def print_table(individual, family):
""" Print table of individuals and families """
individuals = PrettyTable(["ID",
"NAME",
"GENDER",
"BIRTHDAY",
"DEATH"])
# One space between column edges and contents (default)
individuals.padding_width = 1
individuals.align["NAME"] = "l" # Left align names
for row in sorted(individual, key=itemgetter("ID")):
individuals.add_row([row["ID"],
row["NAME"],
row["SEX"],
row["BIRT"],
row["DEAT"]])
print(individuals)
families = PrettyTable(["ID",
"MARRIED",
"DIVORCED",
"HUSBAND",
"WIFE",
"CHILDREN"])
# One space between column edges and contents (default)
families.padding_width = 1
families.align["HUSBAND"] = "1"
families.align["WIFE"] = "1"
for row in sorted(family, key=itemgetter("ID")):
families.add_row([row["ID"],
row["MARR"],
row["DIV"],
row["HUSB"] + ":" +
get_name(individual, row["HUSB"]),
row["WIFE"] + ":" +
get_name(individual, row["WIFE"]),
row["CHIL"]])
print(families)