Esempio n. 1
0
def _getVenueCrosswalk(yelpID):
    yelpURL = "https://yelp.com/biz/%s" % yelpID
    obj = factualClient.crosswalk().filters({"url": yelpURL}).data()

    mapping = {
      "id": yelpID,
      "version": CROSSWALK_CACHE_VERSION,
      "yelp": {
        "url": yelpURL
      }
    }

    if len(obj) == 0:
        return mapping

    factualID = obj[0]["factual_id"]
    mapping["factualID"] = factualID

    idList = factualClient.crosswalk().filters({"factual_id": factualID}).data()

    for idObj in idList:
        namespace = idObj["namespace"]
        del idObj["factual_id"]
        del idObj["namespace"]
        mapping[namespace] = idObj
    
    return mapping
Esempio n. 2
0
def getVenueIdentifiers(yelpID):
    yelpURL = "https://yelp.com/biz/%s" % yelpID
    mapping = {
      "id": yelpID,
      "version": CROSSWALK_CACHE_VERSION,
      "yelp": {
        "url": yelpURL
      }
    }
    try:
        obj = factualClient.crosswalk().filters({"url": yelpURL}).data()

        if len(obj) == 0:
            return mapping, True

        factualID = obj[0]["factual_id"]
        mapping["factualID"] = factualID
        mapping["factual"] = { "id": factualID }

        idList = factualClient.crosswalk().filters({"factual_id": factualID}).data()

        for idObj in idList:
            namespace = idObj["namespace"]
            del idObj["factual_id"]
            del idObj["namespace"]
            mapping[namespace] = idObj
        return mapping, True
    except APIException:
        log.error("Factual API failed again")
    except Exception:
        log.exception("Factual problem " + yelpID)
    return mapping, False
Esempio n. 3
0
def fetchCrosswalk(factualIDs):
    namespaces = ["yelp", "tripadvisor", "wikipedia", "instagram_places"]
    oneOfFilter = [{ "factual_id": {"$eq": f}} for f in factualIDs]
    idFilter = { "$or": oneOfFilter }
    oneOfFilter = [ { "namespace": {"$eq": ns }} for ns in namespaces]
    namespaceFilter = { "$or": oneOfFilter }
    totalFilter = { "$and": [idFilter, namespaceFilter]}
    return factualClient.crosswalk().filters(totalFilter).data()
Esempio n. 4
0
def findFactualIDs(yelpBusinesses):
    totalFilter = {
        "$or": [{
            "url": {
                "$eq": "https://yelp.com/biz/%s" % biz.id
            }
        } for biz in yelpBusinesses]
    }
    crosswalkObjects = factualClient.crosswalk().filters(totalFilter).data()
    return [biz["factual_id"] for biz in crosswalkObjects]
Esempio n. 5
0
def recordAPIStatus(apiName):
    req = True
    try:
        if apiName == "tripadvisor":
            TA_TEST_ID= "8364980"
            params = { "key": tripadvisorkey }
            r = requests.get(TRIP_ADVISOR_API.format(TA_TEST_ID), params)
            if r.status_code == 429:
                e_code = r.json().get("code")
                req = False
        elif apiName == "tripadvisor-mapper":
            TA_TEST_LOC = "37.774125,-122.422099"
            params = {"key": tripadvisorkey + "-mapper",
                      "q": "kittea" }
            r = requests.get(TRIP_ADVISOR_LOC_MAPPER_API.format(TA_TEST_LOC), params)
            if r.status_code == 429:
                e_code = r.json().get("code")
                req = False
        elif apiName == "factual":
            try:
                cw = factualClient.crosswalk()
                r = cw.filters({"factual_id": "1b5a13e0-d022-4a66-b7cd-9f48801f1196"
}).data()
            except api.APIException as e:
                if e.get_status_code() == 403:
                    # Assume this means API limit has been reached b/c we don't want
                    # to string-check the message (the only place where the specific
                    # error type is listed)
                    req = False
        elif apiName == "yelp":
            try:
                # Check an existing location
                yelpClient.get_business("kittea-cat-cafe-san-francisco-4")
            except errors.ExceededReqs:
                req = False
        elif apiName == "yelp3":
            try:
                yelp3Client.request("/businesses/{0}".format("kittea-cat-cafe-san-francisco-4"))
            except HTTPError as e:
                if e.code == 429:
                    req = False

        else:
            raise ValueError("Unknown API name; see app/util.py for API values")
    except Exception as e:
        log.exception("Unknown error while checking for cap limits: %s" % e)

    # Timestamped response
    response = "{} {} {}".format(req, time.strftime("%a %x %X", time.localtime()), time.tzname[0])

    # Status updated at:
    # https://console.firebase.google.com/project/prox-server-cf63e/database/data/api_availability
    db().child(apiAvailabilityTable).update({apiName: response})
    return req
Esempio n. 6
0
def getVenueIdentifiers(yelpID):
    yelpURL = "https://yelp.com/biz/%s" % yelpID
    mapping = {
        "id": yelpID,
        "version": CROSSWALK_CACHE_VERSION,
        "yelp": {
            "url": yelpURL
        }
    }
    try:
        if deployment == "production/":
            crosswalk = factualClient.table("crosswalk-us")
        else:
            crosswalk = factualClient.crosswalk()

        obj = crosswalk.filters({"url": yelpURL}).data()

        if len(obj) == 0:
            log.debug("Crosswalk empty for Yelp -> Factual " + yelpID)
            return mapping, True

        factualID = obj[0]["factual_id"]
        mapping["factualID"] = factualID
        mapping["factual"] = {"id": factualID}

        idList = crosswalk.filters({"factual_id": factualID}).data()

        if len(idList) == 0:
            log.warn("Crosswalk empty for Factual -> * " + yelpID + " " +
                     factualID)
        for idObj in idList:
            namespace = idObj["namespace"]
            del idObj["factual_id"]
            del idObj["namespace"]
            mapping[namespace] = idObj
        return mapping, True
    except APIException:
        log.error("Factual API failed again")
    except Exception:
        log.exception("Factual problem " + yelpID)
    return mapping, False
Esempio n. 7
0
def recordAPIStatus(apiName):
    req = True
    try:
        if (apiName == "tripadvisor"):
            ta_test_link = "https://api.tripadvisor.com/api/partner/2.0/location/8364980"
            params = { "key": tripadvisorkey }
            r = requests.get(ta_test_link, params)
            if (r.status_code == 429):
                e_code = r.json().get("code")
                req = False
        elif (apiName == "factual"):
            try:
                cw = factualClient.crosswalk()
                r = cw.filters({"factual_id": "1b5a13e0-d022-4a66-b7cd-9f48801f1196"
}).data()
            except api.APIException as e:
                if e.get_status_code() == 403:
                    # Assume this means API limit has been reached b/c we don't want
                    # to string-check the message (the only place where the specific
                    # error type is listed)
                    req = False
        elif (apiName == "yelp"):
            try:
                # Check an existing location
                yelpClient.get_business("kittea-cat-cafe-san-francisco-4")
            except errors.ExceededReqs:
                req = False
        else:
            raise ValueError("Unknown API name; see app/util.py for API values")
    except Exception as e:
        log.exception("Unknown error while checking for cap limits: %s" % e)

    db = pyrebase.initialize_app(FIREBASE_CONFIG).database()

    # Timestamped response
    response = "{} {} {}".format(req, time.strftime("%a %x %X", time.localtime()), time.tzname[0])

    # Status updated at:
    # https://console.firebase.google.com/project/prox-server-cf63e/database/data/api_availability
    db.child(statusTable).update({apiName: response})
    return req