Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
GeoInt_SIDT
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mario Chirinos Colunga
GeoInt_SIDT
Commits
dad98aad
Commit
dad98aad
authored
Aug 03, 2018
by
Renán Sosa Guillen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
products management
parent
397f179d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
17 deletions
+31
-17
populate_products_l1c.py
catalog/management/commands/populate_products_l1c.py
+31
-17
No files found.
catalog/management/commands/populate_products_l1c.py
View file @
dad98aad
...
...
@@ -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."
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment