@@ -83,28 +83,12 @@ def read_from_one_table(cls, table, mapping):
8383
8484 elif field1 in ["author" , "maintainer" ]:
8585 #the integrity of the format of the person(s) is assured
86- temp = cls .handle_person_in_unknown_format (table [field2 ])
86+ persons = cls .handle_person_in_unknown_format (table [field2 ])
8787
88- #check if it is one person in the right format or none
89- if isinstance (temp , dict ) and len (temp .keys ()) > 0 :
90- #store the persons data and add the @type field
91- temp ["@type" ] = "Person"
92- ret_data [field1 ] = temp
93-
94- #check if how many persons are in the list
95- elif isinstance (temp , list ):
96- if len (temp ) > 1 :
97- #add for every person the @type field
98- for person in temp :
99- person ["@type" ] = "Person"
100-
101- #store the data of the persons
102- ret_data [field1 ] = temp
103-
104- elif len (temp ) == 1 :
105- #store the persons data and add the @type field
106- temp [0 ]["@type" ] = "Person"
107- ret_data [field1 ] = temp [0 ]
88+ #store the (corrected) format of the person(s) data
89+ persons = cls .handle_differnt_possibilities_for_persons (persons )
90+ if not persons is None :
91+ ret_data [field1 ] = persons
10892
10993 else :
11094 #add the data of a field that needs no processing
@@ -117,6 +101,39 @@ def read_from_one_table(cls, table, mapping):
117101 #return the important data of the table
118102 return ret_data
119103
104+ @classmethod
105+ def handle_differnt_possibilities_for_persons (cls , persons ):
106+ #check if it is one person in the right format or none
107+ if isinstance (persons , dict ):
108+ if len (persons .keys ()) > 0 :
109+ #add the @type field
110+ persons ["@type" ] = "Person"
111+
112+ else :
113+ #set to None if there is no persons data to store
114+ persons = None
115+
116+ #check if how many persons are in the list
117+ elif isinstance (persons , list ):
118+ if len (persons ) > 1 :
119+ #add for every person the @type field
120+ for person in persons :
121+ person ["@type" ] = "Person"
122+
123+ elif len (persons ) == 1 :
124+ #add the @type field
125+ persons [0 ]["@type" ] = "Person"
126+
127+ #remove the list as it is only one peron inside
128+ persons = persons [0 ]
129+
130+ else :
131+ #set to None if there is no persons data to store
132+ persons = None
133+
134+ #return the persons in the (corrected) format
135+ return persons
136+
120137 @classmethod
121138 def handle_person_in_unknown_format (cls , persons ):
122139 #check wheter it is one or are more persons
0 commit comments