def test_api_query_format(): api = SentinelAPI("mock_user", "mock_password") now = datetime.now() query = api.format_query('0 0,1 1,0 1,0 0', end_date=now) last_24h = format_date(now - timedelta(hours=24)) assert query == '(beginPosition:[%s TO %s]) ' % (last_24h, format_date(now)) + \ 'AND (footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))")' query = api.format_query('0 0,1 1,0 1,0 0', end_date=now, producttype='SLC') assert query == '(beginPosition:[%s TO %s]) ' % (last_24h, format_date(now)) + \ 'AND (footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))") ' + \ 'AND (producttype:SLC)'
def test_api_query_format(): api = SentinelAPI("mock_user", "mock_password") now = datetime.now() query = api.format_query('0 0,1 1,0 1,0 0', end_date=now) last_24h = format_date(now - timedelta(hours=24)) assert api.url == 'https://scihub.copernicus.eu/apihub/search?format=json&rows=15000' assert query == '(beginPosition:[%s TO %s]) ' % (last_24h, format_date(now)) + \ 'AND (footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))")' query = api.format_query('0 0,1 1,0 1,0 0', end_date=now, producttype='SLC') assert api.url == 'https://scihub.copernicus.eu/apihub/search?format=json&rows=15000' assert query == '(beginPosition:[%s TO %s]) ' % (last_24h, format_date(now)) + \ 'AND (footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))") ' + \ 'AND (producttype:SLC)'
def test_api_url_format(): api = SentinelAPI( environ.get('SENTINEL_USER'), environ.get('SENTINEL_PASSWORD') ) now = datetime.now() api.format_url('0 0,1 1,0 1,0 0', end_date=now) last_24h = format_date(now - timedelta(hours=24)) assert api.url == 'https://scihub.copernicus.eu/apihub/search?format=json&rows=15000' + \ '&q=(beginPosition:[%s TO %s]) ' % (last_24h, format_date(now)) + \ 'AND (footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))")' api.format_url('0 0,1 1,0 1,0 0', end_date=now, producttype='SLC') assert api.url == 'https://scihub.copernicus.eu/apihub/search?format=json&rows=15000' + \ '&q=(beginPosition:[%s TO %s]) ' % (last_24h, format_date(now)) + \ 'AND (footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))") ' + \ 'AND (producttype:SLC)'
def test_SentinelAPI(): api = SentinelAPI( environ.get('SENTINEL_USER'), environ.get('SENTINEL_PASSWORD') ) api.query('0 0,1 1,0 1,0 0', datetime(2015, 1, 1), datetime(2015, 1, 2)) assert api.url == 'https://scihub.esa.int/dhus/search?format=json&rows=15000' + \ '&q=(ingestionDate:[2015-01-01T00:00:00Z TO 2015-01-02T00:00:00Z]) ' + \ 'AND (footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))")' assert api.content.status_code == 200 now = datetime.now() api.format_url('0 0,1 1,0 1,0 0', end_date=now) last_24h = format_date(now - timedelta(hours=24)) assert api.url == 'https://scihub.esa.int/dhus/search?format=json&rows=15000' + \ '&q=(ingestionDate:[%s TO %s]) ' % (last_24h, format_date(now)) + \ 'AND (footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))")' api.format_url('0 0,1 1,0 1,0 0', end_date=now, producttype='SLC') assert api.url == 'https://scihub.esa.int/dhus/search?format=json&rows=15000' + \ '&q=(ingestionDate:[%s TO %s]) ' % (last_24h, format_date(now)) + \ 'AND (footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))") ' + \ 'AND (producttype:SLC)'
def test_format_date(): assert format_date(datetime(2015, 1, 1)) == '2015-01-01T00:00:00Z' assert format_date(date(2015, 1, 1)) == '2015-01-01T00:00:00Z' assert format_date('2015-01-01T00:00:00Z') == '2015-01-01T00:00:00Z' assert format_date('20150101') == '2015-01-01T00:00:00Z' assert format_date('NOW') == 'NOW'
# GeoJSON FeatureCollection containing footprints and metadata of the scenes fp = api.get_footprints(products) with open('footprints.json', 'w') as outfile: #json.dump({'numbers':n, 'strings':s, 'x':x, 'y':y}, outfile, indent=4) json.dump(fp, outfile, indent=4) with open('product.json', 'w') as outfile: #json.dump({'numbers':n, 'strings':s, 'x':x, 'y':y}, outfile, indent=4) json.dump(products, outfile, indent=4) #print(fp["features"][0]["properties"]["identifier"]) i = 0 #2017-02-07T10:42:00.746Z datetime_old = format_date("20170101") print datetime_old for entry in fp["features"]: datetime = entry["properties"]["date_beginposition"] if (datetime >= datetime_old): datetime_old = datetime product_id = entry["properties"]["product_id"] print "###########" + datetime print entry["properties"]["identifier"] print entry["properties"]["product_id"] print entry["properties"]["date_beginposition"] api.download(product_id)