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 get_MailBoxUsage(userid,password, begin, end):
    """
    Get Office365 MailBoxUsage
    """
    from pyslet.http.auth import BasicCredentials
    from pyslet.rfc2396 import URI
    credentials = BasicCredentials()
    credentials.userid = userid 
    credentials.password = password
    
    if credentials.userid == "":    
        credentials.userid = o365_settings.o365defaultuserid
    if credentials.password == "":    
        credentials.password = o365_settings.o365defaultpassword
    
    credentials.protectionSpace = URI.from_octets("https://reports.office365.com/ecp/reportingwebservice/reporting.svc").get_canonical_root()
# DEBUG
# str(credentials)

    import pyslet.http.client as http
    c = http.Client()
    c.add_credentials(credentials)
    r = http.ClientRequest('https://reports.office365.com/ecp/reportingwebservice/reporting.svc/MailboxUsage')
    c.process_request(r)
# DEBUG
# r.response.status
# print r.response.get_content_type()
# #>>> application/atom+xml; charset=utf-8; type=feed
# print r.response.entity_body.getvalue()
    import xml.etree.ElementTree as ET
    root = ET.fromstring(r.response.entity_body.getvalue())
    ns = {'d': 'http://schemas.microsoft.com/ado/2007/08/dataservices' ,
        'm': 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata' }
    ret = []    
    for entry in root.findall('.//m:properties',ns):
        date = entry.find('d:Date',ns).text
        TotalMailboxCount = entry.find('d:TotalMailboxCount',ns).text
        TotalInactiveMailboxCount  = entry.find('d:TotalInactiveMailboxCount',ns).text
# DEBUG
# print date,TotalMailboxCount,TotalInactiveMailboxCount
        result = { 'Date': date , 'TotalMailboxCount' : TotalMailboxCount, 'TotalInactiveMailboxCount' : TotalInactiveMailboxCount  }
        ret.append(result)
    c.close()
    return ret
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)