Skip to content

Commit 1379139

Browse files
committed
added in sleep mechanism
1 parent 4e03b40 commit 1379139

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

build/beatAML/GetBeatAML.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88
import subprocess
99
import argparse
10-
10+
import time
1111

1212
def download_from_github(raw_url, save_path):
1313
"""
@@ -159,6 +159,8 @@ def retrieve_drug_info(compound_name):
159159
"""
160160
if pd.isna(compound_name):
161161
return np.nan, np.nan, np.nan, np.nan, np.nan, np.nan
162+
163+
##limit is 1 call per 5 seconds. add in wait call.
162164

163165
url = f"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/name/{compound_name}/property/CanonicalSMILES,IsomericSMILES,InChIKey,MolecularFormula,MolecularWeight/JSON"
164166
response = requests.get(url)
@@ -207,12 +209,14 @@ def update_dataframe_with_pubchem(d_df):
207209
for name in chem_names:
208210
print("Attempting to call pubchem API for chem_name: ", name)
209211
chem_data_dict[name] = retrieve_drug_info(name)
212+
time.sleep(0.2)
210213
failed_chem_names = {k for k, v in chem_data_dict.items() if all(pd.isna(val) for val in v)}
211214
other_names = d_df[d_df['chem_name'].isin(failed_chem_names)]['other_name'].dropna().unique()
212215
other_data_dict = {}
213216
for name in other_names:
214217
print("Attempting to call pubchem API for other_name: ", name)
215218
other_data_dict[name] = retrieve_drug_info(name)
219+
time.sleep(0.2)
216220

217221
# Combine both dictionaries for easy lookup
218222
data_dict = {**chem_data_dict, **other_data_dict}

0 commit comments

Comments
 (0)