def post(self): if self.request.get('event_id'): event_id = self.request.get('event_id') elif self.request.get('event_url'): event_id = urls.get_event_id_from_url( self.request.get('event_url')) if not event_id: self.add_error('invalid event_url, expecting eid= parameter') else: self.add_error('missing event_url or event_id parameter') self.errors_are_fatal() try: # Skip cache so we always get latest data for newly-added event fb_event = self.fbl.get(fb_api.LookupEvent, event_id, allow_cache=False) add_entities.add_update_fb_event(fb_event, self.fbl, creating_uid=self.user.fb_uid, creating_method=eventdata.CM_USER) except Exception as e: self.add_error(str(e)) self.errors_are_fatal() if self.request.get('ajax'): self.write_json_response({'success': True}) return else: self.user.add_message('Your event "%s" has been added.' % fb_event['info']['name']) return self.redirect('/')
def get(self): fb_event = None events = [] if self.request.get('event_url'): event_id = urls.get_event_id_from_url( self.request.get('event_url')) else: event_id = self.request.get('event_id') if event_id and not self._errors: logging.info("Showing page for adding event %s", event_id) fb_event = self.fbl.get(fb_api.LookupEvent, event_id) else: logging.info( "Showing page for selecting an event to add. Querying user %s", self.fb_uid) events = add_events.get_decorated_user_events(self.fbl) if self.request.get('new_only') == '1': events = [x for x in events if not x['loaded']] self.display['events'] = events self.display['fb_event'] = fb_event self.jinja_env.filters['parse_fb_timestamp'] = dates.parse_fb_timestamp self.render_template('add')
def handle_error_response(self, errors): event_id = None if self.request.get('event_url'): event_id = urls.get_event_id_from_url( self.request.get('event_url')) elif self.request.get('event_id'): event_id = self.request.get('event_id') error_string = ','.join(errors) self.show_barebones_page(event_id, error_string) return True
def post(self): if self.json_body['scrapinghub_key'] != keys.get('scrapinghub_key'): self.response.status = 403 return fb_uid = '701004' user = users.User.get_by_id(fb_uid) fbl = fb_api.FBLookup(fb_uid, user.fb_access_token) for event_url in self.json_body['events']: logging.info('Adding %s', event_url) event_id = urls.get_event_id_from_url(event_url) if not event_id: logging.warning('Not a valid fb event for adding: %s', event_url) continue fb_event = fbl.get(fb_api.LookupEvent, event_id, allow_cache=False) try: add_entities.add_update_fb_event( fb_event, fbl, creating_method=eventdata.CM_AUTO_WEB) except add_entities.AddEventException: logging.exception('Error adding event %s', event_id)
def get(self): event_id = None if self.request.get('event_url'): event_id = urls.get_event_id_from_url( self.request.get('event_url')) elif self.request.get('event_id'): event_id = self.request.get('event_id') self.finish_preload() fb_event = get_fb_event(self.fbl, event_id) if not fb_event: logging.error('No fetched data for %s, showing error page', event_id) return self.show_barebones_page(event_id, "No fetched data") e = eventdata.DBEvent.get_by_id(event_id) if not fb_events.is_public_ish(fb_event): if e: fb_event = e.fb_event else: self.add_error( 'Cannot add secret/closed events to dancedeets!') self.errors_are_fatal() owner_location = None if 'owner' in fb_event['info']: owner_id = fb_event['info']['owner']['id'] location = self._get_location(owner_id, fb_api.LookupProfile, 'profile') or self._get_location( owner_id, fb_api.LookupThingPage, 'info') if location: owner_location = event_locations.city_for_fb_location(location) self.display['owner_location'] = owner_location display_event = search.DisplayEvent.get_by_id(event_id) # Don't insert object until we're ready to save it... if e and e.creating_fb_uid: #STR_ID_MIGRATE creating_user = self.fbl.get(fb_api.LookupProfile, str(e.creating_fb_uid)) if creating_user.get('empty'): logging.warning( 'Have creating-user %s...but it is not publicly visible, so treating as None: %s', e.creating_fb_uid, creating_user) creating_user = None else: creating_user = None potential_event = potential_events.make_potential_event_without_source( event_id) a = time.time() classified_event = event_classifier.get_classified_event( fb_event, potential_event.language) timelog.log_time_since('Running BasicText Classifier', a) self.display['classified_event'] = classified_event dance_words_str = ', '.join(list(classified_event.dance_matches())) if classified_event.is_dance_event(): event_words_str = ', '.join(list(classified_event.event_matches())) else: event_words_str = 'NONE' self.display['classifier_dance_words'] = dance_words_str self.display['classifier_event_words'] = event_words_str self.display['creating_user'] = creating_user self.display['potential_event'] = potential_event self.display['display_event'] = display_event start = time.time() add_result = event_auto_classifier.is_auto_add_event(classified_event) notadd_result = event_auto_classifier.is_auto_notadd_event( classified_event, auto_add_result=add_result) timelog.log_time_since('Running Text Classifier', start) auto_classified = '' if add_result.is_good_event(): auto_classified += 'add: %s.\n' % add_result if notadd_result[0]: auto_classified += 'notadd: %s.\n' % notadd_result[1] self.display['auto_classified_add'] = add_result self.display['auto_classified_notadd'] = notadd_result styles = categories.find_styles(fb_event) event_types = styles + categories.find_event_types(fb_event) self.display['auto_categorized_types'] = ', '.join( x.public_name for x in event_types) a = time.time() fb_event_attending_maybe = get_fb_event( self.fbl, event_id, lookup_type=fb_api.LookupEventAttendingMaybe) timelog.log_time_since('Loading FB Event Attending Data', a) a = time.time() location_info = event_locations.LocationInfo( fb_event, fb_event_attending_maybe=fb_event_attending_maybe, db_event=e, debug=True) self.display['location_info'] = location_info if location_info.fb_address: fb_geocode = gmaps_api.lookup_address(location_info.fb_address) self.display['fb_geocoded_address'] = formatting.format_geocode( fb_geocode) else: self.display['fb_geocoded_address'] = '' city_name = 'Unknown' if location_info.geocode: city = cities_db.get_nearby_city( location_info.geocode.latlng(), country=location_info.geocode.country()) if city: city_name = city.display_name() self.display['ranking_city_name'] = city_name person_ids = fb_events.get_event_attendee_ids(fb_event_attending_maybe) if location_info.geocode: data = person_city.get_data_fields(person_ids, location_info.geocode.latlng()) self.display['attendee_distance_info'] = data else: self.display['attendee_distance_info'] = 'Unknown' matcher = event_attendee_classifier.get_matcher( self.fbl, fb_event, fb_event_attending_maybe=fb_event_attending_maybe, classified_event=classified_event) timelog.log_time_since('Running Attendee Classifier', a) # print '\n'.join(matcher.results) sorted_matches = sorted(matcher.matches, key=lambda x: -len(x.overlap_ids)) matched_overlap_ids = sorted_matches[ 0].overlap_ids if matcher.matches else [] self.display['auto_add_attendee_ids'] = sorted(matched_overlap_ids) self.display['overlap_results'] = [ '%s %s: %s' % (x.top_n, x.name, x.reason) for x in sorted_matches ] self.display['overlap_attendee_ids'] = sorted(matcher.overlap_ids) if matcher.matches: attendee_ids_to_admin_hash_and_event_ids = sorted_matches[ 0].get_attendee_lookups() self.display[ 'attendee_ids_to_admin_hash_and_event_ids'] = attendee_ids_to_admin_hash_and_event_ids self.display['event'] = e self.display['event_id'] = event_id self.display['fb_event'] = fb_event self.jinja_env.filters[ 'highlight_keywords'] = event_classifier.highlight_keywords self.display['track_analytics'] = False self.render_template('admin_edit')
def post(self): if self.request.get('event_url'): event_id = urls.get_event_id_from_url( self.request.get('event_url')) if not event_id: self.add_error('Unrecognized Facebook event URL') else: self.add_error('Missing Facebook event URL') self.errors_are_fatal() event_errors = [] event_warnings = [] try: fb_event = self.fbl.get(fb_api.LookupEvent, event_id, allow_cache=False) except fb_api.NoFetchedDataException: event_errors.append( 'Unable to fetch event. Please adjust your event privacy settings, or log in.' ) return if 'cover_info' not in fb_event['info']: event_errors.append('The event needs a cover photo.') start_time = dates.parse_fb_start_time(fb_event) if start_time < datetime.datetime.now() - datetime.timedelta(days=1): event_errors.append( 'Your event appears to be in the past. You should fix the date.' ) if 'name' not in fb_event['info']: event_errors.append('The event needs a name.') if 'description' not in fb_event['info']: event_errors.append('The event needs a description.') if not fb_events.is_public(fb_event): event_errors.append( 'The event privacy settings are too restricted.') classified_event = event_classifier.classified_event_from_fb_event( fb_event) classified_event.classify() auto_add_result = event_auto_classifier.is_auto_add_event( classified_event) if not auto_add_result.is_good_event(): event_warnings.append( "The event wouldn't be automatically added. There weren't enough strong keywords for the system to identify it." ) auto_notadd_result = event_auto_classifier.is_auto_notadd_event( classified_event, auto_add_result=auto_add_result) if auto_notadd_result[0]: event_warnings.append( 'The event appears to be the "wrong" kind of dance event for DanceDeets. Are you sure it is a street dance event?' ) # Intentionally don't pass the fb_event_attending_maybe, since we want the event to be tested standalone location_info = event_locations.LocationInfo(fb_event) if not location_info.geocode: event_errors.append( 'Your event has no location. Please select a particular address, city, state, or country for this event.' ) elif 'place' not in fb_event['info']: event_warnings.append( 'For best results, your event should select a location from one of the venues Facebook suggests. DanceDeets believes your event is in %s' % location_info.final_city) self.display['event_warnings'] = event_warnings self.display['event_errors'] = event_errors self.display['event'] = fb_event # Add Event if self.request.get('force_add') or not event_errors: self.user.add_message('Your event "%s" has been added.' % fb_event['info']['name']) add_entities.add_update_fb_event(fb_event, self.fbl, creating_uid=self.user.fb_uid, creating_method=eventdata.CM_USER) self.render_page()