Exemple #1
0
from akara import logger

from akara import response
from akara.services import simple_service
from amara.thirdparty import json
from zen.akamod import geolookup_service

GEOLOOKUP = geolookup_service()

def lookup_place(p):
    lu = GEOLOOKUP(p)
    if p in lu:
        return lu[p]
    else:
        return ""

@simple_service('POST', 'http://purl.org/la/dp/geocode', 'geocode', 'application/json')
def geocode(body,ctype,prop=None,newprop=None):
    '''   
    Service that accepts a JSON document and "unshreds" the value of the
    field named by the "prop" parameter
    '''   

    try :
        data = json.loads(body)
    except:
        response.code = 500
        response.add_header('content-type','text/plain')
        return "Unable to parse body as JSON"

    if prop not in data:
Exemple #2
0
def post(body, sink):
    headers = {'Content-type': 'application/json'}
    h = httplib2.Http()
    resp, content = h.request(sink, "POST", body=body, headers=headers)
    return resp, content


AUGMENTATIONS = {
    u'location': u'http://purl.org/com/zepheira/augmentation/location',
    u'date': u'http://purl.org/com/zepheira/augmentation/datetime',
    u'luckygoogle': u'http://purl.org/com/zepheira/augmentation/luckygoogle',
    u'shredded_list':
    u'http://purl.org/com/zepheira/augmentation/shredded-list',
}

augmentation.GEOCODER = geolookup_service()
#augmentation.GEOCODER = local_geonames(GEONAMES_PLUS_DBFILE, heuristics=[US_STATE_FIRST], logger=logger)

PROP_TYPE_MARKER = "property:type="
PROP_TYPE_MARKER_LEN = len("property:type=")

SERVICE_ID = 'http://purl.org/com/zepheira/services/augment.freemix.json'


@simple_service('POST', SERVICE_ID, 'augment.freemix.json', 'application/json')
def augment_freemix(body, ctype):
    #See: http://foundry.zepheira.com/issues/133#note-4
    '''
    Render the contents of a file as best as possible in Exhibit JSON
    * Supports Excel, BibTex and JSON for now
def post(body, sink):
    headers = {"Content-type": "application/json"}
    h = httplib2.Http()
    resp, content = h.request(sink, "POST", body=body, headers=headers)
    return resp, content


AUGMENTATIONS = {
    u"location": u"http://purl.org/com/zepheira/augmentation/location",
    u"date": u"http://purl.org/com/zepheira/augmentation/datetime",
    u"luckygoogle": u"http://purl.org/com/zepheira/augmentation/luckygoogle",
    u"shredded_list": u"http://purl.org/com/zepheira/augmentation/shredded-list",
}

augmentation.GEOCODER = geolookup_service()
# augmentation.GEOCODER = local_geonames(GEONAMES_PLUS_DBFILE, heuristics=[US_STATE_FIRST], logger=logger)

PROP_TYPE_MARKER = "property:type="
PROP_TYPE_MARKER_LEN = len("property:type=")

SERVICE_ID = "http://purl.org/com/zepheira/services/augment.freemix.json"


@simple_service("POST", SERVICE_ID, "augment.freemix.json", "application/json")
def augment_freemix(body, ctype):
    # See: http://foundry.zepheira.com/issues/133#note-4
    """
    Render the contents of a file as best as possible in Exhibit JSON
    * Supports Excel, BibTex and JSON for now