Skip to content
Snippets Groups Projects

Downloading and extracting a zip file

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by David Huckebrink

    This snippet downloads and extracts a zip file from the german weather service.

    responses_zip.py 525 B
    import zipfile
    from io import BytesIO
    import pandas as pd
    
    
    dwd_temp_zip = requests.get("https://opendata.dwd.de/climate_environment/CDC/observations_germany/climate/hourly/air_temperature/historical/stundenwerte_TU_00555_20080101_20181101_hist.zip")
    buffer = BytesIO(dwd_temp_zip.content)
    
    with zipfile.ZipFile(buffer) as zf:
        # lists contents of zip archive
        # zf.infolist()
        with zf.open("produkt_tu_stunde_20080101_20181101_00555.txt") as le_file:
            df = pd.read_csv(le_file,sep=";")
    
    df.to_csv("test.csv")
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment