def vidly_media_webhook(request): if not request.POST.get('xml'): return http.HttpResponseBadRequest("no 'xml'") # We can expect three pieces of XML. # 1) That the media was submitted # https://bug1135808.bugzilla.mozilla.org/attachment.cgi?id=8568143 # 2) That the media failed processing # https://bug1135808.bugzilla.mozilla.org/attachment.cgi?id=8568190 # 3) That the media succeeded processing # https://bug1135808.bugzilla.mozilla.org/attachment.cgi?id=8568149 # # If it's case number 1, just ignore it and do nothing. # If it's case number 2 or number 3, take it as a hint you can't trust # and kick off the auto-archive procedure. xml_string = request.POST['xml'].strip() try: struct = xmltodict.parse(xml_string) except ExpatError: return http.HttpResponseBadRequest("Bad 'xml'") try: struct['Response']['Result']['Task'] archiver.auto_archive() except KeyError: # If it doesn't have a "Result" or "Task", it was just a notification # that the media was added. pass return http.HttpResponse('OK\n')