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
2135ff9c
Commit
2135ff9c
authored
Jul 25, 2018
by
Renán Sosa Guillen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
products management
parent
822e9968
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
0 deletions
+116
-0
populate_products_l1c.py
catalog/management/commands/populate_products_l1c.py
+71
-0
populate_products_l2a.py
catalog/management/commands/populate_products_l2a.py
+45
-0
No files found.
catalog/management/commands/populate_products_l1c.py
0 → 100644
View file @
2135ff9c
# -*- 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'
]
catalog/management/commands/populate_products_l2a.py
0 → 100644
View file @
2135ff9c
# -*- 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
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