From 92ea9bf5d9f85cb894a9177ad429b521179352ac Mon Sep 17 00:00:00 2001 From: Rehan Dalal Date: Mon, 18 Mar 2013 10:58:45 -0400 Subject: [PATCH] Revert "Revert [bug 839930] Update to Tweepy 2.0" This reverts commit 0a4e2416f379cd8b1aab339eab8914784427f506. --- apps/customercare/cron.py | 18 ++++++++++++------ settings.py | 3 ++- vendor/src/tweepy | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) 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