def send_notice_impl(self, user, type, context): from film20.account.models import OAuthService message = self.render_template(type, 'twitter.txt', context, 140) service = OAuthService.get_by_name("twitter") token = service.get_access_token(user) for url in set(self.URL_RE.findall(message)): message = message.replace(url, shorten(url)) service.post(token, message)
def handle(self, *args, **kw): twitter = OAuthService.get_by_name('twitter') profiles = Profile.objects.filter(twitter_access_token__gt='', user__username='******') total = profiles.count() for n, profile in enumerate(profiles): print "%3s/%s" % (n + 1, total), profile.user.username try: info = twitter.get_user_info(profile.twitter_access_token) print 'ok' except urllib2.HTTPError: new_token = settings.TWITTER_EXTRA_KEY + '|' + profile.twitter_access_token try: info = twitter.get_user_info(new_token) profile.twitter_access_token = new_token profile.save() print 'fixed' except urllib2.HTTPError: pass