コード例 #1
0
ファイル: goods.py プロジェクト: jessamynsmith/DOL-ILAB
def to_xml_by_good(filename, goods_list):

    target = open(filename, 'w+')

    # Write XML Header
    target.write(utility.get_xml_header() + "\n")
    target.write("<Good_List>\n")

    # Sets of attributes
    products = []

    # Group by Good
    for n in range(0, len(goods_list)):
        row = goods_list[n]
        country = special_chars.xml_safe(
            str(row['Country_Name']).strip(), sp_chars)
        good = special_chars.xml_safe(str(row['Good_Name']).strip(), sp_chars)
        good_sector = special_chars.xml_safe(
            str(row['Good_Sector']).strip(), sp_chars)
        if (good not in products):
            target.write("\t<Good>\n" + "\t\t<Good_Name>" + good +
                         "</Good_Name>" + "\n")
            target.write("\t\t<Good_Sector>" + good_sector + "</Good_Sector>" +
                         "\n")
            countryset = get_country_tuples_for_good(goods_list, good)
            target.write("\t\t<Countries>\n")
            for count in range(0, len(countryset)):
                target.write("\t\t\t<Country>\n")
                target.write(
                    "\t\t\t\t" + "<Country_Name>" + special_chars.xml_safe(
                        str(countryset[count]['Country_Name']), sp_chars) +
                    "</Country_Name>\n")
                target.write("\t\t\t\t" + "<Country_ISO2>" +
                             str(countryset[count]['Country_ISO2']) +
                             "</Country_ISO2>\n")
                target.write("\t\t\t\t" + "<Country_ISO3>" +
                             str(countryset[count]['Country_ISO3']) +
                             "</Country_ISO3>\n")
                target.write(
                    "\t\t\t\t" + "<Country_Region>" + special_chars.xml_safe(
                        str(countryset[count]['Country_Region']), sp_chars) +
                    "</Country_Region>\n")
                target.write("\t\t\t\t" + "<Child_Labor>" +
                             str(countryset[count]['Child_Labor']) +
                             "</Child_Labor>\n")
                target.write("\t\t\t\t" + "<Forced_Labor>" +
                             str(countryset[count]['Forced_Labor']) +
                             "</Forced_Labor>\n")
                target.write("\t\t\t\t" + "<Forced_Child_Labor>" +
                             str(countryset[count]['Forced_Child_Labor']) +
                             "</Forced_Child_Labor>\n")
                target.write("\t\t\t</Country>\n")
            target.write("\t\t</Countries>\n")
            target.write("\t</Good>\n")
            products.append(good)
    target.write("</Good_List>\n")
    target.close()
    return
コード例 #2
0
ファイル: goods.py プロジェクト: jessamynsmith/DOL-ILAB
def to_xml_by_country(filename, goods_list):

    target = open(filename, 'w+')

    target.write(utility.get_xml_header() + "\n")
    target.write("<Country_List>\n")

    countries = []

    # Group by Country
    for n in range(0, len(goods_list)):
        row = goods_list[n]
        country = special_chars.xml_safe(
            str(row['Country_Name']).strip(), sp_chars)
        iso2 = str(row['Country_ISO2'])
        iso3 = str(row['Country_ISO3'])
        region = special_chars.xml_safe(str(row['Country_Region']), sp_chars)
        good = str(row['Good_Name']).strip()
        if (country not in countries):
            target.write("\t<Country>\n" + "\t\t<Country_Name>" + country +
                         "</Country_Name>" + "\n")
            target.write("\t\t<Country_ISO2>" + iso2 + "</Country_ISO2>" +
                         "\n")
            target.write("\t\t<Country_ISO3>" + iso3 + "</Country_ISO3>" +
                         "\n")
            target.write("\t\t<Country_Region>" + region +
                         "</Country_Region>" + "\n")
            good_tuples = get_good_tuples_for_country(goods_list, country)
            target.write("\t\t<Goods>\n")
            for c in range(0, len(good_tuples)):
                target.write("\t\t\t<Good>\n")
                target.write("\t\t\t\t\t" + "<Good_Name>" +
                             special_chars.xml_safe(
                                 str(good_tuples[c]['Good_Name']), sp_chars) +
                             "</Good_Name>\n")
                target.write(
                    "\t\t\t\t\t" + "<Good_Sector>" + special_chars.xml_safe(
                        str(good_tuples[c]['Good_Sector']), sp_chars) +
                    "</Good_Sector>\n")
                target.write("\t\t\t\t\t" + "<Child_Labor>" +
                             str(good_tuples[c]['Child_Labor']) +
                             "</Child_Labor>\n")
                target.write("\t\t\t\t\t" + "<Forced_Labor>" +
                             str(good_tuples[c]['Forced_Labor']) +
                             "</Forced_Labor>\n")
                target.write("\t\t\t\t\t" + "<Forced_Child_Labor>" +
                             str(good_tuples[c]['Forced_Child_Labor']) +
                             "</Forced_Child_Labor>\n")
                target.write("\t\t\t</Good>\n")
            target.write("\t\t</Goods>\n")
            target.write("\t</Country>\n")
            countries.append(country)
    target.write("</Country_List>\n")
    target.close()
    return
