Esempio n. 1
0
def to_xml(filename, data):
	target = open(filename, 'w+')
	target.write(utility.get_xml_header() + utility.get_newline())
	target.write("<Goods>" + utility.get_newline())
	for good_record in data:
		target.write( utility.tabs(1) + utility.create_starting_xml_tag("Good")  + utility.get_newline() )
		write_record(target, good_record, 2)
		target.write( utility.tabs(1) + utility.create_closing_xml_tag("Good")  + utility.get_newline() )
	target.write("</Goods>" + utility.get_newline())
	target.close()
	return
Esempio n. 2
0
def to_xml(filename, data):
	target = open(filename, 'w+')
	target.write(utility.get_xml_header() + utility.get_newline())
	target.write("<Countries>" + utility.get_newline())
	for country_record in data:
		target.write( utility.tabs(1) + utility.create_starting_xml_tag("Country") + utility.get_newline())
		write_record(target, country_record, 2)
		target.write( utility.tabs(1) + utility.create_closing_xml_tag("Country") + utility.get_newline() )
	target.write("</Countries>" + utility.get_newline())
	target.close()
	return
Esempio n. 3
0
def to_xml(filename, mlist):
    target = open(filename, 'w+')
    target.write(utility.get_xml_header() + utility.get_newline())
    target.write("<Country_Master_Data>" + utility.get_newline())
    for country_record in mlist:
        target.write(utility.tabs(1) + "<Country>" + utility.get_newline())
        write_front(target, country_record, 2)
        write_rest(target, country_record, 2)
        target.write(utility.tabs(1) + "</Country>" + utility.get_newline())
    target.write("</Country_Master_Data>" + utility.get_newline())
    target.close()
    return
Esempio n. 4
0
def to_xml(filename, mlist):
	target = open(filename, 'w+')
	target.write(utility.get_xml_header()+""+utility.get_newline())
	target.write("<Country_Statistics>"+utility.get_newline())
	for country_record in mlist:
		target.write(utility.tabs(1)+"<Country>"+utility.get_newline())
		write_record(target, country_record)
		write_data(target, country_record, 2)
		target.write(utility.tabs(1)+"</Country>"+utility.get_newline())		
	target.write("</Country_Statistics>"+utility.get_newline())
	target.close()
	return
Esempio n. 5
0
def to_xml(filename, mlist):
    target = open(filename, 'w+')
    target.write(utility.get_xml_header() + "" + utility.get_newline())
    target.write("<Country_Statistics>" + utility.get_newline())
    for country_record in mlist:
        target.write(utility.tabs(1) + "<Country>" + utility.get_newline())
        write_record(target, country_record)
        write_data(target, country_record, 2)
        target.write(utility.tabs(1) + "</Country>" + utility.get_newline())
    target.write("</Country_Statistics>" + utility.get_newline())
    target.close()
    return
Esempio n. 6
0
def to_xml(filename, data):
    target = open(filename, 'w+')
    target.write(utility.get_xml_header() + utility.get_newline())
    target.write("<Countries>" + utility.get_newline())
    for country_record in data:
        target.write(
            utility.tabs(1) + utility.create_starting_xml_tag("Country") +
            utility.get_newline())
        write_record(target, country_record, 2)
        target.write(
            utility.tabs(1) + utility.create_closing_xml_tag("Country") +
            utility.get_newline())
    target.write("</Countries>" + utility.get_newline())
    target.close()
    return
Esempio n. 7
0
def to_xml(filename, data):
    target = open(filename, 'w+')
    target.write(utility.get_xml_header() + utility.get_newline())
    target.write("<Goods>" + utility.get_newline())
    for good_record in data:
        target.write(
            utility.tabs(1) + utility.create_starting_xml_tag("Good") +
            utility.get_newline())
        write_record(target, good_record, 2)
        target.write(
            utility.tabs(1) + utility.create_closing_xml_tag("Good") +
            utility.get_newline())
    target.write("</Goods>" + utility.get_newline())
    target.close()
    return
