Last active
October 18, 2020 07:44
-
-
Save gionn/3e27e090f5f5786d1fba19f2e6b1f247 to your computer and use it in GitHub Desktop.
J.CRS - Centro Regionale Sangue - Script per scaricamento dati automatico
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import time | |
# J.CRS Credentials | |
username = '' | |
password = '' | |
# Export interval | |
date_from = '01-09-2020' | |
date_to = '17-10-2020' | |
# Downloaded file name: {association_id}{location_id}.zip | |
association_id = '' | |
location_id = '' | |
s = requests.Session() | |
payload = {'user': username, 'pwd': password, 'submitPlasmaLogin': 'Procedi'} | |
s.post("https://web2.e.toscana.it/crs/login.jsp", data=payload) | |
print("Logged in") | |
s.get(f'https://web2.e.toscana.it/crs/ass/MakeFile.jsp?A1gg_1={date_from}&A2gg_2={date_to}&f_struttura=&associazione={association_id}&mode=null&SubFiltro=Esegui') | |
print("Archive request") | |
time.sleep(3.0) | |
archive_url = f'https://web2.e.toscana.it/crs/_filesTmp/{association_id}{location_id}.zip' | |
zip = s.get(archive_url, stream=True) | |
while 'Content-Length' in zip.headers: | |
print("Zip not found, looping...") | |
zip = s.get(archive_url, stream=True) | |
time.sleep(1.0) | |
with open("dump.zip", "wb") as f: | |
for chunk in zip.iter_content(chunk_size=1024): | |
f.write(chunk) | |
print("Done!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requests==2.24.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment