Пример #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
Пример #2
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)