Esempio n. 8
0
def write_record(target, md):

    target.write(utility.tabs(2) + "<Country_Name>")
    target.write(special_chars.xml_safe(md['Country_Name'], sp_chars))
    target.write("</Country_Name>" + utility.get_newline())

    target.write(utility.tabs(2) + "<Country_ISO2>")
    target.write(str(md['Country_ISO2']))
    target.write("</Country_ISO2>" + utility.get_newline())

    target.write(utility.tabs(2) + "<Country_ISO3>")
    target.write(str(md['Country_ISO3']))
    target.write("</Country_ISO3>" + utility.get_newline())

    target.write(utility.tabs(2) + "<Country_Region>")
    target.write(special_chars.xml_safe(str(md['Country_Region']), sp_chars))
    target.write("</Country_Region>" + utility.get_newline())
    return
Esempio n. 9
0
def write_record(target, md):

	target.write(utility.tabs(2)+"<Country_Name>")
	target.write(special_chars.xml_safe(md['Country_Name'],sp_chars))
	target.write("</Country_Name>"+utility.get_newline())

	target.write(utility.tabs(2)+"<Country_ISO2>")
	target.write(str(md['Country_ISO2']))
	target.write("</Country_ISO2>"+utility.get_newline())

	target.write(utility.tabs(2)+"<Country_ISO3>")
	target.write(str(md['Country_ISO3']))
	target.write("</Country_ISO3>"+utility.get_newline())

	target.write(utility.tabs(2)+"<Country_Region>")
	target.write(special_chars.xml_safe(str(md['Country_Region']),sp_chars))
	target.write("</Country_Region>"+utility.get_newline())
	return
Esempio n. 10
0
def write_rest(target, country_record, count):
    mkeys = country_record.keys()
    for n in range(5, len(mkeys)):
        currentkey = mkeys[n]
        opentext = utility.tabs(count) + "<" + currentkey + ">"
        valuetext = special_chars.xml_safe(str(country_record[currentkey]),
                                           sp_chars)
        closetext = "</" + currentkey + ">" + utility.get_newline()
        target.write(opentext + valuetext + closetext)
    return
Esempio n. 11
0
def write_front(target, country_record, count):
    target.write(
        utility.tabs(count) + "<Country_Name>" +
        special_chars.xml_safe(country_record["Country_Name"], sp_chars) +
        "</Country_Name>" + utility.get_newline())
    target.write(
        utility.tabs(count) + "<Country_ISO2>" +
        country_record["Country_ISO2"] + "</Country_ISO2>" +
        utility.get_newline())
    target.write(
        utility.tabs(count) + "<Country_ISO3>" +
        country_record["Country_ISO3"] + "</Country_ISO3>" +
        utility.get_newline())
    target.write(
        utility.tabs(count) + "<Country_Region>" +
        special_chars.xml_safe(country_record["Country_Region"], sp_chars) +
        "</Country_Region>" + utility.get_newline())
    target.write(
        utility.tabs(count) + "<Assessment>" + country_record["Assessment"] +
        "</Assessment>" + utility.get_newline())
    return
Esempio n. 12
0
def write_record(target, cr, count):
    ckeys = cr.keys()
    for n in range(0, len(cr)):
        kv = cr[ckeys[n]]
        if (type(kv) == list):
            target.write(
                utility.tabs(count) +
                utility.create_starting_xml_tag(ckeys[n]) +
                utility.get_newline())
            count += 1
            for l in kv:
                this_key_group = (ckeys[n])[:(len(ckeys[n]) - 1)]
                if len(kv) > 0:
                    this_key_group = this_key_group.replace("ie", "y")
                    #print this_key_group
                    target.write(
                        utility.tabs(count) +
                        utility.create_starting_xml_tag(this_key_group) +
                        utility.get_newline())
                write_record(target, l, count + 1)
                if len(kv) > 0:
                    target.write(
                        utility.tabs(count) +
                        utility.create_closing_xml_tag(this_key_group) +
                        utility.get_newline())
            target.write(
                utility.tabs(count - 1) +
                utility.create_closing_xml_tag(ckeys[n]) +
                utility.get_newline())
        else:
            keyname = utility.to_str(ckeys[n])
            start = utility.create_starting_xml_tag(keyname)
            val = special_chars.xml_safe(utility.to_str(cr[keyname]), sp_chars)
            end = utility.create_closing_xml_tag(keyname)
            target.write(
                utility.tabs(count) + start + val + end +
                utility.get_newline())
    return