コード例 #3
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
コード例 #4
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
コード例 #5
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
コード例 #6
0
ファイル: sectors.py プロジェクト: jessamynsmith/DOL-ILAB
def to_xml(filename, data):
	target = open(filename, 'w+')
	target.write(utility.get_xml_header()+"\n")
	target.write("<Goods>\n")
	for good in data:
		target.write("\t<Good>\n")
		target.write("\t\t<Good_Name>"+special_chars.xml_safe(good['Good_Name'],sp_chars)+"</Good_Name>\n")
		target.write("\t\t<Good_Sector>"+special_chars.xml_safe(good['Good_Sector'],sp_chars)+"</Good_Sector>\n")
		target.write("\t</Good>\n")
	target.write("</Goods>\n")
	target.close()
	return
コード例 #7
0
ファイル: stats.py プロジェクト: jessamynsmith/DOL-ILAB
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
コード例 #8
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
コード例 #9
0
ファイル: regions.py プロジェクト: jessamynsmith/DOL-ILAB
def to_xml(filename, data):	
	target = open(filename, 'w+')
	target.write(utility.get_xml_header()+"\n")
	target.write("<Countries>\n")
	for country in data:
		target.write("\t<Country>\n")
		target.write("\t\t<Country_Name>"+special_chars.xml_safe(country['Country_Name'],sp_chars)+"</Country_Name>\n")
		target.write("\t\t<Country_ISO2>"+str(country['Country_ISO2'])+"</Country_ISO2>\n")
		target.write("\t\t<Country_ISO3>"+str(country['Country_ISO3'])+"</Country_ISO3>\n")
		target.write("\t\t<Country_Region>"+special_chars.xml_safe(country['Country_Region'],sp_chars)+"</Country_Region>\n")						
		target.write("\t</Country>\n")
	target.write("</Countries>\n")
	target.close()
	return
コード例 #10
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
コード例 #11
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
コード例 #12
0
ファイル: regions.py プロジェクト: jessamynsmith/DOL-ILAB
def to_xml(filename, data):
    target = open(filename, 'w+')
    target.write(utility.get_xml_header() + "\n")
    target.write("<Countries>\n")
    for country in data:
        target.write("\t<Country>\n")
        target.write(
            "\t\t<Country_Name>" +
            special_chars.xml_safe(country['Country_Name'], sp_chars) +
            "</Country_Name>\n")
        target.write("\t\t<Country_ISO2>" + str(country['Country_ISO2']) +
                     "</Country_ISO2>\n")
        target.write("\t\t<Country_ISO3>" + str(country['Country_ISO3']) +
                     "</Country_ISO3>\n")
        target.write(
            "\t\t<Country_Region>" +
            special_chars.xml_safe(country['Country_Region'], sp_chars) +
            "</Country_Region>\n")
        target.write("\t</Country>\n")
    target.write("</Countries>\n")
    target.close()
    return
