diff --git a/apps/customercare/cron.py b/apps/customercare/cron.py index 005b26d35..352a5f9ab 100644 --- a/apps/customercare/cron.py +++ b/apps/customercare/cron.py @@ -4,9 +4,6 @@ import json import logging import re import rfc822 -import time -import urllib -import urllib2 from django.conf import settings from django.db.utils import IntegrityError @@ -14,6 +11,7 @@ from django.db.utils import IntegrityError import cronjobs from multidb.pinning import pin_this_thread import tweepy +from tweepy.parsers import RawParser from sumo.redis_utils import redis_client, RedisError from statsd import statsd @@ -33,6 +31,15 @@ log = logging.getLogger('k.twitter') def collect_tweets(): """Collect new tweets about Firefox.""" with statsd.timer('customercare.tweets.time_elapsed'): + auth = tweepy.OAuthHandler(settings.TWITTER_CONSUMER_KEY, + settings.TWITTER_CONSUMER_SECRET, + secure=True) + + auth.set_access_token(settings.TWITTER_ACCESS_TOKEN, + settings.TWITTER_ACCESS_TOKEN_SECRET) + + api = tweepy.API(auth) + search_options = { 'q': 'firefox OR #fxinput', 'rpp': settings.CC_TWEETS_PERPAGE, # Items per page. @@ -51,9 +58,8 @@ def collect_tweets(): # Retrieve Tweets try: - raw_data = json.load(urllib.urlopen('%s?%s' % ( - SEARCH_URL, urllib.urlencode(search_options)))) - except Exception, e: + raw_data = json.loads(str(api.search(**search_options))) + except tweepy.TweepError, e: log.warning('Twitter request failed: %s' % e) return diff --git a/settings.py b/settings.py index 7a0b46346..8a1f1be99 100644 --- a/settings.py +++ b/settings.py @@ -981,7 +981,8 @@ CC_BANNED_USERS = ['lucasbytegenius'] # Twitter handles banned from AoA TWITTER_COOKIE_SECURE = True TWITTER_CONSUMER_KEY = '' TWITTER_CONSUMER_SECRET = '' - +TWITTER_ACCESS_TOKEN = '' +TWITTER_ACCESS_TOKEN_SECRET = '' TIDINGS_FROM_ADDRESS = 'notifications@support.mozilla.org' # Anonymous watches must be confirmed. diff --git a/vendor/src/tweepy b/vendor/src/tweepy index cf4ebd0d2..957f2762c 160000 --- a/vendor/src/tweepy +++ b/vendor/src/tweepy @@ -1 +1 @@ -Subproject commit cf4ebd0d2698bbfa0ccf10a29399a396306de68a +Subproject commit 957f2762c68b6d539b2733a01b4650a251f8cae4