Esempio n. 13
0
def write_record(target, cr, count): 
	ckeys = cr.keys()
	for n in range(0, len(cr)): 
		kv = cr[ckeys[n]]
		if (type(kv) == list):
			target.write( utility.tabs(count) + utility.create_starting_xml_tag(ckeys[n]) + utility.get_newline() )
			count += 1
			for l in kv:
				this_key_group = (ckeys[n])[:(len(ckeys[n])-1)]
				if len(kv) > 0:
					this_key_group = this_key_group.replace("ie", "y")
					#print this_key_group
					target.write( utility.tabs(count) + utility.create_starting_xml_tag(this_key_group) + utility.get_newline())
				write_record(target, l, count+1)
				if len(kv) > 0:
					target.write( utility.tabs(count) + utility.create_closing_xml_tag(this_key_group) + utility.get_newline())
			target.write( utility.tabs(count-1) + utility.create_closing_xml_tag(ckeys[n]) + utility.get_newline() )
		else:
			keyname = utility.to_str(ckeys[n])
			start = utility.create_starting_xml_tag(keyname)
			val = special_chars.xml_safe(utility.to_str(cr[keyname]), sp_chars)
			end = utility.create_closing_xml_tag(keyname)
			target.write( utility.tabs(count) + start + val + end + utility.get_newline() )
	return
Esempio n. 14
0
def write_record(target, cr, count):
    ckeys = cr.keys()
    for n in range(0, len(cr)):
        kv = cr[ckeys[n]]
        if (type(kv) == list):
            target.write(
                utility.tabs(count) +
                utility.create_starting_xml_tag(ckeys[n]) +
                utility.get_newline())
            if (ckeys[n] != "Goods") and (ckeys[n] != "Suggested_Actions"):
                for l in kv:
                    write_record(target, l, count + 1)
            if (ckeys[n] == "Goods"):
                for good in cr[ckeys[n]]:
                    target.write(
                        utility.tabs(count + 1) + "<Good>" +
                        utility.get_newline())
                    target.write(
                        utility.tabs(count + 2) +
                        utility.create_starting_xml_tag("Good_Name"))
                    target.write(good["Good_Name"])
                    target.write(
                        utility.create_closing_xml_tag("Good_Name") +
                        utility.get_newline())
                    target.write(
                        utility.tabs(count + 2) +
                        utility.create_starting_xml_tag("Child_Labor"))
                    target.write(good["Child_Labor"])
                    target.write(
                        utility.create_closing_xml_tag("Child_Labor") +
                        utility.get_newline())
                    target.write(
                        utility.tabs(count + 2) +
                        utility.create_starting_xml_tag("Forced_Labor"))
                    target.write(good["Forced_Labor"])
                    target.write(
                        utility.create_closing_xml_tag("Forced_Labor") +
                        utility.get_newline())
                    target.write(
                        utility.tabs(count + 2) +
                        utility.create_starting_xml_tag("Forced_Child_Labor"))
                    target.write(good["Forced_Child_Labor"])
                    target.write(
                        utility.create_closing_xml_tag("Forced_Child_Labor") +
                        utility.get_newline())
                    target.write(
                        utility.tabs(count + 1) + "</Good>" +
                        utility.get_newline())
            if (ckeys[n] == "Suggested_Actions"):
                sga = cr[ckeys[n]]
                for action in sga:
                    stripped = unicode(utility.unicode_to_str(action['Area']),
                                       'ascii', 'ignore')
                    xmltag = sanitize(utility.unicode_to_str(stripped))
                    target.write(
                        utility.tabs(count + 1) +
                        utility.create_starting_xml_tag(xmltag) +
                        utility.get_newline())
                    for act in action['Actions']:
                        target.write(
                            utility.tabs(count + 2) +
                            utility.create_starting_xml_tag("Action") +
                            utility.get_newline())
                        aname = special_chars.xml_safe(
                            utility.unicode_to_str(act['Name']), sp_chars)
                        ayears = special_chars.xml_safe(
                            utility.unicode_to_str(act['Years']), sp_chars)
                        target.write(
                            utility.tabs(count + 3) +
                            utility.create_starting_xml_tag("Name") + aname +
                            utility.create_closing_xml_tag("Name") +
                            utility.get_newline())
                        target.write(
                            utility.tabs(count + 3) +
                            utility.create_starting_xml_tag("Years") + ayears +
                            utility.create_closing_xml_tag("Years") +
                            utility.get_newline())
                        target.write(
                            utility.tabs(count + 2) +
                            utility.create_closing_xml_tag("Action") +
                            utility.get_newline())
                    target.write(
                        utility.tabs(count + 1) +
                        utility.create_closing_xml_tag(xmltag) +
                        utility.get_newline())
            target.write(
                utility.tabs(count) +
                utility.create_closing_xml_tag(ckeys[n]) +
                utility.get_newline())
        else:
            keyname = utility.to_str(ckeys[n])
            start = utility.create_starting_xml_tag(keyname)
            val = special_chars.xml_safe(utility.to_str(cr[keyname]), sp_chars)
            end = utility.create_closing_xml_tag(keyname)
            target.write(
                utility.tabs(count) + start + val + end +
                utility.get_newline())
    return
