Skip to content

Commit 3bc4b41

Browse files
committed
Satisfy linter
1 parent 4d82515 commit 3bc4b41

File tree

4 files changed

+197
-229
lines changed

4 files changed

+197
-229
lines changed

generate-address-list.py

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
FEATURE_TYPE_TEXT = "Digital Currency Address - "
1212
NAMESPACE = {
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
@@ -22,41 +22,42 @@
2222

2323
def 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

100100
def 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

119118
def 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

125124
def 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:

ofac_scraper.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from selenium.webdriver.chrome.service import Service
77
from selenium.webdriver.common.action_chains import ActionChains
88
from selenium.webdriver.common.by import By
9-
from selenium.webdriver.support import expected_conditions as EC
9+
from selenium.webdriver.support import expected_conditions as ec
1010
from selenium.webdriver.support.ui import WebDriverWait
1111

1212

@@ -28,20 +28,20 @@ def open_website(self, url):
2828

2929
def wait_for_element(self, by, value, timeout=30):
3030
return WebDriverWait(self.driver, timeout).until(
31-
EC.presence_of_element_located((by, value))
31+
ec.presence_of_element_located((by, value))
3232
)
3333

3434
def get_element_text(self, by, value):
3535
return self.driver.find_element(by, value).text
3636

3737
def get_sha256_checksum(self):
38-
MAX_RETRIES = 10
39-
RETRY_DELAY = 10 # seconds to wait before retrying
38+
max_retries = 10
39+
retry_delay = 10
4040

41-
for attempt in range(MAX_RETRIES):
41+
for attempt in range(max_retries):
4242
print(
4343
f"Attempting to get SHA-256 checksum (attempt"
44-
f" {attempt + 1}/{MAX_RETRIES})..."
44+
f" {attempt + 1}/{max_retries})..."
4545
)
4646
try:
4747
self.open_website("https://sanctionslist.ofac.treas.gov/Home/SdnList")
@@ -54,8 +54,7 @@ def get_sha256_checksum(self):
5454
# Scroll to (waiting for animation) and Click the 'File
5555
# Signatures' button with the known ID
5656
header_element = self.driver.find_element(
57-
By.ID,
58-
"accordion__heading-:r1:"
57+
By.ID, "accordion__heading-:r1:"
5958
)
6059
ActionChains(self.driver).move_to_element(header_element).perform()
6160
time.sleep(1)
@@ -79,16 +78,16 @@ def get_sha256_checksum(self):
7978
sha256_checksum = checksums_content.split("SHA-256: ")[1].split("\n")[0]
8079
return sha256_checksum
8180

82-
except TimeoutException:
81+
except TimeoutException as e:
8382
print(
84-
f"Timeout occurred on attempt {attempt + 1}/{MAX_RETRIES}. "
85-
f"Retrying in {RETRY_DELAY} seconds..."
83+
f"Timeout occurred on attempt {attempt + 1}/{max_retries}. "
84+
f"Retrying in {retry_delay} seconds..."
8685
)
87-
time.sleep(RETRY_DELAY)
88-
if attempt == MAX_RETRIES - 1:
86+
time.sleep(retry_delay)
87+
if attempt == max_retries - 1:
8988
raise TimeoutException(
9089
"Max retries reached. The website is not responding."
91-
)
90+
) from e
9291

9392
def close(self):
9493
self.driver.quit()

0 commit comments

Comments
 (0)