-
Notifications
You must be signed in to change notification settings - Fork 2
/
CS555_Proj3.py
103 lines (94 loc) · 3.15 KB
/
CS555_Proj3.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: utf-8 -*-
"""Created on Sun Feb 12 01:22:22 2017@author: Kunal"""
def file_len(f):
for i,l in enumerate(f):
pass
return i+1
def indi_list():
return [0 for i in range(7)]
def fam_list():
oplist = [0 for i in range(6)]
oplist[5] = []
return oplist
def getLastName(str):
temp=''
for i in str:
if(i != '/'):
temp += i
return temp
def getNameByID(indi_list, id):
for i in indi_list:
if(i[0] == id):
return i[1]
def parse(file_name):
f = open(file_name,'r')
f_len = file_len(open(file_name))
indi_on = 0
fam_on = 0
list_indi = []
list_fam = []
indi = indi_list()
fam = fam_list()
for line in f:
str = line.split()
if(str != []):
if(str[0] == '0'):
if(indi_on == 1):
list_indi.append(indi)
indi = indi_list()
indi_on = 0
if(fam_on == 1):
list_fam.append(fam)
fam = fam_list()
fam_on = 0
if(str[1] in ['NOTE', 'HEAD', 'TRLR']):
pass
else:
if(str[2] == 'INDI'):
indi_on = 1
indi[0] = (str[1])
if(str[2] == 'FAM'):
fam_on = 1
fam[0] = (str[1])
if(str[0] == '1'):
if(str[1] == 'NAME'):
indi[1] = str[2] + " " + getLastName(str[3])
if(str[1] == 'SEX'):
indi[2] = str[2]
if(str[1] == 'BIRT'):
date_id = 'BIRT'
if(str[1] == 'DEAT'):
date_id = 'DEAT'
if(str[1] == 'MARR'):
date_id = 'MARR'
if(str[1] == 'DIV'):
date_id = 'DIV'
if(str[1] == 'FAMS'):
indi[5] = str[2]
if(str[1] == 'FAMC'):
indi[6] = str[2]
if(str[1] == 'HUSB'):
fam[1] = str[2]
if(str[1] == 'WIFE'):
fam[2] = str[2]
if(str[1] == 'CHIL'):
fam[5].append(str[2])
if(str[0] == '2'):
if(str[1] == 'DATE'):
date = str[4] + " " + str[3] + " " + str[2]
if(date_id == 'BIRT'):
indi[3] = date
if(date_id == 'DEAT'):
indi[4] = date
if(date_id == 'MARR'):
fam[3] = date
if(date_id == 'DIV'):
fam[4] = date
return list_indi, list_fam
list_indi, list_fam = parse('testGEDCOMFile.ged')
list_indi.sort()
list_fam.sort()
for i in list_indi:
print("ID: " + i[0] + "\nName: " + i[1] + "\n")
for i in list_fam:
print("ID: "+i[0]+"\nHusband's Name: "+getNameByID(list_indi,i[1])+"\nWife's Name: "+getNameByID(list_indi,i[2])+"\n")