Esempio n. 15
0
def write_record(target, cr, count): 
	ckeys = cr.keys()
	for n in range(0, len(cr)): 
		kv = cr[ckeys[n]]
		if (type(kv) == list):
			target.write( utility.tabs(count) + utility.create_starting_xml_tag(ckeys[n]) + utility.get_newline() )
			if (ckeys[n] != "Goods") and (ckeys[n] != "Suggested_Actions"):
				for l in kv:
					write_record(target, l, count+1)
			if (ckeys[n] == "Goods"):
				for good in cr[ckeys[n]]:
					target.write( utility.tabs(count+1) + "<Good>" + utility.get_newline() )
					target.write( utility.tabs(count+2) + utility.create_starting_xml_tag("Good_Name"))
					target.write( good["Good_Name"])
					target.write( utility.create_closing_xml_tag("Good_Name") + utility.get_newline() )
					target.write( utility.tabs(count+2) + utility.create_starting_xml_tag("Child_Labor") )
					target.write( good["Child_Labor"] )
					target.write( utility.create_closing_xml_tag("Child_Labor") + utility.get_newline() )
					target.write( utility.tabs(count+2) + utility.create_starting_xml_tag("Forced_Labor") )
					target.write( good["Forced_Labor"]  )
					target.write( utility.create_closing_xml_tag("Forced_Labor") + utility.get_newline() )
					target.write( utility.tabs(count+2) + utility.create_starting_xml_tag("Forced_Child_Labor")  )
					target.write( good["Forced_Child_Labor"]  )
					target.write( utility.create_closing_xml_tag("Forced_Child_Labor") + utility.get_newline() )
					target.write( utility.tabs(count+1) + "</Good>" + utility.get_newline() )
			if (ckeys[n] == "Suggested_Actions"):
				sga = cr[ckeys[n]]
				for action in sga:
					stripped = unicode(utility.unicode_to_str(action['Area']), 'ascii', 'ignore')
					xmltag = sanitize(utility.unicode_to_str(stripped))
					target.write( utility.tabs(count+1) + utility.create_starting_xml_tag(xmltag) + utility.get_newline() )
					for act in action['Actions']:
						target.write(utility.tabs(count+2) + utility.create_starting_xml_tag("Action") + utility.get_newline() )
						aname = special_chars.xml_safe(utility.unicode_to_str(act['Name']), sp_chars)
						ayears = special_chars.xml_safe(utility.unicode_to_str(act['Years']), sp_chars)
						target.write(utility.tabs(count+3) + utility.create_starting_xml_tag("Name")  
						             + aname + utility.create_closing_xml_tag("Name")
						             + utility.get_newline() )
						target.write(utility.tabs(count+3) + utility.create_starting_xml_tag("Years")  
						             + ayears + utility.create_closing_xml_tag("Years")
						             + utility.get_newline() )
						target.write(utility.tabs(count+2) + utility.create_closing_xml_tag("Action") + utility.get_newline() )
					target.write( utility.tabs(count+1) + utility.create_closing_xml_tag(xmltag) + utility.get_newline() )
			target.write( utility.tabs(count) + utility.create_closing_xml_tag(ckeys[n]) + utility.get_newline() )
		else:
			keyname = utility.to_str(ckeys[n])
			start = utility.create_starting_xml_tag(keyname)
			val = special_chars.xml_safe(utility.to_str(cr[keyname]), sp_chars)
			end = utility.create_closing_xml_tag(keyname)
			target.write( utility.tabs(count) + start + val + end + utility.get_newline() )
	return
