Exemplo n.º 1
0
def geolocate_comment_local(message={}):
    if "comment_id" not in message:
        logging.error("$$$$ nytCommunity.geolocate_comment_local:ERROR No Comment ID Provided")
        return False
    logging.info("$$$$ nytCommunity.geolocate_comment_local[" + str(message["comment_id"]) + "]")
    comment = voxpop.VPE.get_items().get(_id=message["comment_id"])
    if comment is None:
        logging.error("$$$$ nytCommunity.geolocate_comment_local:ERROR No Comment Found")
        return False
    if u"location" not in comment.doc:
        logging.error(
            "$$$$ nytCommunity.geolocate_comment_local:ERROR No Comment 'location' Provided ["
            + message["comment_id"]
            + "]"
        )
        return False
    _geo = vpGeo.geocoder().get_geo_local(comment.doc[u"location"])
    if _geo is False:
        with voxpop.VPE.beanstalkd_lock:
            voxpop.VPE.get_beanstalkd().use("geocodegmaps")
            voxpop.VPE.get_beanstalkd().put(
                pickle.dumps({"comment_id": message["comment_id"], "functions": [geolocate_comment_gmaps]}),
                pri=100000,
                delay=5,
            )
        return True
    comment.add_to_cache(_geo._id)
    _myGeo = _geo.doc
    _myGeo["key"] = _geo._id
    comment.update_doc({"geo": _geo.doc})
    return True
Exemplo n.º 2
0
def geolocate_comment_gmaps(message={}):
    if "comment_id" not in message:
        logging.error("$$$$ nytCommunity.geolocate_comment_gmaps:ERROR No Comment ID Provided")
        return True
    logging.error("$$$$ nytCommunity.geolocate_comment_gmaps[" + str(message["comment_id"]) + "]")
    comment = voxpop.VPE.get_items().get(_id=message["comment_id"])
    if comment is None:
        logging.error("$$$$ nytCommunity.geolocate_comment_gmaps:ERROR No Comment Found")
        return True
    if u"location" not in comment.doc:
        logging.error(
            "$$$$ nytCommunity.geolocate_comment_gmaps:ERROR No Comment 'location' Provided ["
            + message["comment_id"]
            + "]"
        )
        return True
    _geo = vpGeo.geocoder().get_geo_gmaps(comment.doc[u"location"])
    if _geo is False:
        return True
    comment.add_to_cache(_geo._id)
    _myGeo = _geo.doc
    _myGeo["key"] = _geo._id
    comment.update_doc({"geo": _geo.doc})
    return True