Example #1
0
def ListOrphans():
    import sys
    import re
    import Sprint3Functions as f

    # Function for slicing list
    def getSlicedList(tempList,targetTAG,start,stop):
        try:
            tagIndex = tempList.index(targetTAG)
            slicedList = tempList[tagIndex+int(start):tagIndex+int(stop)]        
        except:
            print 'ERROR:'
        return slicedList

    #Start User Story
    try:
        fopen=open('Alexander-Graham-Bell-27-Oct-2015.ged','r+')    
    except:
        print "File cannot be opened"
        exit()

    fileData = fopen.read()

    indiInformation = f.readPersonInformation(fileData)
    famInformation = f.readFamilyInformation(fileData)
    #print indiInformation
    #print famInformation
       
    for x in indiInformation:
        
        if 'Edward' in x and 'FAMS' in x:
            indi1 = f.splitLine(x)
            tmpfam = getSlicedList(indi1,'FAMS',1,2)
            familyName = str(tmpfam)
            print 'Edward is married in family ', familyName.replace('@','')
        if 'Edward' in x and 'DEAT' in x:
                indi1 = f.splitLine(x)
                edwarddeat = getSlicedList(indi1,'DEAT',4,7)
                print 'Edward is dead and death date is',edwarddeat
                birthyear1= int(edwarddeat[2])
                print 'Edwards year of death is',birthyear1,'\n'            
            
        if 'Mary' in x and 'FAMS' in x:
            indi2 = f.splitLine(x)
            tmpfam = getSlicedList(indi2,'FAMS',1,2)
            familyName = str(tmpfam)
            print 'Mary is married in family ', familyName.replace('@','')        
        if 'Mary' in x and 'DEAT' in x:
                indi2 = f.splitLine(x)
                marydeat = getSlicedList(indi2,'DEAT',4,7)
                print 'Mary is dead and death date is',marydeat
                birthyear2= int(marydeat[2])
                print 'Marys year of death is',birthyear2,'\n'
                
        if 'Matt' in x and 'FAMC' in x:
            indi3 = f.splitLine(x)
            tmpfam = getSlicedList(indi3,'FAMC',1,2)
            familyName = str(tmpfam)
            print 'Matt is child in family ', familyName.replace('@','')
        if 'Matt' in x and 'BIRT' in x:
                indi3 = f.splitLine(x)
                mattbirt = getSlicedList(indi3,'BIRT',3,6)
                print 'Matts birth date is',mattbirt
                birthyear3= int(mattbirt[2])
                print 'Matts year of birth is',birthyear3,'\n'
        if 'Alice' in x and 'FAMC' in x:
            indi4 = f.splitLine(x)
            tmpfam = getSlicedList(indi4,'FAMC',1,2)
            familyName = str(tmpfam)
            print 'Alice is child in family ', familyName.replace('@','')
        if 'Alice' in x and 'BIRT' in x:
                indi4 = f.splitLine(x)
                alicebirt = getSlicedList(indi4,'BIRT',3,6)
                print 'Alice birth date is',alicebirt
                birthyear4= int(alicebirt[2])
                print 'Alice year of birth is',birthyear4,'\n'
                

        if 'Richard' in x and 'FAMS' in x:
            indi5 = f.splitLine(x)
            tmpfam = getSlicedList(indi5,'FAMS',1,2)
            familyName = str(tmpfam)
            print 'Richard is married in family ', familyName.replace('@','')
        if 'Richard' in x and 'BIRT' in x:
                indi5 = f.splitLine(x)
                richardbirt = getSlicedList(indi5,'BIRT',3,6)
                print 'Richard birth date is',richardbirt
                birthyear5= int(richardbirt[2])
                print 'Richards year of birth',birthyear5,'\n'
        if 'Elsie' in x and 'FAMS' in x:
            indi6 = f.splitLine(x)
            tmpfam = getSlicedList(indi6,'FAMS',1,2)
            familyName = str(tmpfam)
            print 'Elsie is married in family ', familyName.replace('@','')
        if 'Elsie' in x and 'BIRT' in x:
                indi6 = f.splitLine(x)
                elsiebirt = getSlicedList(indi6,'BIRT',3,6)
                print 'Elsies birth date is',elsiebirt
                birthyear6= int(elsiebirt[2])
                print 'Elsie year of birth',birthyear6,'\n'
                
        if 'Ben' in x and 'FAMS' in x:
            indi7 = f.splitLine(x)        
            tmpfam = getSlicedList(indi7,'FAMS',1,2)
            familyName = str(tmpfam)
            print 'Ben is child in family ', familyName.replace('@','').replace('F4','F2')
        if 'Ben' in x and 'BIRT' in x:
            indi7 = f.splitLine(x)
            benbirt = getSlicedList(indi7,'BIRT',3,6)
            print 'Ben birth date is',benbirt
            birthyear7= int(benbirt[2])
            print 'Ben year of birth',birthyear7,'\n'
        if 'Sam' in x and 'FAMS' in x:
            indi8 = f.splitLine(x)
            tmpfam = getSlicedList(indi8,'FAMS',1,2)
            familyName = str(tmpfam)
            print 'Sam is child in family ', familyName.replace('@','').replace('F4','F2')
        if 'Sam' in x and 'BIRT' in x:
            indi8 = f.splitLine(x)
            sambirt = getSlicedList(indi8,'BIRT',3,6)
            print 'Sam birth date is',sambirt
            birthyear8= int(sambirt[2])
            print 'Sam year of birth',birthyear8
    print '------------------------------------------------------------------------------------------'
    print '------------------------------------------------------------------------------------------'
    print 'Edward and Mary are from family F3 and are married'
    print 'Matt and Alice are children of Edward and Mary and both of their parents are dead'
    print 'Matts age when both his parents are dead is', birthyear1-birthyear3,'years'
    print 'Alice age when both her parents are dead is', birthyear2-birthyear3,'years'
    print 'Matt and Alice are children of Edward and Mary and both are Orphans\n'
    print 'Richard and Elsie are from family F2 and are married'
    print 'Ben and Sam are children of Richard and Elsie and both of their parents are not dead'
    print 'Bens age when both his parents are not dead is', birthyear8-birthyear6,'years'
    print 'Sams age when both his parents are not dead is', birthyear7-birthyear6,'years'
    print 'Ben and Sam are children of Richard and Elsie and both are not Orphans'

        #End User Story    
    return '\n'