Commit 2135ff9c authored by Renán Sosa Guillen's avatar Renán Sosa Guillen

products management

parent 822e9968
# -*- coding: utf-8 -*-
"""
Script that saves in DB the downloaded zip products.
Usage:
$ cd GeoInt_SIDT
$ python manage.py populate_products_l1c [path_where_files_are_located]
Example:
$ cd GeoInt_SIDT
$ python manage.py populate_products_l1c /home/geointdev/sidt-env/sidt-zip/L1C/
"""
from django.core.management.base import BaseCommand, CommandError
from sentinelsat.sentinel import SentinelAPI
from catalog.models import Product_l1c
import xml.etree.ElementTree as ET
import os, requests, json
usr = "emmhp"
pwd = "geoemm29"
URL_Sentinel = 'https://scihub.copernicus.eu/dhus'
apiSentinel = SentinelAPI(usr, pwd, URL_Sentinel)
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):
"""
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
data_dict = apiSentinel.get_product_odata(uuid, full=True)
return data_dict
def handle(self, *args, **options):
path = options['file_path'][0]
file_list = os.listdir(path)
file_list.sort()
for file in file_list:
file_name = file.replace(".zip", '')
data_dict = self.generate_json(file_name)
# print json.dumps(data_dict, indent=3, sort_keys=True)
product_l1c = Product_l1c(
uuid = data_dict['id'],
identifier = data_dict['Identifier'],
file_path = path,
json = json.dumps(data_dict, indent=3, sort_keys=True, ensure_ascii=True, default=str)
)
product_l1c.save()
print "Id: " + data_dict['id']
# -*- coding: utf-8 -*-
"""
Script that saves in DB the L2A products.
Usage:
$ cd GeoInt_SIDT
$ python manage.py populate_products_l2a [path_where_files_are_located]
Example:
$ cd GeoInt_SIDT
$ python manage.py populate_products_l2a /home/geointdev/sidt-env/sidt-zip/L2A/
"""
from django.core.management.base import BaseCommand, CommandError
from catalog.models import Product_l1c, Product_l2a
import os
class Command(BaseCommand):
def add_arguments(self, parser):
## positional arguments
parser.add_argument('file_path', nargs=1, type=str)
def handle(self, *args, **options):
path = options['file_path'][0]
file_list = os.listdir(path)
file_list.sort()
for file in file_list:
file_name = file.replace(".zip", '')
prod_l1c = Product_l1c.objects.all().filter(identifier=file_name)[0]
product_l2a = Product_l2a(
prod_l1c = prod_l1c,
identifier = prod_l1c.identifier,
file_path = path
)
product_l2a.save()
print prod_l1c.identifier
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