bracket_count = 0

state = 'save_default'

count = 0

temp_string = ''

file_contents = file . read ( )

has_run = False

for x in file_contents:

count + = 1

if x is '{' :

bracket_count + = 1

elif x is '}' :

bracket_count - = 1

add_dynasty = 0

#Default state

if state is 'save_default' :

if bracket_count is 0 :

temp_string + = x

else :

temp_string = ''

if 'dynasties' in temp_string:

state = state_change ( 'dynasties_default' , debugging2 )

has_run = False

temp_string = ''

elif 'character' in temp_string:

state = state_change ( 'character_default' , debugging2 )

has_run = False

temp_string = ''

elif 'delayed_event' in temp_string:

'here'

break

#Dynasties state

elif state is 'dynasties_default' :

if bracket_count is 1 and x in digits:

has_run = True

state = state_change ( 'dynasties_id' , debugging2 )

temp_string + = x

elif bracket_count is 0 and has_run:

state = state_change ( 'save_default' , debugging2 )

temp_string = ''

elif state is 'dynasties_id' :

if x in digits:

temp_string + = x

else :

add_dynasty = int ( temp_string )

state = state_change ( 'dynasties_name_1' , debugging2 )

temp_string = ''

elif state is 'dynasties_name_1' :

temp_string + = x

if 'name' in temp_string:

state = state_change ( 'dynasties_name_2' , debugging2 )

temp_string = ''

elif '}' in temp_string:

state = state_change ( 'dynasties_name_4' , debugging2 )

temp_string = ''

elif state is 'dynasties_name_2' :

if x is '"' :

state = state_change ( 'dynasties_name_3' , debugging2 )

elif state is 'dynasties_name_3' :

if x is not '"' :

temp_string + = x

else :

dynasty_list. append ( dynasty ( ) )

dynasty_list [ - 1 ] . id = dynasty_id

dynasty_list [ - 1 ] . name = temp_string

state = state_change ( 'dynasties_default' , debugging2 )

temp_string = ''

add_dynasty = 0

elif state is 'dynasties_name_4' :

state = state_change ( 'dynasties_default' , debugging2 )

temp_string = ''

#Character state

elif state is 'character_default' :

if bracket_count is 1 and x in digits:

has_run = True

state = state_change ( 'character_id' , debugging3 )

temp_string + = x

elif bracket_count is 0 and has_run:

state = state_change ( 'save_default' , debugging3 )

temp_string = ''

elif state is 'character_id' :

if x in digits:

temp_string + = x

else :

character_id = int ( temp_string )

character_list. append ( character ( ) )

character_list [ - 1 ] . id = character_id

state = state_change ( 'character_data' , debugging3 )

has_run2 = False

substate = 'default'

temp_string = ''

elif state is 'character_data' :

if substate is 'default' :

if bracket_count is 2 :

has_run2 = True

temp_string + = x

elif bracket_count is 1 and has_run2:

state = state_change ( 'character_default' , debugging3 )

temp_string = ''

if 'birth_name' in temp_string:

substate = state_change ( 'birth_name' , debugging3 )

getting_name = False

temp_string = ''

if 'female' in temp_string:

character_list [ - 1 ] . gender = 0

temp_string = ''

if 'birth_date' in temp_string:

substate = state_change ( 'birth_date' , debugging3 )

getting_date = 0

temp_string = ''

if 'death_date' in temp_string:

substate = state_change ( 'death_date' , debugging3 )

getting_date = 0

temp_string = ''

if 'father' in temp_string:

substate = state_change ( 'father' , debugging3 )

getting_id = False

temp_string = ''

if 'mother' in temp_string:

substate = state_change ( 'mother' , debugging3 )

getting_id = False

temp_string = ''

if 'spouse' in temp_string:

substate = state_change ( 'spouse' , debugging3 )

getting_id = False

temp_string = ''

if 'dynasty' in temp_string:

substate = state_change ( 'dynasty' , debugging3 )

getting_id = False

temp_string = ''

elif substate is 'birth_name' :

if getting_name is False and x is '"' :

getting_name = True

elif getting_name is True and x is not '"' :

temp_string + = x

elif getting_name is True and x is '"' :

character_list [ - 1 ] . birth_name = temp_string

substate = state_change ( 'default' , debugging3 )

temp_string = ''

elif substate is 'birth_date' :

if getting_date is 0 and x is '"' :

getting_date = 1

elif getting_date is 1 and x is not '.' :

temp_string + = x

elif getting_date is 1 and x is '.' :

character_list [ - 1 ] . birth_year = int ( temp_string )

getting_date = 2

temp_string = ''

elif getting_date is 2 and x is not '.' :

temp_string + = x

elif getting_date is 2 and x is '.' :

character_list [ - 1 ] . birth_month = int ( temp_string )

getting_date = 3

temp_string = ''

elif getting_date is 3 and x is not '"' :

temp_string + = x

elif getting_date is 3 and x is '"' :

character_list [ - 1 ] . birth_day = int ( temp_string )

substate = state_change ( 'default' , debugging3 )

temp_string = ''

elif substate is 'death_date' :

if getting_date is 0 and x is '"' :

getting_date = 1

elif getting_date is 1 and x is not '.' :

temp_string + = x

elif getting_date is 1 and x is '.' :

character_list [ - 1 ] . death_year = int ( temp_string )

getting_date = 2

temp_string = ''

elif getting_date is 2 and x is not '.' :

temp_string + = x

elif getting_date is 2 and x is '.' :

character_list [ - 1 ] . death_month = int ( temp_string )

getting_date = 3

temp_string = ''

elif getting_date is 3 and x is not '"' :

temp_string + = x

elif getting_date is 3 and x is '"' :

character_list [ - 1 ] . death_day = int ( temp_string )

substate = state_change ( 'default' , debugging3 )

temp_string = ''

elif substate is 'father' :

if x in digits:

temp_string + = x

getting_id = True

elif getting_id is True :

character_list [ - 1 ] . father = int ( temp_string )

substate = state_change ( 'default' , debugging3 )

temp_string = ''

elif substate is 'mother' :

if x in digits:

temp_string + = x

getting_id = True

elif getting_id is False :

if x is ' ' or x is '=' :

pass

else :

substate = state_change ( 'default' , debugging3 )

temp_string = ''

elif getting_id is True :

character_list [ - 1 ] . mother = int ( temp_string )

substate = state_change ( 'default' , debugging3 )

temp_string = ''

elif substate is 'spouse' :

if x in digits:

temp_string + = x

getting_id = True

elif getting_id is True :

character_list [ - 1 ] . spouse . append ( int ( temp_string ) )

substate = state_change ( 'default' , debugging3 )

temp_string = ''

elif substate is 'dynasty' :

if x in digits:

temp_string + = x

getting_id = True

elif getting_id is True :

character_list [ - 1 ] . dynasty_id = int ( temp_string )

substate = state_change ( 'default' , debugging3 )

temp_string = ''

elif bracket_count is 1 :