Ejemplo n.º 1
0
def main(user, password, product_list):
    metadata = URI.from_path('metadata.xml')
    service = URI.from_path('scihub.copernicus.eu.xml')
    credentials = BasicCredentials()
    credentials.userid = user
    credentials.password = password
    credentials.protectionSpace = URI.from_octets(SERVICE).get_canonical_root()
    # the full link of odata is https://scihub.copernicus.eu/apihub/odata/v1
    # this is for the authentication
    c = Client(ca_certs=CERTIFICATE)
    c.add_credentials(credentials)
    c.load_service(service_root=service, metadata=metadata)
    with c.feeds['Products'].open() as products:
        for pid in product_list:
            p = products[pid]
            name = p['Name'].value
            size = p['ContentLength'].value
            output("Product: %s [%i]\n" % (name, size))
            with open('%s.zip' % name, 'wb') as f:
                products.read_stream(p.key(), f)
        if not product_list:
            i = 0
            for p in products.itervalues():
                name = p['Name'].value
                type = p['ContentType'].value
                size = p['ContentLength'].value
                output("%s\n" % str(p.get_location()))
                output("    %s %s[%i]\n" % (name, type, size))
                i += 1
                if i > MAX_LIST:
                    break
Ejemplo n.º 2
0
def main(user, password, product_list):
    metadata = URI.from_path('metadata.xml')
    service = URI.from_path('scihub.copernicus.eu.xml')
    credentials = BasicCredentials()
    credentials.userid = user
    credentials.password = password
    credentials.protectionSpace = URI.from_octets(SERVICE).get_canonical_root()
    # the full link of odata is https://scihub.copernicus.eu/apihub/odata/v1
    # this is for the authentication
    c = Client(ca_certs=CERTIFICATE)
    c.add_credentials(credentials)
    c.load_service(service_root=service, metadata=metadata)
    with c.feeds['Products'].open() as products:
        for pid in product_list:
            p = products[pid]
            name = p['Name'].value
            size = p['ContentLength'].value
            output("Product: %s [%i]\n" % (name, size))
            with open('%s.zip' % name, 'wb') as f:
                products.read_stream(p.key(), f)
        if not product_list:
            i = 0
            for p in products.itervalues():
                name = p['Name'].value
                type = p['ContentType'].value
                size = p['ContentLength'].value
                output("%s\n" % str(p.get_location()))
                output("    %s %s[%i]\n" % (name, type, size))
                i += 1
                if i > MAX_LIST:
                    break
Ejemplo n.º 3
0
    def setup(cls, options=None, args=None, **kwargs):
        """Adds OData initialisation

        Loads the :attr:`metadata` document.  Creates the
        :attr:`data_source` according to the configured :attr:`settings`
        (creating the tables only if requested in the command line
        options).  Finally sets the :attr:`container` to the entity
        container for the application.

        If the -s or --sqlout option is given in options then the data
        source's create table script is output to standard output and
        sys.exit(0) is used to terminate the process."""
        super(DemoApp, cls).setup(options, args, **kwargs)
        settings = cls.settings.setdefault('DemoApp', {})
        customer_id = settings.setdefault('customer_id', None)
        url = settings.setdefault('deliveryodata', None)
        if url:
            # overrides customer_id in settings file
            customer_id = None
        if options and options.customer_id:
            # overrides url in settings file
            customer_id = options.customer_id
            url = None
        if options and options.deliveryodata_url:
            # overrides everything
            customer_id = None
            url = options.deliveryodata_url
        if customer_id:
            if customer_id.isdigit():
                if int(customer_id) < 600000:
                    url = US_ONDEMAND % customer_id
                else:
                    url = EU_ONDEMAND % customer_id
            elif customer_id.isalnum():
                url = US_ONDEMAND % customer_id
            else:
                sys.exit("Bad customer id: %s" % customer_id)
        if url:
            cls.deliveryodata = URI.from_octets(url)
            if not cls.deliveryodata.is_absolute():
                # resolve relative to the current working directory
                cls.deliveryodata = cls.deliveryodata.resolve(
                    URI.from_path(os.path.join(os.getcwd(), 'index')))
            elif not url.endswith('/'):
                url = url + '/'
        else:
            sys.exit("One of customer id or Delivery OData URL is required")
        if options and options.cert:
            # grab the certificate from the live server
            cls.ca_path = options.cert
        settings.setdefault('user', customer_id)
        if options and options.user is not None:
            settings['user'] = options.user
        settings.setdefault('password', None)
        if options and options.password is not None:
            settings['password'] = options.password
        if not settings['password']:
            settings['password'] = getpass.getpass()        
Ejemplo n.º 4
0
def main(user, password, product_list):
    metadata = URI.from_path('metadata.xml')
    credentials = BasicCredentials()
    credentials.userid = user
    credentials.password = password
    credentials.protectionSpace = URI.from_octets(SERVICE).get_canonical_root()
    # the full link of odata is https://scihub.esa.int/dhus/odata/v1
    # this is for the authentication
    c = Client(ca_certs=CERTIFICATE)
    c.add_credentials(credentials)
    c.LoadService(SERVICE, metadata=metadata)

    with c.feeds['Products'].OpenCollection() as products:
        for pid in product_list:
            p = products[pid]
            name = p['Name'].value
            size = p['ContentLength'].value
            print name, size
            with open('%s.zip' % name, 'wb') as f:
                products.read_stream(p.key(), f)
Ejemplo n.º 5
0
def main(user, password, product_list):
    metadata = URI.from_path('metadata.xml')
    credentials = BasicCredentials()
    credentials.userid = user
    credentials.password = password
    credentials.protectionSpace = URI.from_octets(SERVICE).get_canonical_root()
    # the full link of odata is https://scihub.esa.int/dhus/odata/v1
    # this is for the authentication
    c = Client(ca_certs=CERTIFICATE)
    c.add_credentials(credentials)
    c.LoadService(SERVICE, metadata=metadata)

    with c.feeds['Products'].OpenCollection() as products:
        for pid in product_list:
            p = products[pid]
            name = p['Name'].value
            size = p['ContentLength'].value
            print name, size
            with open('%s.zip' % name, 'wb') as f:
                products.read_stream(p.key(), f)