1010
1111FEATURE_TYPE_TEXT = "Digital Currency Address - "
1212NAMESPACE = {
13- ' sdn' : ' https://sanctionslistservice.ofac.treas.gov/api/PublicationPreview/exports/'
14- ' ADVANCED_XML'
13+ " sdn" : " https://sanctionslistservice.ofac.treas.gov/api/PublicationPreview/exports/"
14+ " ADVANCED_XML"
1515}
1616
1717# List of implemented output formats
2222
2323def parse_arguments ():
2424 parser = argparse .ArgumentParser (
25- description = 'Tool to extract sanctioned digital currency addresses from the '
26- 'OFAC special designated nationals XML file (sdn_advanced.xml)' )
25+ description = "Tool to extract sanctioned digital currency addresses from the "
26+ "OFAC special designated nationals XML file (sdn_advanced.xml)"
27+ )
2728 parser .add_argument (
28- ' assets' ,
29- nargs = '*' ,
29+ " assets" ,
30+ nargs = "*" ,
3031 default = [],
31- help = ' the asset for which the sanctioned addresses should be extracted '
32- ' (default: XBT (Bitcoin))'
32+ help = " the asset for which the sanctioned addresses should be extracted "
33+ " (default: XBT (Bitcoin))" ,
3334 )
3435 parser .add_argument (
35- ' -sdn' ,
36- ' --special-designated-nationals-list' ,
37- dest = ' sdn' ,
38- type = argparse .FileType ('rb' ),
39- help = ' the path to the sdn_advanced.xml file (can be downloaded from '
40- ' https://www.treasury.gov/ofac/downloads/sanctions/1.0/sdn_advanced.xml)' ,
41- default = SDN_ADVANCED_FILE_PATH
36+ " -sdn" ,
37+ " --special-designated-nationals-list" ,
38+ dest = " sdn" ,
39+ type = argparse .FileType ("rb" ),
40+ help = " the path to the sdn_advanced.xml file (can be downloaded from "
41+ " https://www.treasury.gov/ofac/downloads/sanctions/1.0/sdn_advanced.xml)" ,
42+ default = SDN_ADVANCED_FILE_PATH ,
4243 )
4344 parser .add_argument (
44- '-f' ,
45- ' --output-format' ,
46- dest = ' format' ,
47- nargs = '*' ,
45+ "-f" ,
46+ " --output-format" ,
47+ dest = " format" ,
48+ nargs = "*" ,
4849 choices = OUTPUT_FORMATS ,
4950 default = OUTPUT_FORMATS [0 ],
50- help = ' the output file format of the address list (default: TXT)'
51+ help = " the output file format of the address list (default: TXT)" ,
5152 )
5253 parser .add_argument (
53- ' -path' ,
54- ' --output-path' ,
55- dest = ' outpath' ,
54+ " -path" ,
55+ " --output-path" ,
56+ dest = " outpath" ,
5657 type = pathlib .Path ,
5758 default = pathlib .Path ("./" ),
58- help = ' the path where the lists should be written to (default: current working '
59- 'directory ("./")'
59+ help = " the path where the lists should be written to (default: current working "
60+ 'directory ("./")' ,
6061 )
6162 return parser .parse_args ()
6263
@@ -72,12 +73,11 @@ def get_possible_assets(root):
7273 """
7374 assets = []
7475 feature_types = root .findall (
75- 'sdn:ReferenceValueSets/sdn:FeatureTypeValues/sdn:FeatureType' ,
76- NAMESPACE
76+ "sdn:ReferenceValueSets/sdn:FeatureTypeValues/sdn:FeatureType" , NAMESPACE
7777 )
7878 for feature_type in feature_types :
79- if feature_type .text .startswith (' Digital Currency Address - ' ):
80- asset = feature_type .text .replace (' Digital Currency Address - ' , '' )
79+ if feature_type .text .startswith (" Digital Currency Address - " ):
80+ asset = feature_type .text .replace (" Digital Currency Address - " , "" )
8181 assets .append (asset )
8282 return assets
8383
@@ -87,7 +87,7 @@ def get_address_id(root, asset):
8787 feature_type = root .find (
8888 f"sdn:ReferenceValueSets/sdn:FeatureTypeValues"
8989 f"/*[.='{ feature_type_text (asset )} ']" ,
90- NAMESPACE
90+ NAMESPACE ,
9191 )
9292 if feature_type is None :
9393 raise LookupError (
@@ -99,10 +99,9 @@ def get_address_id(root, asset):
9999
100100def get_sanctioned_addresses (root , address_id ):
101101 """returns a list of sanctioned addresses for the given address_id"""
102- addresses = list ()
102+ addresses = []
103103 for feature in root .findall (
104- f"sdn:DistinctParties//*[@FeatureTypeID='{ address_id } ']" ,
105- NAMESPACE
104+ f"sdn:DistinctParties//*[@FeatureTypeID='{ address_id } ']" , NAMESPACE
106105 ):
107106 for version_detail in feature .findall (".//sdn:VersionDetail" , NAMESPACE ):
108107 addresses .append (version_detail .text )
@@ -117,13 +116,13 @@ def write_addresses(addresses, asset, output_formats, outpath):
117116
118117
119118def write_addresses_txt (addresses , asset , outpath ):
120- with open (f"{ outpath } /sanctioned_addresses_{ asset } .txt" , 'w' ) as out :
119+ with open (f"{ outpath } /sanctioned_addresses_{ asset } .txt" , "w" ) as out :
121120 for address in addresses :
122121 out .write (address + "\n " )
123122
124123
125124def write_addresses_json (addresses , asset , outpath ):
126- with open (f"{ outpath } /sanctioned_addresses_{ asset } .json" , 'w' ) as out :
125+ with open (f"{ outpath } /sanctioned_addresses_{ asset } .json" , "w" ) as out :
127126 out .write (json .dumps (addresses , indent = 2 ) + "\n " )
128127
129128
@@ -157,7 +156,7 @@ def main():
157156 tree = ET .parse (args .sdn )
158157 root = tree .getroot ()
159158
160- assets = list ()
159+ assets = []
161160 if isinstance (args .format , str ):
162161 assets .append (args .assets )
163162 else :
@@ -166,7 +165,7 @@ def main():
166165 if len (assets ) == 0 :
167166 assets = get_possible_assets (root )
168167
169- output_formats = list ()
168+ output_formats = []
170169 if isinstance (args .format , str ):
171170 output_formats .append (args .format )
172171 else :
0 commit comments