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
ec00a8c7
Commit
ec00a8c7
authored
Jul 19, 2018
by
Renán Sosa Guillen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes is product management
parent
6766ce06
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
271 additions
and
16 deletions
+271
-16
populate_products.py
catalog/management/commands/populate_products.py
+246
-0
models.py
catalog/models.py
+22
-14
views.py
catalog/views.py
+3
-2
No files found.
catalog/management/commands/populate_products.py
0 → 100644
View file @
ec00a8c7
# -*- 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
%20
cover
%20
percentage')"
r
=
requests
.
get
(
uri
,
auth
=
(
usr
,
pwd
))
root
=
ET
.
fromstring
(
r
.
content
)
cloud_percent
=
root
[
5
][
0
][
4
]
.
text
uri
=
base_link
+
"/Attributes('Sensing
%20
start')"
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
%20
footprint')"
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
%20
Date')"
r
=
requests
.
get
(
uri
,
auth
=
(
usr
,
pwd
))
root
=
ET
.
fromstring
(
r
.
content
)
ingestion_date
=
root
[
5
][
0
][
4
]
.
text
uri
=
base_link
+
"/Attributes('Instrument
%20
name')"
r
=
requests
.
get
(
uri
,
auth
=
(
usr
,
pwd
))
root
=
ET
.
fromstring
(
r
.
content
)
inst_name
=
root
[
5
][
0
][
4
]
.
text
uri
=
base_link
+
"/Attributes('Instrument
%20
abbreviation')"
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
%20
direction')"
r
=
requests
.
get
(
uri
,
auth
=
(
usr
,
pwd
))
root
=
ET
.
fromstring
(
r
.
content
)
orbit_dir
=
root
[
5
][
0
][
4
]
.
text
uri
=
base_link
+
"/Attributes('Orbit
%20
number
%20%28
start
%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
%20
identifier')"
r
=
requests
.
get
(
uri
,
auth
=
(
usr
,
pwd
))
root
=
ET
.
fromstring
(
r
.
content
)
platform_id
=
root
[
5
][
0
][
4
]
.
text
uri
=
base_link
+
"/Attributes('Satellite
%20
name')"
r
=
requests
.
get
(
uri
,
auth
=
(
usr
,
pwd
))
root
=
ET
.
fromstring
(
r
.
content
)
platform_name
=
root
[
5
][
0
][
4
]
.
text
uri
=
base_link
+
"/Attributes('Platform
%20
serial
%20
identifier')"
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
%20
baseline')"
r
=
requests
.
get
(
uri
,
auth
=
(
usr
,
pwd
))
root
=
ET
.
fromstring
(
r
.
content
)
proc_baseline
=
root
[
5
][
0
][
4
]
.
text
uri
=
base_link
+
"/Attributes('Processing
%20
level')"
r
=
requests
.
get
(
uri
,
auth
=
(
usr
,
pwd
))
root
=
ET
.
fromstring
(
r
.
content
)
proc_level
=
root
[
5
][
0
][
4
]
.
text
uri
=
base_link
+
"/Attributes('Product
%20
type')"
r
=
requests
.
get
(
uri
,
auth
=
(
usr
,
pwd
))
root
=
ET
.
fromstring
(
r
.
content
)
product_type
=
root
[
5
][
0
][
4
]
.
text
uri
=
base_link
+
"/Attributes('Relative
%20
orbit
%20%28
start
%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
%20
datatake
%20
id')"
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
%20
mode')"
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
catalog/models.py
View file @
ec00a8c7
...
...
@@ -24,3 +24,11 @@ class Polygon(models.Model):
E_MUN
=
models
.
CharField
(
verbose_name
=
"City Stratum"
,
max_length
=
10
,
default
=
''
)
E_AGEB
=
models
.
CharField
(
verbose_name
=
"AGEB Stratum"
,
max_length
=
10
,
default
=
''
)
wkt_polygon
=
models
.
TextField
(
default
=
''
)
class
Product
(
models
.
Model
):
uuid
=
models
.
CharField
(
max_length
=
50
,
default
=
''
)
identifier
=
models
.
CharField
(
max_length
=
50
,
default
=
''
)
file_path
=
models
.
CharField
(
max_length
=
50
,
default
=
''
)
json
=
models
.
TextField
(
default
=
''
)
catalog/views.py
View file @
ec00a8c7
...
...
@@ -77,8 +77,9 @@ def productList(request):
# se crea una lista de objetos del catalogo
catalog
=
[]
for
p
in
products
:
img_link
=
products
[
p
][
'link_icon'
]
img_link
=
img_link
[:
img_link
.
find
(
"/"
)
+
2
]
+
"emmhp:geoemm29@"
+
img_link
[
img_link
.
find
(
"/"
)
+
2
:]
if
products
.
keys
()
.
index
(
p
)
==
0
:
print
json
.
dumps
(
products
[
p
],
indent
=
3
,
sort_keys
=
True
,
default
=
date_handler
)
# img_link = products[p]['link_icon']
# img_link = img_link[:img_link.find("/")+2] + "emmhp:geoemm29@" + img_link[img_link.find("/")+2:]
catalog
.
append
({
'process'
:
process
,
...
...
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