Commit b0551220 authored by abuddenberg's avatar abuddenberg
Browse files

Continued adding support for contributors

parent a7388f8e
......@@ -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,'
#
......
......@@ -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__()
......@@ -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)
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment