def process_event_from_json(self, event_kind, event_url, event_json): source_id = self.event_source_id(event_json) event = self.fetch_existing_event(source_id) if event is None: event = Event() organiser_email = self.fetch_organiser_email_from_bsd(event_json) venue = self.venue_for_event(event) (new_event, new_venue) = self.new_models_from_json(event_json) new_event.event_url = event_url new_event.source_id = source_id new_event.organiser_email = organiser_email if not self.are_model_instances_identical(venue, new_venue): venue = new_venue venue.save() if not self.are_model_instances_identical(event, new_event): if event.id: new_event.id = event.id event = new_event if event.id: log.info('Updating event %s from %s' % (event.id, event_url)) else: log.info('Adding new event for %s' % event_url) event.kind = event_kind event.venue = venue event.public = True event.verified = True event.save()
def process(self): input_query = Event.all_upcoming_bsd() if input_query.count() > 50: input_query = self.subset(input_query) for event in input_query: response = requests.head(event.event_url) if response.status_code == 404: log.info('Deleting event %s' % event.event_url) event.delete()
def process_event_from_json(self, event_kind, event_url, event_json): source_id = event_json['event_id'] event = self.fetch_existing_event(source_id) if event is None: event = Event() organiser_email = self.fetch_organiser_email_from_bsd(event_json) venue = self.venue_for_event(event) (new_event, new_venue) = self.new_models_from_json(event_json) new_event.event_url = event_url new_event.source_id = source_id new_event.source = 'bsd' new_event.organiser_email = organiser_email new_event.kind = event_kind new_event.public = True new_event.verified = True if event.id: log.info('Updating event %s from %s' % (event.id, event_url)) else: log.info('Adding new event for %s' % event_url) EventAndVenueUpdater.update(event, new_event, venue, new_venue)
def new_models_from_json(self, event_json): model_data = self.extract_from_event_json(event_json) event = Event(**model_data['event']) venue = Venue(**model_data['venue']) return (event, venue)