-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
41 lines (30 loc) · 1.06 KB
/
main.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
import os, requests
from bs4 import BeautifulSoup
print(f'OS type -> {os.name}')
EXAMPLE_URL = "https://www.python.org/ftp/python/3.11.1/python-3.11.1-embed-amd64.zip"
### Take in the study ID
study_id = input("Enter a study_ID to download from SUPRA: ")
### Go to the SUPRA page and soup it
with open("supra.html") as fp:
soup = BeautifulSoup(fp, "html.parser")
### parse the SUPRA site for the SC# and file name
data = {}
table = soup.find("table")
rows = table.find_all('tr')
for idx, row in enumerate(rows):
cols = row.find_all('td')
cols = [ele.text.strip() for ele in cols]
data[idx] = {"SC#" : cols[0], "filename" : cols[1]}
### List the files that will be downloaded
print('')
print('####################')
print(f'The following files will be downloaded from study {study_id}')
print('####################')
print('')
for key, value in data.items():
print(data[key]["filename"])
### Start downloading
for key, value in data.items():
r = requests.get(EXAMPLE_URL)
with open(value['filename'], 'wb') as file:
file.write(r.content)