Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Andrew Buddenberg
gcis-py-client
Commits
b0551220
Commit
b0551220
authored
Apr 13, 2014
by
abuddenberg
Browse files
Continued adding support for contributors
parent
a7388f8e
Changes
4
Hide whitespace changes
Inline
Side-by-side
bin/sync_figures
View file @
b0551220
...
...
@@ -10,9 +10,9 @@ import pickle
webform
=
WebformClient
(
'http://resources.assessment.globalchange.gov'
,
'mgTD63FAjG'
)
#
gcis_url = 'http://data.gcis-dev-front.joss.ucar.edu'
#
gcis = GcisClient(gcis_url, 'andrew.buddenberg@noaa.gov', 'ad90c05b37d4128ae514bc6caa7a41911d2f1de353443a54')
gcis
=
GcisClient
(
'http://data-stage.globalchange.gov'
,
'andrew.buddenberg@noaa.gov'
,
'b4f1458c3cf28248c982428c46e170019327bd4c533c23dd'
)
gcis_url
=
'http://data.gcis-dev-front.joss.ucar.edu'
gcis
=
GcisClient
(
gcis_url
,
'andrew.buddenberg@noaa.gov'
,
'ad90c05b37d4128ae514bc6caa7a41911d2f1de353443a54'
)
#
gcis = GcisClient('http://data-stage.globalchange.gov', 'andrew.buddenberg@noaa.gov', 'b4f1458c3cf28248c982428c46e170019327bd4c533c23dd')
sync_metadata_tree
=
{
#Reports
...
...
@@ -144,7 +144,7 @@ sync_metadata_tree = {
def
main
():
# print gcis.test_login()
# sync_dataset_metadata(aggregate_webform_datasets())
sync
(
replace
=
False
)
sync
(
replace
=
False
)
# s = 'Vose, R.S., S. Applequist, M.A. Bourassa, S.C. Pryor, R.J. Barthelmie, B. Blanton, P.D. Bromirski, H.E. Brooks, A.T. D,'
#
...
...
gcis_clients/domain.py
View file @
b0551220
...
...
@@ -343,7 +343,16 @@ class Organization(Gcisbase):
self
.
translations
=
{}
self
.
_identifiers
=
{
'NOAA NCDC/CICS-NC'
:
'cooperative-institute-climate-satellites-nc'
,
'NESDIS/NCDC'
:
'noaa-national-climatic-data-center'
,
'U.S. Forest Service'
:
'us-forest-service'
,
}
super
(
Organization
,
self
).
__init__
(
data
,
fields
=
self
.
gcis_fields
,
trans
=
self
.
translations
)
self
.
identifier
=
self
.
_identifiers
[
self
.
name
]
if
self
.
name
in
self
.
_identifiers
else
self
.
name
def
__repr__
(
self
):
return
'{id}: {name}'
.
format
(
id
=
self
.
identifier
,
name
=
self
.
name
)
...
...
@@ -361,4 +370,4 @@ class Contributor(object):
return
'({p}/{o})'
.
format
(
p
=
self
.
person
,
o
=
self
.
organization
)
def
__str__
(
self
):
return
self
.
__repr__
()
\ No newline at end of file
return
self
.
__repr__
()
gcis_clients/gcis_client.py
View file @
b0551220
...
...
@@ -403,10 +403,14 @@ class GcisClient(object):
except
ValueError
:
raise
Exception
(
resp
.
text
)
@
http_resp
def
lookup_organization
(
self
,
name
):
url
=
'{b}/organization/lookup/name'
.
format
(
b
=
self
.
base_url
)
return
requests
.
post
(
url
,
data
=
json
.
dumps
(
name
),
headers
=
self
.
headers
,
verify
=
False
)
url
=
'{b}/autocomplete'
.
format
(
b
=
self
.
base_url
)
resp
=
requests
.
get
(
url
,
params
=
{
'q'
:
name
,
'items'
:
15
,
'type'
:
'organization'
},
headers
=
self
.
headers
,
verify
=
False
)
if
resp
.
status_code
==
200
:
return
[
re
.
match
(
r
'\[organization\] \{(.*)\} (.*)'
,
r
).
groups
()
for
r
in
resp
.
json
()]
else
:
raise
Exception
(
resp
.
text
)
@
http_resp
def
create_organization
(
self
,
org
):
...
...
@@ -421,4 +425,13 @@ class GcisClient(object):
@
http_resp
def
delete_organization
(
self
,
org
):
url
=
'{b}/organization/{org_id}'
.
format
(
b
=
self
.
base_url
,
org_id
=
org
.
identifier
)
return
requests
.
delete
(
url
,
headers
=
self
.
headers
,
verify
=
False
)
\ No newline at end of file
return
requests
.
delete
(
url
,
headers
=
self
.
headers
,
verify
=
False
)
@
http_resp
def
associate_contributor_with_figure
(
self
,
contrib
,
report_id
,
chapter_id
,
figure_id
):
url
=
'{b}/report/{rpt}/chapter/{chp}/figure/contributors/{fig}'
.
format
(
b
=
self
.
base_url
,
rpt
=
report_id
,
chp
=
chapter_id
,
fig
=
figure_id
)
data
=
{}
return
requests
.
post
(
url
,
data
=
json
.
dumps
(
data
),
headers
=
self
.
headers
,
verify
=
False
)
gcis_clients/sync_utils.py
View file @
b0551220
...
...
@@ -34,11 +34,26 @@ def populate_contributors(gcis_client, contributors):
person
=
cont
.
person
org
=
cont
.
organization
matches
=
gcis_client
.
lookup_person
(
person
.
last_name
)
if
len
(
matches
)
==
1
:
person
.
id
=
matches
[
0
][
0
]
elif
len
(
matches
)
==
0
:
print
'No ID found for '
+
person
.
last_name
name_
matches
=
gcis_client
.
lookup_person
(
person
.
first_name
+
' '
+
person
.
last_name
)
if
len
(
name_
matches
)
==
1
:
person
.
id
=
name_
matches
[
0
][
0
]
elif
len
(
name_
matches
)
==
0
:
print
'
\t
'
,
'No ID found for '
+
person
.
last_name
else
:
print
'Ambiguous results for '
+
person
.
last_name
print
'
\t
'
,
matches
\ No newline at end of file
print
'
\t
'
,
'Ambiguous results for '
+
person
.
last_name
print
'
\t\t
'
,
name_matches
if
org
.
identifier
in
(
None
,
''
):
print
org
.
name
# if org.name not in (None, ''):
# org_matches = gcis_client.lookup_organization(org.name)
# if len(org_matches) == 1:
# org.identifier = org_matches[0][0]
# elif len(org_matches) == 0:
# print 'No ID found for ' + org.name
# else:
# print 'Ambiguous results for ' + org.name
# print '\t', org_matches
Write
Preview
Supports
Markdown
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