<commit_before>from __future__ import division

from datetime import datetime
import json
import logging
import re
from urllib import urlencode

from django.conf import settings
import httplib2
import oauth2 as oauth

from leapfrog.models import Account, Media, Person, Object, UserStream
import leapfrog.poll.embedlam


log = logging.getLogger(__name__)


def call_vimeo(method, token=None, **kwargs):
    csr = oauth.Consumer(*settings.VIMEO_CONSUMER)

    http_url = 'http://vimeo.com/api/rest/v2?format=json&method=%s' % method
    if kwargs:
        http_url = '&'.join((http_url, urlencode(kwargs)))
    oauth_request = oauth.Request.from_consumer_and_token(csr, token,
        http_method='GET', http_url=http_url)
    oauth_sign_method = oauth.SignatureMethod_HMAC_SHA1()
    oauth_request.sign_request(oauth_sign_method, csr, token)
    oauth_signing_base = oauth_sign_method.signing_base(oauth_request, csr, token)
    oauth_header = oauth_request.to_header()

    h = httplib2.Http()
    h.follow_redirects = 0
    normal_url = oauth_request.to_url()
    log.debug('Making request to URL %r', normal_url)
    try:
        resp, content = h.request(normal_url, method=oauth_request.method,
            headers=oauth_header)
    except socket.error, exc:
        raise leapfrog.poll.embedlam.RequestError("Request to %s could not complete: %s" % (uri, str(exc)))

    if resp.status == 500:
        raise leapfrog.poll.embedlam.RequestError("500 Server Error making Vimeo request %s" % normal_url)<commit_msg>Ignore 503 errors too<commit_after>from __future__ import division

from datetime import datetime
import json
import logging
import re
from urllib import urlencode

from django.conf import settings
import httplib2
import oauth2 as oauth

from leapfrog.models import Account, Media, Person, Object, UserStream
import leapfrog.poll.embedlam


log = logging.getLogger(__name__)


def call_vimeo(method, token=None, **kwargs):
    csr = oauth.Consumer(*settings.VIMEO_CONSUMER)

    http_url = 'http://vimeo.com/api/rest/v2?format=json&method=%s' % method
    if kwargs:
        http_url = '&'.join((http_url, urlencode(kwargs)))
    oauth_request = oauth.Request.from_consumer_and_token(csr, token,
        http_method='GET', http_url=http_url)
    oauth_sign_method = oauth.SignatureMethod_HMAC_SHA1()
    oauth_request.sign_request(oauth_sign_method, csr, token)
    oauth_signing_base = oauth_sign_method.signing_base(oauth_request, csr, token)
    oauth_header = oauth_request.to_header()

    h = httplib2.Http()
    h.follow_redirects = 0
    normal_url = oauth_request.to_url()
    log.debug('Making request to URL %r', normal_url)
    try:
        resp, content = h.request(normal_url, method=oauth_request.method,
            headers=oauth_header)
    except socket.error, exc:
        raise leapfrog.poll.embedlam.RequestError("Request to %s could not complete: %s" % (uri, str(exc)))

    if resp.status == 503:
        raise leapfrog.poll.embedlam.RequestError("503 Service Unavailable making Vimeo request %s" % normal_url)
    if resp.status == 500:
        raise leapfrog.poll.embedlam.RequestError("500 Server Error making Vimeo request %s" % normal_url)
{'fraction_non_alphanumeric': 0.09764521193092622, 'fraction_numerical': 0.010361067503924647, 'mean_word_length': 4.292358803986711, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '199619', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1043, 'n_words': 240}