コード例 #13
0
ファイル: goods.py プロジェクト: jessamynsmith/DOL-ILAB
def to_xml_by_good(filename, goods_list):
	
	target = open(filename, 'w+')

	# Write XML Header
	target.write(utility.get_xml_header()+"\n")
	target.write("<Good_List>\n")

	# Sets of attributes
	products = []

	# Group by Good
	for n in range(0, len(goods_list)):
		row = goods_list[n]
		country = special_chars.xml_safe(str(row['Country_Name']).strip(),sp_chars)
		good = special_chars.xml_safe(str(row['Good_Name']).strip(),sp_chars)
		good_sector = special_chars.xml_safe(str(row['Good_Sector']).strip(),sp_chars)
		if 	(good not in products):
			target.write("\t<Good>\n"+"\t\t<Good_Name>"+good+"</Good_Name>"+"\n")
			target.write("\t\t<Good_Sector>"+good_sector+"</Good_Sector>"+"\n")			
			countryset = get_country_tuples_for_good(goods_list, good)
			target.write("\t\t<Countries>\n")
			for count in range(0, len(countryset)):
				target.write("\t\t\t<Country>\n")
				target.write("\t\t\t\t"+"<Country_Name>"+special_chars.xml_safe(str(countryset[count]['Country_Name']),sp_chars)+"</Country_Name>\n")
				target.write("\t\t\t\t"+"<Country_ISO2>"+str(countryset[count]['Country_ISO2'])+"</Country_ISO2>\n")
				target.write("\t\t\t\t"+"<Country_ISO3>"+str(countryset[count]['Country_ISO3'])+"</Country_ISO3>\n")
				target.write("\t\t\t\t"+"<Country_Region>"+special_chars.xml_safe(str(countryset[count]['Country_Region']),sp_chars)+"</Country_Region>\n")
				target.write("\t\t\t\t"+"<Child_Labor>"+str(countryset[count]['Child_Labor'])+"</Child_Labor>\n")
				target.write("\t\t\t\t"+"<Forced_Labor>"+str(countryset[count]['Forced_Labor'])+"</Forced_Labor>\n")
				target.write("\t\t\t\t"+"<Forced_Child_Labor>"+str(countryset[count]['Forced_Child_Labor'])+"</Forced_Child_Labor>\n")
				target.write("\t\t\t</Country>\n")
			target.write("\t\t</Countries>\n")
			target.write("\t</Good>\n")
			products.append(good)
	target.write("</Good_List>\n")
	target.close()
	return
コード例 #14
0
ファイル: goods.py プロジェクト: jessamynsmith/DOL-ILAB
def to_xml_by_country(filename, goods_list):
	
	target = open(filename, 'w+')

	target.write(utility.get_xml_header()+"\n")
	target.write("<Country_List>\n")

	countries = []

	# Group by Country
	for n in range(0, len(goods_list)):
		row = goods_list[n]
		country = special_chars.xml_safe(str(row['Country_Name']).strip(), sp_chars)
		iso2 = str(row['Country_ISO2'])
		iso3 = str(row['Country_ISO3'])
		region = special_chars.xml_safe(str(row['Country_Region']), sp_chars)
		good = str(row['Good_Name']).strip()
		if 	(country not in countries):
			target.write("\t<Country>\n"+"\t\t<Country_Name>"+country+"</Country_Name>"+"\n")
			target.write("\t\t<Country_ISO2>"+iso2+"</Country_ISO2>"+"\n")
			target.write("\t\t<Country_ISO3>"+iso3+"</Country_ISO3>"+"\n")
			target.write("\t\t<Country_Region>"+region+"</Country_Region>"+"\n")
			good_tuples = get_good_tuples_for_country(goods_list, country)
			target.write("\t\t<Goods>\n")
			for c in range(0, len(good_tuples)):
				target.write("\t\t\t<Good>\n")
				target.write("\t\t\t\t\t"+"<Good_Name>"+special_chars.xml_safe(str(good_tuples[c]['Good_Name']),sp_chars)+"</Good_Name>\n")
				target.write("\t\t\t\t\t"+"<Good_Sector>"+special_chars.xml_safe(str(good_tuples[c]['Good_Sector']),sp_chars)+"</Good_Sector>\n")				
				target.write("\t\t\t\t\t"+"<Child_Labor>"+str(good_tuples[c]['Child_Labor'])+"</Child_Labor>\n")
				target.write("\t\t\t\t\t"+"<Forced_Labor>"+str(good_tuples[c]['Forced_Labor'])+"</Forced_Labor>\n")
				target.write("\t\t\t\t\t"+"<Forced_Child_Labor>"+str(good_tuples[c]['Forced_Child_Labor'])+"</Forced_Child_Labor>\n")
				target.write("\t\t\t</Good>\n")
			target.write("\t\t</Goods>\n")
			target.write("\t</Country>\n")
			countries.append(country)
	target.write("</Country_List>\n")
	target.close()
	return