Esempio n. 16
0
def write_data(target, md, count):
	target.write(utility.tabs(count)+"<Childrens_Work_Statistics>"+utility.get_newline())
	target.write(utility.tabs(count+1)+"<Age_Range>")
	target.write(md[CWS+'_Age_Range'])
	target.write("</Age_Range>"+utility.get_newline())
	target.write(utility.tabs(count+1)+"<Total_Percentage_of_Working_Children>")
	target.write(str(md[CWS+'_Total_Percentage_of_Working_Children']))
	target.write("</Total_Percentage_of_Working_Children>"+utility.get_newline())
	target.write(utility.tabs(count+1)+"<Total_Working_Population>")
	target.write(str(md[CWS+'_Total_Working_Population']))
	target.write("</Total_Working_Population>"+utility.get_newline())
	target.write(utility.tabs(count+1)+"<Agriculture>")
	target.write(str(md[CWS+'_Agriculture']))
	target.write("</Agriculture>"+utility.get_newline())
	target.write(utility.tabs(count+1)+"<Services>")
	target.write(str(md[CWS+'_Services']))
	target.write("</Services>"+utility.get_newline())
	target.write(utility.tabs(count+1)+"<Industry>")
	target.write(str(md[CWS+'_Industry']))
	target.write("</Industry>"+utility.get_newline())
	target.write(utility.tabs(count)+"</Childrens_Work_Statistics>"+utility.get_newline())
	
	target.write(utility.tabs(count)+"<Education_Statistics_Attendance_Statistics>"+utility.get_newline())
	target.write(utility.tabs(count+1)+"<Year>")
	target.write(md[ESAS+'_Year'])
	target.write("</Year>"+utility.get_newline())
	target.write(utility.tabs(count+1)+"<Age_Range>")
	target.write(md[ESAS+'_Age_Range'])
	target.write("</Age_Range>"+utility.get_newline())
	target.write(utility.tabs(count+1)+"<Percentage>")
	target.write(md[ESAS+'_Percentage'])
	target.write("</Percentage>"+utility.get_newline())
	target.write(utility.tabs(count)+"</Education_Statistics_Attendance_Statistics>"+utility.get_newline())

	target.write(utility.tabs(count)+"<Children_Work_And_Studying>"+utility.get_newline())
	target.write(utility.tabs(count+1)+"<Year>")
	target.write(md[CWAS+'_Year'])
	target.write("</Year>"+utility.get_newline())
	target.write(utility.tabs(count+1)+"<Age_Range>")
	target.write(md[CWAS+'_Age_Range'])
	target.write("</Age_Range>"+utility.get_newline())
	target.write(utility.tabs(count+1)+"<Total>")
	target.write(md[CWAS+'_Total'])
	target.write("</Total>"+utility.get_newline())
	target.write(utility.tabs(count)+"</Children_Work_And_Studying>"+utility.get_newline())

	target.write(utility.tabs(count)+"<Unesco_Primary_Completion_Rate>"+utility.get_newline())
	target.write(utility.tabs(count+1)+"<Year>")
	target.write(md[UPCR+'_Year'])
	target.write("</Year>"+utility.get_newline())
	target.write(utility.tabs(count+1)+"<Rate>")
	target.write(md[UPCR+'_Rate'])
	target.write("</Rate>"+utility.get_newline())
	target.write(utility.tabs(count)+"</Unesco_Primary_Completion_Rate>"+utility.get_newline())
	return
