def create_entries_from_data_and_source(cls, data, source): """Create the needed sitting and entries""" venue = Venue.objects.get(slug=data['meta']['venue']) # Joint Sittings can be published by both Houses (identical documents) # prevent the same Sitting being created twice if 'Joint Sitting' in source.name \ and Sitting.objects.filter( venue=venue, source__name=source.name, start_date=source.date, start_time=data['meta'].get('start_time', None) ).exists(): print "skipping duplicate source %s for %s" % (source.name, source.date) return None sitting = Sitting( source=source, venue=venue, start_date=source.date, start_time=data['meta'].get('start_time', None), end_date=source.date, end_time=data['meta'].get('end_time', None), ) sitting.save() with transaction.commit_on_success(): counter = 0 for line in data['transcript']: counter += 1 entry = Entry( sitting=sitting, type=line['type'], page_number=line['page_number'], text_counter=counter, speaker_name=line.get('speaker_name', ''), speaker_title=line.get('speaker_title', ''), content=line['text'], ) entry.save() source.last_processing_success = datetime.datetime.now() source.save() return None
def create_entries_from_data_and_source( cls, data, source ): """Create the needed sitting and entries""" venue = Venue.objects.get( slug=data['meta']['venue'] ) # Joint Sittings can be published by both Houses (identical documents) # prevent the same Sitting being created twice if 'Joint Sitting' in source.name \ and Sitting.objects.filter( venue=venue, source__name=source.name, start_date=source.date, start_time=data['meta'].get('start_time', None) ).exists(): print "skipping duplicate source %s for %s" % (source.name, source.date) return None sitting = Sitting( source = source, venue = venue, start_date = source.date, start_time = data['meta'].get('start_time', None), end_date = source.date, end_time = data['meta'].get('end_time', None), ) sitting.save() with transaction.commit_on_success(): counter = 0 for line in data['transcript']: counter += 1 entry = Entry( sitting = sitting, type = line['type'], page_number = line['page_number'], text_counter = counter, speaker_name = line.get('speaker_name', ''), speaker_title = line.get('speaker_title', ''), content = line['text'], ) entry.save() source.last_processing_success = datetime.datetime.now() source.save() return None
def create_entries_from_data_and_source( cls, data, source ): """Create the needed sitting and entries""" venue = Venue.objects.get( slug=data['meta']['venue'] ) sitting = Sitting( source = source, venue = venue, start_date = source.date, start_time = data['meta'].get('start_time', None), end_date = source.date, end_time = data['meta'].get('end_time', None), ) sitting.save() with transaction.commit_on_success(): counter = 0 for line in data['transcript']: counter += 1 entry = Entry( sitting = sitting, type = line['type'], page_number = line['page_number'], text_counter = counter, speaker_name = line.get('speaker_name', ''), speaker_title = line.get('speaker_title', ''), content = line['text'], ) entry.save() source.last_processing_success = datetime.datetime.now() source.save() return None