def message_send(self, data): """ value={ 'channel': 'nsfw', 'show': 'not-safe-for-work', 'origin': 'feedupdater', 'message': 'error parsing feed', 'severity': '3', 'stamp': '2013-02-25T20:35:29' } """ if "channel" in data: obj = Channel.objects.get(cluster=data["channel"]) else: obj = Show.objects.get(slug=data["show"]) if "stamp" in data: d = dateutil.parser.parse(data["stamp"]) else: d = None if "path" in data: m = Message( message_object=obj, origin=data["path"], message=data["message"], severity=data["level"], timestamp=d ) else: m = Message( message_object=obj, origin=data["component"], message=str(data["context"]), severity=data["level"], timestamp=d, ) m.save()
def importer_ical(self, data): try: show = Show.objects.get(slug=data["show"]) except Show.DoesNotExist: return for uid, e in data["entries"].iteritems(): if not ICalEpisodeSource.objects.filter(identifier=uid).count(): source = ICalEpisodeSource(identifier=uid, source=show.icalfeed) source.save() ep = Episode(show=show, source=source, slug=e["slug"], status=Episode.STATUS[2][0]) ep.save() epp = EpisodePart(episode=ep) epp.begin = dateutil.parser.parse(e["begin"], ignoretz=True) epp.save() ep.current_part = epp ep.save() else: source = ICalEpisodeSource.objects.get(identifier=uid) try: ep = source.episode except Episode.DoesNotExist: text = "No episode created for uid %s as the previously" " created episode was deleted" % uid m = Message(message_object=show, origin="importer.ical", message=text, severity=3) m.save() continue ep.slug = e["slug"] ep.save() epp = ep.current_part epp.begin = dateutil.parser.parse(e["begin"], ignoretz=True) if "end" in e: epp.end = dateutil.parser.parse(e["end"], ignoretz=True) if "url" in e: epp.url = e["url"] if "description" in e: epp.description = e["description"][:200] if "title" in e: epp.title = e["title"] epp.save() if show.icalfeed.delete_missing and False: ICalEpisodeSource.objects.exclude(identifier__in=data["entries"].keys()).filter( episode__status="UPCOMING" ).delete()
def error_handler(msg, channel): logger.error(msg) m=Message(message_object=channel, origin="BackendInterpreter", message=msg, severity=3) m.save()