Examples of using API
Get Sentinel-2 Metadata for a specific area of interest during May 2020
#############################################
# A basic example of using the Umbrella API #
#############################################
import os
import sys
import csv
import json
import stat
import types
import requests
import logging
# set the query
url = 'http://umbrella.beyond-eocenter.eu/api/products/sentinel2?in_bbox=20.8,38.41,23.82,40&sensing_date__gte=2020-05-01&sensing_date__lte=2020-05-31'
# used for pagination
starting = -100
# used for counting the total results harvested
total_results = 0
# dictionary with the collected url per product
products = {}
# loop over pages generated by the query
while True:
# set starting point, increasing every time by 100
try:
starting += 100
# add the pagination
url_pagination = url + '&offset=%d&limit=100&format=json' % starting
session = requests.Session()
session.stream = True
resp = session.get(url_pagination)
# check the response
if resp.status_code == 200:
response = resp.json()
logging.info("Successfull connection. Total results %s",response['count'])
results = response['count']
if results == 0:
sys.exit("No results for this query")
total_results += 100
# loop over the results of the current page
for item in response['results']:
products[item['identifier']] = item['url_download']
# ending conditional
if total_results >= results:
break
else:
sys.exit("Not a successful response from the API")
except Exception as e:
logging.error("Cannot access API. Exception:",e)
sys.exit()
# write results to a csv
csv_columns = ['Identifier','Download Link']
csv_file = "productsToDownload.csv"
try:
with open(csv_file, 'w') as f:
f.write("%s,%s\n" % (csv_columns[0], csv_columns[1]))
for product in sorted(products):
f.write("%s,%s\n" % (product, products[product]))
except IOError:
sys.exit("I/O error")
finally:
f.close()
http://umbrella.beyond-eocenter.eu/api/products/sentinel2?in_bbox=20.8,38.41,23.82,40&sensing_date__gte=2020-05-01&sensing_date__lte=2020-05-31&format=json