Esempio n. 17
0
def write_data(target, md, count):
    target.write(
        utility.tabs(count) + "<Childrens_Work_Statistics>" +
        utility.get_newline())
    target.write(utility.tabs(count + 1) + "<Age_Range>")
    target.write(md[CWS + '_Age_Range'])
    target.write("</Age_Range>" + utility.get_newline())
    target.write(
        utility.tabs(count + 1) + "<Total_Percentage_of_Working_Children>")
    target.write(str(md[CWS + '_Total_Percentage_of_Working_Children']))
    target.write("</Total_Percentage_of_Working_Children>" +
                 utility.get_newline())
    target.write(utility.tabs(count + 1) + "<Total_Working_Population>")
    target.write(str(md[CWS + '_Total_Working_Population']))
    target.write("</Total_Working_Population>" + utility.get_newline())
    target.write(utility.tabs(count + 1) + "<Agriculture>")
    target.write(str(md[CWS + '_Agriculture']))
    target.write("</Agriculture>" + utility.get_newline())
    target.write(utility.tabs(count + 1) + "<Services>")
    target.write(str(md[CWS + '_Services']))
    target.write("</Services>" + utility.get_newline())
    target.write(utility.tabs(count + 1) + "<Industry>")
    target.write(str(md[CWS + '_Industry']))
    target.write("</Industry>" + utility.get_newline())
    target.write(
        utility.tabs(count) + "</Childrens_Work_Statistics>" +
        utility.get_newline())

    target.write(
        utility.tabs(count) + "<Education_Statistics_Attendance_Statistics>" +
        utility.get_newline())
    target.write(utility.tabs(count + 1) + "<Year>")
    target.write(md[ESAS + '_Year'])
    target.write("</Year>" + utility.get_newline())
    target.write(utility.tabs(count + 1) + "<Age_Range>")
    target.write(md[ESAS + '_Age_Range'])
    target.write("</Age_Range>" + utility.get_newline())
    target.write(utility.tabs(count + 1) + "<Percentage>")
    target.write(md[ESAS + '_Percentage'])
    target.write("</Percentage>" + utility.get_newline())
    target.write(
        utility.tabs(count) + "</Education_Statistics_Attendance_Statistics>" +
        utility.get_newline())

    target.write(
        utility.tabs(count) + "<Children_Work_And_Studying>" +
        utility.get_newline())
    target.write(utility.tabs(count + 1) + "<Year>")
    target.write(md[CWAS + '_Year'])
    target.write("</Year>" + utility.get_newline())
    target.write(utility.tabs(count + 1) + "<Age_Range>")
    target.write(md[CWAS + '_Age_Range'])
    target.write("</Age_Range>" + utility.get_newline())
    target.write(utility.tabs(count + 1) + "<Total>")
    target.write(md[CWAS + '_Total'])
    target.write("</Total>" + utility.get_newline())
    target.write(
        utility.tabs(count) + "</Children_Work_And_Studying>" +
        utility.get_newline())

    target.write(
        utility.tabs(count) + "<Unesco_Primary_Completion_Rate>" +
        utility.get_newline())
    target.write(utility.tabs(count + 1) + "<Year>")
    target.write(md[UPCR + '_Year'])
    target.write("</Year>" + utility.get_newline())
    target.write(utility.tabs(count + 1) + "<Rate>")
    target.write(md[UPCR + '_Rate'])
    target.write("</Rate>" + utility.get_newline())
    target.write(
        utility.tabs(count) + "</Unesco_Primary_Completion_Rate>" +
        utility.get_newline())
    return