-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProject02_Jenish_Kevadia.py
47 lines (39 loc) · 1.43 KB
/
Project02_Jenish_Kevadia.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
"""
@author Jenish Kevadia
Script reads the data from gedcom file and validates whether it's correct or not
"""
supported_tags = ['HEAD', 'TRLR', 'NOTE', 'SEX', 'BIRT', 'DEAT', 'FAMC', 'FAMS', 'MARR', 'HUSB', 'WIFE', 'CHIL', 'DIV']
define_tags = ['INDI', 'FAM']
name_tag = 'NAME'
date_tag = 'DATE'
output = []
with open('test.ged', 'r') as file:
lines = file.readlines()
file.close()
for line in lines:
level, tag, *args = line.split()
valid = None
output.append(f'--> {line}')
if tag not in supported_tags:
if args and args[0] in define_tags:
valid = 'Y'
out_line = f'<-- {level}|{args[0]}|{valid}|{tag}\n'
output.append(out_line)
elif level == '1' and tag == name_tag:
valid = 'Y'
out_line = f'<-- {level}|{tag}|{valid}|'+' '.join(args)+'\n'
output.append(out_line)
elif level == '2' and tag == date_tag:
valid = 'Y'
out_line = f'<-- {level}|{tag}|{valid}|'+' '.join(args)+'\n'
output.append(out_line)
else:
valid = 'N'
out_line = f'<-- {level}|{tag}|{valid}|'+' '.join(args)+'\n'
output.append(out_line)
else:
valid = 'Y'
out_line = f'<-- {level}|{tag}|{valid}|'+' '.join(args)+'\n'
output.append(out_line)
with open('output.txt', 'w') as file:
file.writelines(output)