Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pymoondb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alessandro Frigeri
pymoondb
Commits
dca675b8
Commit
dca675b8
authored
6 years ago
by
Alessandro Frigeri
Browse files
Options
Downloads
Patches
Plain Diff
added timeout exception
parent
51e980d5
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
moondb.py
+27
-13
27 additions, 13 deletions
moondb.py
with
27 additions
and
13 deletions
moondb.py
+
27
−
13
View file @
dca675b8
...
@@ -8,6 +8,9 @@
...
@@ -8,6 +8,9 @@
import
requests
import
requests
import
json
import
json
import
urllib.parse
import
urllib.parse
import
urllib3
,
socket
import
logging
from
collections
import
namedtuple
from
collections
import
namedtuple
class
Mission
:
class
Mission
:
...
@@ -102,14 +105,25 @@ def _check_resp(resp):
...
@@ -102,14 +105,25 @@ def _check_resp(resp):
pass
pass
def
_get_resp
(
path
):
def
_get_resp
(
path
):
resp
=
requests
.
get
(
_url
(
path
))
try
:
resp
=
requests
.
get
(
_url
(
path
),
timeout
=
1
)
except
requests
.
exceptions
.
ReadTimeout
:
# urllib3.exceptions.ReadTimeoutError:
print
(
"
no response in timeout time
"
)
logging
.
warning
(
'
no response in timeout time
'
)
sys
.
exit
(
0
)
except
requests
.
exceptions
.
ConnectTimeout
:
print
(
"
no response in timeout time
"
)
logging
.
warning
(
'
no response in timeout time
'
)
sys
.
exit
(
0
)
_check_resp
(
resp
)
_check_resp
(
resp
)
r
=
resp
.
json
()
r
=
resp
.
json
()
# To be checked with Peng
# To be checked with Peng
count
=
r
[
'
count
'
]
if
'
results
'
in
r
:
if
'
results
'
in
r
:
return
r
[
'
results
'
]
return
count
,
r
[
'
results
'
]
if
'
result
'
in
r
:
if
'
result
'
in
r
:
return
r
[
'
result
'
]
return
count
,
r
[
'
result
'
]
def
get_specimen
(
sc
=
None
,
mn
=
None
,
ln
=
None
,
sty
=
None
,
ste
=
None
):
def
get_specimen
(
sc
=
None
,
mn
=
None
,
ln
=
None
,
sty
=
None
,
ste
=
None
):
'''
'''
...
@@ -123,26 +137,26 @@ def get_specimen(sc=None,mn=None,ln=None,sty=None,ste=None):
...
@@ -123,26 +137,26 @@ def get_specimen(sc=None,mn=None,ln=None,sty=None,ste=None):
sp_list
=
[]
sp_list
=
[]
if
sc
:
if
sc
:
for
s
in
sc
:
for
s
in
sc
:
spec
=
_get_resp
(
'
/specimen/
'
+
s
)
count
,
spec
=
_get_resp
(
'
/specimen/
'
+
s
)
sp_list
.
extend
(
spec
)
sp_list
.
extend
(
spec
)
if
mn
:
if
mn
:
for
n
in
mn
:
for
n
in
mn
:
spec
=
_get_resp
(
'
/specimenlist/mission/
'
+
n
)
count
,
spec
=
_get_resp
(
'
/specimenlist/mission/
'
+
n
)
sp_list
.
extend
(
spec
)
sp_list
.
extend
(
spec
)
if
ln
:
if
ln
:
for
n
in
ln
:
for
n
in
ln
:
spec
=
_get_resp
(
'
/specimenlist/mission/
'
+
n
)
count
,
spec
=
_get_resp
(
'
/specimenlist/mission/
'
+
n
)
sp_list
.
extend
(
spec
)
sp_list
.
extend
(
spec
)
if
sty
:
if
sty
:
for
st
in
sty
:
for
st
in
sty
:
spec
=
_get_resp
(
'
/specimenlist/mission/
'
+
st
)
count
,
spec
=
_get_resp
(
'
/specimenlist/mission/
'
+
st
)
sp_list
.
extend
(
spec
)
sp_list
.
extend
(
spec
)
if
ste
:
if
ste
:
for
st
in
ste
:
for
st
in
ste
:
spec
=
_get_resp
(
'
/specimenlist/mission/
'
+
st
)
count
,
spec
=
_get_resp
(
'
/specimenlist/mission/
'
+
st
)
sp_list
.
extend
(
spec
)
sp_list
.
extend
(
spec
)
from
collections
import
namedtuple
from
collections
import
namedtuple
...
@@ -180,7 +194,7 @@ def get_missions():
...
@@ -180,7 +194,7 @@ def get_missions():
def
get_specimentypes
():
def
get_specimentypes
():
st_list
=
[]
st_list
=
[]
st
=
_get_resp
(
'
/cv/specimentypes
'
)
count
,
st
=
_get_resp
(
'
/cv/specimentypes
'
)
for
s
in
st
:
for
s
in
st
:
stobj
=
SpecimenType
(
s
[
'
name
'
])
stobj
=
SpecimenType
(
s
[
'
name
'
])
st_list
.
append
(
stobj
)
st_list
.
append
(
stobj
)
...
@@ -188,7 +202,7 @@ def get_specimentypes():
...
@@ -188,7 +202,7 @@ def get_specimentypes():
def
get_samplingtechniques
():
def
get_samplingtechniques
():
st_list
=
[]
st_list
=
[]
st
=
_get_resp
(
'
/cv/samplingtechniques
'
)
count
,
st
=
_get_resp
(
'
/cv/samplingtechniques
'
)
for
s
in
st
:
for
s
in
st
:
stobj
=
SamplingTechnique
(
s
[
'
name
'
])
stobj
=
SamplingTechnique
(
s
[
'
name
'
])
st_list
.
append
(
stobj
)
st_list
.
append
(
stobj
)
...
@@ -196,7 +210,7 @@ def get_samplingtechniques():
...
@@ -196,7 +210,7 @@ def get_samplingtechniques():
def
get_analyzedmaterials
():
def
get_analyzedmaterials
():
st_list
=
[]
st_list
=
[]
st
=
_get_resp
(
'
/cv/analyzedmaterials
'
)
count
,
st
=
_get_resp
(
'
/cv/analyzedmaterials
'
)
for
s
in
st
:
for
s
in
st
:
stobj
=
AnalyzedMaterial
(
s
[
'
name
'
])
stobj
=
AnalyzedMaterial
(
s
[
'
name
'
])
st_list
.
append
(
stobj
)
st_list
.
append
(
stobj
)
...
@@ -204,14 +218,14 @@ def get_analyzedmaterials():
...
@@ -204,14 +218,14 @@ def get_analyzedmaterials():
def
get_analytes
():
def
get_analytes
():
analytes
=
[]
analytes
=
[]
an
=
_get_resp
(
'
/cv/analyzedmaterials
'
)
count
,
an
=
_get_resp
(
'
/cv/analyzedmaterials
'
)
for
a
in
an
:
for
a
in
an
:
analytes
.
append
(
Analyte
(
m_item
[
'
name
'
]
))
analytes
.
append
(
Analyte
(
m_item
[
'
name
'
]
))
return
analytes
return
analytes
def
get_analysismethods
():
def
get_analysismethods
():
am_list
=
[]
am_list
=
[]
am
=
_get_resp
(
'
/cv/analysismethods
'
)
count
,
am
=
_get_resp
(
'
/cv/analysismethods
'
)
for
a
in
am
:
for
a
in
am
:
aobj
=
AnalysisMethod
(
s
[
'
name
'
])
aobj
=
AnalysisMethod
(
s
[
'
name
'
])
am_list
.
append
(
aobj
)
am_list
.
append
(
aobj
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment