Commit c01b6ac5 authored by Renán Sosa Guillen's avatar Renán Sosa Guillen

deleted

parent 0e0e5afb
# -*- coding: utf-8 -*-
"""
Script that saves in DB the downloaded zip products.
"""
from django.core.management.base import BaseCommand, CommandError
from catalog.models import Product
import xml.etree.ElementTree as ET
import os, requests, json
# * listar todos los elementos de la carpeta
# * por cada elemento hacer la peticion con requests
# * leer el xml obtenido y construir el diccionario con los parámetros correspondientes
# https://scihub.copernicus.eu/dhus/odata/v1/Products('3fab650d-4c8c-4a34-beec-dda7fa9788e0')/Attributes
class Command(BaseCommand):
def add_arguments(self, parser):
## positional arguments
parser.add_argument('file_path', nargs=1, type=str)
def generate_json(self, product_name):
usr = "emmhp"
pwd = "geoemm29"
# uri = "https://scihub.copernicus.eu/dhus/odata/v1/Products?$filter=Name eq 'S2A_MSIL1C_20161206T162652_N0204_R040_T15QZD_20161206T163422'"
uri = "https://scihub.copernicus.eu/dhus/odata/v1/Products?$filter=Name eq '" + product_name + "'"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
base_link = root[5][0].text
uuid = root[5][11][0].text
uri = base_link + "/Attributes('Date')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
date_val = root[5][0][4].text
uri = base_link + "/Attributes('Cloud%20cover%20percentage')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
cloud_percent = root[5][0][4].text
uri = base_link + "/Attributes('Sensing%20start')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
sensing_start = root[5][0][4].text
uri = base_link + "/Attributes('Filename')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
file_name = root[5][0][4].text
uri = base_link + "/Attributes('JTS%20footprint')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
footprint = root[5][0][4].text
uri = base_link + "/Attributes('Footprint')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
gml_footprint = root[5][0][4].text
uri = base_link + "/Attributes('Format')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
file_format = root[5][0][4].text
uri = base_link + "/Attributes('Identifier')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
identifier = root[5][0][4].text
uri = base_link + "/Attributes('Ingestion%20Date')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
ingestion_date = root[5][0][4].text
uri = base_link + "/Attributes('Instrument%20name')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
inst_name = root[5][0][4].text
uri = base_link + "/Attributes('Instrument%20abbreviation')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
inst_short_name = root[5][0][4].text
uri = base_link + "/Attributes('Pass%20direction')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
orbit_dir = root[5][0][4].text
uri = base_link + "/Attributes('Orbit%20number%20%28start%29')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
orbit_num = root[5][0][4].text
uri = base_link + "/Attributes('NSSDC%20identifier')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
platform_id = root[5][0][4].text
uri = base_link + "/Attributes('Satellite%20name')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
platform_name = root[5][0][4].text
uri = base_link + "/Attributes('Platform%20serial%20identifier')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
platform_serial_id = root[5][0][4].text
uri = base_link + "/Attributes('Processing%20baseline')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
proc_baseline = root[5][0][4].text
uri = base_link + "/Attributes('Processing%20level')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
proc_level = root[5][0][4].text
uri = base_link + "/Attributes('Product%20type')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
product_type = root[5][0][4].text
uri = base_link + "/Attributes('Relative%20orbit%20%28start%29')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
relative_orbit = root[5][0][4].text
uri = base_link + "/Attributes('Mission%20datatake%20id')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
data_take_id = root[5][0][4].text
uri = base_link + "/Attributes('Instrument%20mode')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
sensor_op_mode = root[5][0][4].text
uri = base_link + "/Attributes('Size')"
r = requests.get(uri, auth=(usr, pwd))
root = ET.fromstring(r.content)
size = root[5][0][4].text
data_dict = {
'beginposition' : date_val,
'cloudcoverpercentage' : cloud_percent,
'datatakesensingstart' : sensing_start,
'endposition' : date_val,
'filename' : file_name,
'footprint' : footprint,
'format' : file_format,
'gmlfootprint' : gml_footprint,
'hv_order_tileid' : '',
'identifier' : identifier,
'ingestiondate' : ingestion_date,
'instrumentname' : inst_name,
'instrumentshortname' : inst_short_name,
'link' : base_link + "/$value",
'link_alternative' : base_link + "/",
'link_icon' : base_link + "/Products('Quicklook')/$value",
'orbitdirection' : orbit_dir,
'orbitnumber' : orbit_num,
'platformidentifier' : platform_id,
'platformname' : platform_name,
'platformserialidentifier' : platform_serial_id,
'processingbaseline' : proc_baseline,
'processinglevel' : proc_level,
'producttype' : product_type,
'relativeorbitnumber' : relative_orbit,
's2datatakeid' : data_take_id,
'sensoroperationalmode' : sensor_op_mode,
'size' : size,
'summary' : "Date: " + date_val + ", Instrument: " + inst_short_name + ", Mode: , Satellite: " + platform_name + ", Size: " + size,
'tileid' : identifier[-21:][:5],
'title' : identifier,
'uuid' : uuid
}
return data_dict
def handle(self, *args, **options):
path = options['file_path'][0]
file_list = os.listdir(path)
file_list.sort()
file_name = file_list[0].replace(".zip", '')
data_dict = self.generate_json(file_name)
# print json.dumps(data_dict, indent=3, sort_keys=True)
product = Product(
uuid = data_dict['uuid'],
identifier = data_dict['identifier'],
file_path = path,
json = json.dumps(data_dict, indent=3, sort_keys=True)
)
product.save()
print "Id: " + data_dict['uuid']
# print "Begin position: " + date_val
# print "Cloud percentage: " + cloud_percent
# print "Data take sensing start: " + sensing_start
# print "End position: " + date_val
# print "File name: " + file_name
# print "Footprint: " + footprint
# print "Format: " + file_format
# print "Gml footprint: " + gml_footprint
# print "Identifier: " + identifier
# print "Ingestion date: " + ingestion_date
# print "Instrument name: " + inst_name
# print "Instrument short name: " + inst_short_name
# print "Link: " + base_link + "/$value"
# print "Link alternative: " + base_link + "/"
# print "Link icon: " + base_link + "/Products('Quicklook')/$value"
# print "Orbit direction: " + orbit_dir
# print "Orbit number: " + orbit_num
# print "Platform id: " + platform_id
# print "Platform name: " + platform_name
# print "Platform serial id: " + platform_serial_id
# print "Processing baseline: " + proc_baseline
# print "Processing level: " + proc_level
# print "Product type: " + product_type
# print "Relative orbit: " + relative_orbit
# print "Sensor op mode: " + sensor_op_mode
# print "Size: " + size
# print "Summary: " + "Date: " + date_val + ", Instrument: " + inst_short_name + ", Mode: , Satellite: " + platform_name + ", Size: " + size
# print "Tile id: " + identifier[-21:][:5]
# print "Title: " + identifier
# print "UUID: " + uuid
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment