Source code for scripts.pull_data

    # For Python 3.0 and later
    from urllib.request import urlopen
except ImportError:
    # Fall back to Python 2's urllib2
    from urllib2 import urlopen
import os
from datetime import datetime, timedelta
from progressbar import ProgressBar

[docs]class ExampleData(): def __init__(self, url, filenames, path): self.url = url self.filenames = filenames self.path = path
[docs] def download(self): """Function used to download example data from""" if not os.path.exists(self.path): os.makedirs(self.path) pbar = ProgressBar() print("Downloading %s ..." % (self.url.split("/")[-1])) for filename in pbar(self.filenames): if not os.path.exists(os.path.join(self.path, filename)): f = urlopen(self.url + "/" + filename) with open(os.path.join(self.path, filename), 'wb') as temp_file: temp_file.write(
if __name__ == "__main__": ExampleData(url="", filenames=["", "", ""], path="examples/MovingEddies_data").download() ExampleData(url="", filenames=["", ""], path="examples/OFAM_example_data").download() ExampleData(url="", filenames=["", "", ""], path="examples/Peninsula_data").download() dates = [datetime(2002, 1, 1) + timedelta(days=x) for x in range(0, 365)] globfiles = [x.strftime("%Y%m%d") + "" for x in dates] ExampleData(url="", filenames=globfiles, path="examples/GlobCurrent_example_data").download() ExampleData(url="", filenames=["", ""], path="examples/DecayingMovingEddy_data").download()