Skip to content
Snippets Groups Projects

Download YOPP data from UCAR server

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Matt Noojin
    ucar_source.txt 4.08 MiB
    Content could not be displayed: it is larger than 1.00 MiB. Options to address this: load it anyway or download it .
    ucar_yopp_download.py 1.23 KiB
    import re, requests
    
    UCAR_URL = "https://www2.mmm.ucar.edu/rt/amps/YOPP-SH-WINTER/txtfiles/"
    
    def download_ucar_files():
        filenames = []
    
        with open("ucar_source.txt") as file:
            source = file.read()
            source = source.split("\n")
    
        ## Loop through the HTML source
        for line in source:
            ## Find lines with '.txt' -- these are the links
            if ".txt" in line:
                ## Use regular expressions to extract filename
                filename = re.search('href=".*txt', line).group()
                filename = filename.replace('href="', '')
                filename, _ = filename.split(" ")
                filenames.append(filename)
    
        ## Loop through files
        for ind, filename in enumerate(filenames):
            try:
                ## Assemble file URL + download
                url = UCAR_URL + filename
                response = requests.get(url)
                ## Write file to current working directory
                with open(filename, mode="wb") as file:
                    file.write(response.content)
                    print(f"{filename} saved\n{ind}/{len(filenames)} files downloaded")
            except Exception as e:
                print(f"Could not download {filename}:\n{e}")
                continue
    
    if __name__ == "__main__":
        download_ucar_files()
    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