Skip to content

Instantly share code, notes, and snippets.

@knu2xs
Created May 19, 2014 15:23
Show Gist options
  • Select an option

  • Save knu2xs/fcda3c6e70b307dcebb3 to your computer and use it in GitHub Desktop.

Select an option

Save knu2xs/fcda3c6e70b307dcebb3 to your computer and use it in GitHub Desktop.
Connect to the ftp server and retrieve all NOAA quantitative predictive forecast (QPF) resources for day one.
# import modules
from ftplib import FTP
import os
def get_day_one(directory_target):
"""
Retrieve zero to 30 hour precipitation forecasts
"""
# ftp url
url = 'ftp.hpc.ncep.noaa.gov'
# directory to find files
directory_ftp = '/shapefiles/qpf/day1'
# set of resources
resources = (
'QPF24hr_Day1_latest.tar' # cumulative 24 hour
,'QPF6hr_f00-f06_latest.tar'# 0-6 hour
,'QPF6hr_f06-f12_latest.tar'# 6-12 hour
,'QPF6hr_f12-f18_latest.tar'# 12-18 hour
,'QPF6hr_f18-f24_latest.tar'# 18-24 hour
,'QPF6hr_f24-f30_latest.tar'# 24-30 hour
)
# create FTP object instance referencing the NOAA server
ftp = FTP(url)
# login to the server
ftp.login()
# change the ftp current working directory to the day one directory
ftp.cwd(directory_ftp)
# change the local current working directory to the function parameter
os.chdir(directory_target)
# iterate files
for resource in resources:
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment