def handle_notification(request): """ Handle bounced emails via an SNS webhook. """ try: notification = json.loads(request.body) except ValueError, e: client.captureException() return HttpResponseBadRequest()
def handle_Notification(notification): message = json.loads(notification['Message']) notification_type = message.get('notificationType') if notification_type == 'Bounce': handle_bounce(message) elif notification_type == 'Complaint': handle_complaint(message)
def verify(url): tries = 3 for try_ in range(1, tries + 1): try: req = urllib2.Request(url, data) resp = urllib2.urlopen(req, timeout=18) # app timeout is supposed to be 60 return json.loads(resp.read()) except (urllib2.URLError, socket_error) as e: if try_ == tries: raise e
def verify(url): tries = 3 for try_ in range(1, tries + 1): try: req = urllib2.Request(url, data) resp = urllib2.urlopen( req, timeout=18) # app timeout is supposed to be 60 return json.loads(resp.read()) except (urllib2.URLError, socket_error) as e: if try_ == tries: raise e
def _canvas_api(endpoint, data): data = json.dumps(data) headers = { 'Authorization': 'Basic ZHJhd3F1ZXN0OkRUZ3JnWTJT', # DTgrgY2S 'Content-Type': 'application/json', 'Content-Length': len(data), 'X_REQUESTED_WITH': 'XMLHttpRequest', 'ACCEPT': '*/*', } req = urllib2.Request('https://example.com/api' + endpoint, data, headers) f = urllib2.urlopen(req, timeout=_CANVAS_TIMEOUT) resp = json.loads(f.read()) f.close() return resp
def save_stroke_count(comment, playback_data): stroke_count = None if isinstance(playback_data, basestring): try: playback_data = json.loads(playback_data) except JSONDecodeError: stroke_count = playback_data.count("components") if stroke_count is None: try: stroke_count = len(playback_data["strokes"]) except (KeyError, TypeError): return comment.reply_content.stroke_count = stroke_count comment.reply_content.save()
def save_stroke_count(comment, playback_data): stroke_count = None if isinstance(playback_data, basestring): try: playback_data = json.loads(playback_data) except JSONDecodeError: stroke_count = playback_data.count('components') if stroke_count is None: try: stroke_count = len(playback_data['strokes']) except ( KeyError, TypeError, ): return comment.reply_content.stroke_count = stroke_count comment.reply_content.save()
def _moderation_context(sections, id_range=None): per_page = knobs.WHITELIST_COMMENTS_PER_PAGE if id_range is not None: from_, to = get_divvy_range(id_range) per_page = knobs.WHITELIST_COMMENTS_PER_PAGE * (to - from_) comments = [] left_per_page = per_page for section in sections: if left_per_page == 0: break incoming_comments = section[:left_per_page] left_per_page -= len(incoming_comments) if id_range is None: comments.extend(list(incoming_comments)) else: comments.extend(list(divvy(incoming_comments, from_, to))) if id_range is not None: comments = divvy(comments, from_, to) try: auto_curate = loads(redis.get('dq:auto_curate')) except TypeError: auto_curate = False min_ago = time.time() - 60 return { 'comments': comments, 'auto_curate_enabled': auto_curate, 'body_class': 'moderation', }
def verify(url): req = urllib2.Request(url, data) resp = urllib2.urlopen(req) return json.loads(resp.read())
def _check(self, cmt_id, playback_data): resp = self.api_post('/api/playback/playback_data', {'comment_id': cmt_id}) self.assertAPISuccess(resp) self.assertEqual(json.loads(resp['playback_data']), json.loads(playback_data))
def json_data(self): return json.loads(self.blob)