Skip to content

Instantly share code, notes, and snippets.

@gionn
Last active October 18, 2020 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gionn/3e27e090f5f5786d1fba19f2e6b1f247 to your computer and use it in GitHub Desktop.
Save gionn/3e27e090f5f5786d1fba19f2e6b1f247 to your computer and use it in GitHub Desktop.
J.CRS - Centro Regionale Sangue - Script per scaricamento dati automatico
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!")
requests==2.24.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment