-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathofac_script.py
41 lines (35 loc) · 1.36 KB
/
ofac_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#MADE BY RAFFAELE CRISTODARO
import pandas as pd
import csv
import requests
import json
import xmltodict
from collections import defaultdict
coins = []
myCoins = {}
sdn = defaultdict(list)
filename = 'sdn2.xml'
URL = "https://www.treasury.gov/ofac/downloads/sanctions/1.0/sdn_advanced.xml"
response = requests.get(URL)
with open(filename, 'wb') as file:
file.write(response.content)
xml_data = open(filename, 'r').read() # Read file
d = xmltodict.parse(xml_data)
for i in d['Sanctions']['ReferenceValueSets']['FeatureTypeValues']['FeatureType']:
if 'Digital Currency Address' in i['#text']:
coins.append(i['@ID'])
myCoins[i['@ID']] = i['#text'].replace('Digital Currency Address - ','')
# print(i['@ID'],'-',i['#text'])
for i in d['Sanctions']['DistinctParties']['DistinctParty']:
if 'Feature' in i['Profile'].keys():
for j in i['Profile']['Feature']:
if '@FeatureTypeID' in j:
if type(j) is not str:
if str(j['@FeatureTypeID']) in coins:
# print(j)
# print(j['FeatureVersion']['VersionDetail']['#text'])
sdn[myCoins[j['@FeatureTypeID']]].append(j['FeatureVersion']['VersionDetail']['#text'])
# break
with open('sdn.json', 'w') as fp:
json_data = json.dump(sdn, fp)
fp.close()