from lxml import etree from lxml.etree import tostring from lxml.objectify import ElementMaker from datetime import datetime, timezone from validate import validate_rdr territories = ['CL', 'CN', 'GA', 'AG', 'PM', 'MS', 'UG', 'FM', 'BJ', 'BT', 'CH', 'IT', 'SG', 'MC', 'MV', 'CY', 'PS', 'GH', 'IL', 'NA', 'KR', 'TF', 'FO', 'GI', 'ME', 'OM', 'MW', 'ML', 'BE', 'TR', 'ST', 'NF', 'LT', 'PL', 'UZ', 'BB', 'RW', 'JM', 'NI', 'SE', 'GS', 'LY', 'PH', 'FR', 'IN', 'IQ', 'BD', 'TZ', 'AX', 'EC', 'EH', 'BV', 'MQ', 'PR', 'BZ', 'CA', 'JE', 'TD', 'CW', 'YE', 'KN', 'PT', 'KY', 'BL', 'MF', 'NE', 'AM', 'NU', 'SO', 'PW', 'BG', 'LU', 'GU', 'NR', 'DO', 'SI', 'CM', 'KM', 'ES', 'LV', 'BY', 'HN', 'ER', 'SS', 'NG', 'AZ', 'KE', 'TH', 'GE', 'DE', 'AS', 'CV', 'KH', 'HK', 'UY', 'IE', 'MN', 'BI', 'TL', 'MK', 'GM', 'SK', 'CK', 'CU', 'HR', 'TW', 'FK', 'SA', 'RS', 'CO', 'AW', 'BF', 'CZ', 'AR', 'DM', 'IO', 'MZ', 'MH', 'RE', 'AF', 'GB', 'CX', 'TJ', 'TG', 'KZ', 'SB', 'VG', 'NC', 'KW', 'YT', 'LK', 'WF', 'BQ', 'BH', 'BO', 'DZ', 'BW', 'GL', 'VU', 'BA', 'CG', 'TK', 'ET', 'SZ', 'SD', 'CF', 'NZ', 'JP', 'TM', 'MU', 'BM', 'VN', 'SV', 'SH', 'IM', 'BS', 'BN', 'GQ', 'MD', 'AU', 'TV', 'MX', 'FI', 'MG', 'GN', 'CI', 'TT', 'ZW', 'IS', 'TN', 'ZA', 'MO', 'VC', 'AT', 'TC', 'MT', 'GG', 'HT', 'VE', 'EE', 'NO', 'AO', 'LI', 'SX', 'AD', 'MM', 'AI', 'GW', 'AQ', 'SR', 'IR', 'NL', 'VI', 'GY', 'SM', 'DK', 'AE', 'DJ', 'SL', 'QA', 'LS', 'ID', 'HM', 'MA', 'SJ', 'HU', 'RO', 'LC', 'PE', 'US', 'GD', 'TO', 'SC', 'KI', 'LB', 'PG', 'PK', 'RU', 'SY', 'JO', 'MY', 'PY', 'AL', 'GR', 'ZM', 'GF', 'SN', 'KG', 'MP', 'BR', 'UM', 'GT', 'PA', 'EG', 'NP', 'PF', 'VA', 'KP', 'GP', 'CC', 'PN', 'MR', 'WS', 'CD', 'FJ', 'LA', 'LR', 'UA', 'CR'] Eroot = ElementMaker(annotate=False, nsmap={ None: 'http://ddex.net/xml/mlc/131', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance', 'xsd': 'http://www.w3.org/2001/XMLSchema', }) root_attribs = { 'LanguageAndScriptCode': 'en', 'BusinessProfileVersionId': 'SCPP_BusinessProfileVersionId_2017.02.xml', etree.QName("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation"): "http://ddex.net/xml/mlc/131 http://service.ddex.net/xml/mlc/131/music-licensing-companies.xsd"} E = ElementMaker(annotate=False, nsmap={None: ""}) root = Eroot('{http://ddex.net/xml/mlc/131}DeclarationOfSoundRecordingRightsClaimMessage', root_attribs, E('MessageHeader', E('MessageThreadId', '2538381'), E('MessageId', '2538381_20190205_141524'), E('MessageSender', E('PartyId', 'PADPIDA2012041004F'), E('PartyName', E('FullName', 'The Orchard Enterprises')), E('TradingName', 'The Orchard Enterprises, LLC')), E('MessageRecipient', E('PartyId', 'PADPIDA2013040801U'), E('PartyName', E('FullName', 'GVL'))), E('MessageCreatedDateTime', datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ'))), E('ResourceList', E('SoundRecording', {'LanguageAndScriptCode': 'en'}, E('SoundRecordingType', 'MusicalWorkSoundRecording'), E('IsArtistRelated', True), E('SoundRecordingId', E('ISRC', 'NOUGY1800030')), E('ResourceReference', 'A1'), E('ReferenceTitle', E('TitleText', 'I See You'), E('SubTitle')), E('IsBonusResource', False), E('LanguageOfPerformance', 'en'), E('Duration', 'PT0H3M26S'), E('SoundRecordingDetailsByTerritory', *( list(map(lambda territory: E.TerritoryCode(territory), territories))) + [E('Title', {'TitleType': 'OriginalTitle'}, E('TitleText', 'I See You'), E('SubTitle'))] ) ) ) ) print(tostring(root, pretty_print=True, xml_declaration=True, encoding='utf-8').decode('utf-8')) validate_rdr(root)