<commit_before>from datetime import datetime
import json
import logging
import re
import cgi

from django.conf import settings
import httplib2
import oauth2 as oauth
from urllib import urlencode
from urlparse import urlunparse

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


log = logging.getLogger(__name__)


def poll_facebook(account):
    user = account.person.user
    if user is None:
        log.debug("No user attached to account %r. Skipping.", account)
        return

    access_token = account.authinfo
    if not access_token:
        log.error("Account %r has no authinfo. Ignoring.", account)
        # Nothing to do!
        return

    # Now find out who this user is
    query = { 'access_token': access_token }
    url = urlunparse(('https', 'graph.facebook.com', 'me/home', None, urlencode(query), None))
    log.debug("Fetching news feed for %r from %s", account, url)
    h = httplib2.Http()
    resp, content = h.request(url, method='GET')
    feed = json.loads(content)

    if 'error' in feed:
        log.error("Facebook returned %s: %s", feed['error']['type'], feed['error']['message'])<commit_msg>Expect Facebook OAuthExceptions since people like to change their passwords<commit_after>from datetime import datetime
import json
import logging
import re
import cgi

from django.conf import settings
import httplib2
import oauth2 as oauth
from urllib import urlencode
from urlparse import urlunparse

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


log = logging.getLogger(__name__)


def poll_facebook(account):
    user = account.person.user
    if user is None:
        log.debug("No user attached to account %r. Skipping.", account)
        return

    access_token = account.authinfo
    if not access_token:
        log.error("Account %r has no authinfo. Ignoring.", account)
        # Nothing to do!
        return

    # Now find out who this user is
    query = { 'access_token': access_token }
    url = urlunparse(('https', 'graph.facebook.com', 'me/home', None, urlencode(query), None))
    log.debug("Fetching news feed for %r from %s", account, url)
    h = httplib2.Http()
    resp, content = h.request(url, method='GET')
    feed = json.loads(content)

    if 'error' in feed:
        if feed['error']['type'] == 'OAuthException':
            # User probably changed their password. Ignore it.
            log.debug("Facebook returned OAuthException I'm ignoring: %s", feed['error']['message'])
            return
        log.error("Facebook returned %s: %s", feed['error']['type'], feed['error']['message'])
{'fraction_non_alphanumeric': 0.10797773654916512, 'fraction_numerical': 0.0022263450834879408, 'mean_word_length': 3.54637436762226, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2818413', 'n_tokens_mistral': 783, 'n_tokens_neox': 771, 'n_words': 266}