Skip to content

Commit

Permalink
Start to be more interactive with the SPMT.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael-ritz committed Jun 6, 2016
1 parent 34a73e5 commit 4234689
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
install_requires=[
'setuptools',
# -*- Extra requirements: -*-
'requests',
],
entry_points="""
# -*- Entry points: -*-
Expand Down
4 changes: 3 additions & 1 deletion src/pcp/cregsync/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ def preparedata(values, site, additional_org, email2puid):
fields['service_complete_link'] = scl
fields['identifiers'] = identifiers
# link contacts
contact_url = fields['contact_information']['links']['self']
# first map exceptions
contact_email = fields['contact_information']['email']
contact_data = utils.getDataFromSPMT(contact_url)
contact_email = contact_data['external_contact_information']['email']
email = config.creg2dp_email.get(contact_email,contact_email)
# then look up corresponding UID
contact_uid = email2puid.get(email, None)
Expand Down
15 changes: 15 additions & 0 deletions src/pcp/cregsync/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import logging
import argparse
import requests
from collections import defaultdict

from Products.PlonePAS.utils import cleanId
Expand Down Expand Up @@ -249,3 +250,17 @@ def getSTT(id, context):
"""Look up the title of the term specified by id in the service types vocabulary"""
vocab = context.portal_vocabularies['service_types']
return vocab[id].Title()

# interact with SPMT

def getDataFromSPMT(url):
"""Returns the payload from url or None.
Never fails."""

r = requests.get(url)
d = json.loads(r.content)
try:
return d['data']
except KeyError:
# TODO add logging
return None

0 comments on commit 4234689

Please sign in to comment.