Skip to content

Instantly share code, notes, and snippets.

@kapadia
Created August 28, 2015 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kapadia/fb4ffa5aff7c92471cb4 to your computer and use it in GitHub Desktop.
Save kapadia/fb4ffa5aff7c92471cb4 to your computer and use it in GitHub Desktop.
import sys
import requests
from requests.auth import HTTPBasicAuth
def go(username, password):
"""
Example of programmatically accessing Sentinel data.
:param username:
Username for ESA's Sentinels Scientific Data Hub
:param password:
Corresponding password
Reference: https://scihub.esa.int/twiki/do/view/SciHubUserGuide/BatchScripting
"""
# Example for a data product with a UUID of 700893d3-3c87-4984-8533-52bc5b956ea8
# corresponding to S1A_EW_GRDM_1SDH_20150828T152957_20150828T153057_007465_00A4AC_C89B
uuid = '700893d3-3c87-4984-8533-52bc5b956ea8'
uri = "https://scihub.esa.int/dhus/odata/v1/Products('%s')/$value" % uuid
r = requests.get(uri, auth=HTTPBasicAuth(username, password), stream=True)
with open('%s.zip' % uuid, 'wb') as dst:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
dst.write(chunk)
dst.flush()
if __name__ == '__main__':
if len(sys.argv) != 3:
exit()
go(*sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment