#!/cygdrive/c/python34/python
# Used to get the bird names with their titles and headers from bird_class and
# to get the breakdown of the left menu.  Hopfully, the output will let me see
# if I have done things right in the left menu.
import pdb
import subprocess

# delete beginning and ending spaces and carriage return
def astrip(line):
    line = line.rstrip('\n')
    line = line.lstrip()
    line = line.rstrip()
    return line

        # read in the bird_class databases
        # inventory database
filein = open('bird_class')
for line in filein:
    line = line.rstrip('\n')
        # get birdname, title and header
    if 'title:' in line[0:6]:
        title = line.replace('title:','')
        title = astrip(title)
    elif 'header:' in line[0:7]:
        header = line.replace('header:','')
        header = astrip(header)
    elif 'bird:' in line[0:5]:
        fields = line.split(':')
        name = astrip(fields[1])
            # now put last name first, if possible
        if ' ' in name:
            ind = name.rfind(' ')
            lastname = name[ind+1:]
            firstname = name[:ind]
            bird = lastname + ', ' + firstname
        else:
            bird = name
        strng = "{0:<35} {1:<32} {2:<30}".format(bird, header, title)
        print (strng)
filein.close()
