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

products management

parent 397f179d
......@@ -28,10 +28,13 @@ apiSentinel = SentinelAPI(usr, pwd, URL_Sentinel)
class Command(BaseCommand):
help = "Populates DB with downloaded L1C products."
def add_arguments(self, parser):
## positional arguments
parser.add_argument('file_path', nargs=1, type=str)
# parser.add_argument('file_path', nargs=1, type=str)
parser.add_argument('--file_path', dest='file_path')
parser.add_argument('--products_list', dest='products_list')
def generate_json(self, product_name):
......@@ -50,22 +53,33 @@ class Command(BaseCommand):
def handle(self, *args, **options):
path = options['file_path'][0]
file_list = os.listdir(path)
if options['file_path'] and not options['products_list']:
path = options['file_path']
file_list = os.listdir(path)
elif options['file_path'] and options['products_list']:
path = options['file_path']
file_list = options['products_list']
file_list.sort()
for file in file_list:
file_name = file.replace(".zip", '')
file_name = file.replace(".zip", '')
PRODUCT_EXISTS = Product_l1c.objects.filter(identifier=file_name).exists()
if not PRODUCT_EXISTS:
data_dict = self.generate_json(file_name)
# print json.dumps(data_dict, indent=3, sort_keys=True, default=str)
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']
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']
else:
print "Product " + file_name + "is already in DB."
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