chg: Structurded data

pull/168/head
chrisr3d 2018-02-26 11:47:35 +01:00
parent 359ac9100e
commit 81a6be17d3
No known key found for this signature in database
GPG Key ID: 6BBED1B63A6D639F
1 changed files with 8 additions and 6 deletions

View File

@ -24,7 +24,7 @@ t_account = {'nodes': ['signatory'],
entity = {'nodes': ['addresses'],
'leaves': ['name', 'commercial_name', 'incorporation_legal_form', 'incorporation_number', 'business', 'phone']}
goAMLobjects = {'report': {'nodes': ['reporting_person', 'location', 'transaction'],
goAMLobjects = {'report': {'nodes': ['reporting_person', 'location'],
'leaves': ['rentity_id', 'submission_code', 'report_code', 'submission_date',
'currency_code_local']},
'reporting_person': {'nodes': ['addresses'],
@ -53,25 +53,27 @@ goAMLobjects = {'report': {'nodes': ['reporting_person', 'location', 'transactio
class GoAmlParser():
def __init__(self):
self.dict = defaultdict(list)
self.dict = {}
def readFile(self, filename):
self.tree = ET.parse(filename).getroot()
def parse_xml(self):
self.itterate(self.tree, 'report')
self.dict = self.itterate(self.tree, 'report')
self.dict['transaction'] = []
for t in self.tree.findall('transaction'):
self.dict['transaction'].append(self.itterate(t, 'transaction'))
def itterate(self, tree, aml_type):
elementDict = {}
for element in tree:
tag = element.tag
print(tag)
mapping = goAMLobjects.get(aml_type)
if tag in mapping.get('nodes'):
self.itterate(element, tag)
elementDict[tag] = self.itterate(element, tag)
elif tag in mapping.get('leaves'):
elementDict[tag] = element.text
self.dict[aml_type].append(elementDict)
return elementDict
def handler(q=False):
if q is False: