示例#1
0
文件: tasks.py 项目: WPMedia/muckrock
def pull_data(type_, uuid, **kwargs):
    """Task to pull data from squarelet"""
    types_url = {"user": "******", "organization": "organizations"}
    types_model = {"user": Profile, "organization": Organization}
    if type_ not in types_url:
        logger.warning("Pull data received invalid type: %s", type_)
        return
    try:
        resp = squarelet_get("/api/{}/{}/".format(types_url[type_], uuid))
        resp.raise_for_status()
    except requests.exceptions.RequestException as exc:
        logger.warning("Exception during pull data: %s",
                       exc,
                       exc_info=sys.exc_info())
        pull_data.retry(
            args=(type_, uuid),
            kwargs=kwargs,
            exc=exc,
            countdown=2**pull_data.request.retries,
        )
    else:
        model = types_model[type_]
        data = resp.json()
        logger.info("Pull data for: %s %s %s", type_, uuid, data)
        model.objects.squarelet_update_or_create(uuid, data)
示例#2
0
 def get_url_auth_token_squarelet():
     """Get the URL auth token from squarelet"""
     try:
         resp = squarelet_get("/api/url_auth_tokens/{}/".format(
             self.uuid))
         resp.raise_for_status()
     except requests.exceptions.RequestException:
         return None
     return resp.json().get("url_auth_token")