def final_city(self): if self.geocode: return formatting.format_geocode(self.geocode) elif self.online: return ONLINE_ADDRESS else: return None
def runTest(self): for address, final_address in formatting_reg_data.iteritems(): logging.info('%s should be formatted as %s', address, final_address) formatted_address = formatting.format_geocode(gmaps_api.lookup_address(address), include_neighborhood=True) if formatted_address != final_address: logging.error('formatted address for %r is %r, should be %r', address, formatted_address, final_address) logging.error('%s', gmaps_api._fetch_geocode_as_json(address=address)) self.assertEqual(final_address, formatted_address)
def __init__(self, fb_event=None, db_event=None, debug=False, check_places=True): self.overridden_address = None self.fb_address = None self.remapped_address = None self.final_address = None self.geocode = None # If we're not doing a full-fledged step-by-step debug, used our cached geocode (if available) if not debug and db_event and db_event.has_geocode(): self.geocode = db_event.get_geocode() self.final_address = self.geocode.formatted_address() # Sometimes we get called with a webevent...in which case the fb_address doesn't matter if db_event.fb_event: self.fb_address = get_address_for_fb_event(db_event.fb_event) return has_overridden_address = db_event and db_event.address if not has_overridden_address and not fb_event: logging.warning( "Passed a db_event without an address, and no fb_event to pull from: %s" % db_event.id) if (not has_overridden_address and fb_event) or debug: # We try to trust the address *over* the latlong, # because fb uses bing which has less accuracy on some addresses (ie a jingsta address) self.fb_address = get_address_for_fb_event(fb_event) logging.info('fb address is %s', self.fb_address) self.remapped_address = _get_remapped_address_for(self.fb_address) if self.remapped_address: logging.info("Checking remapped address, which is %r", self.remapped_address) lookup_address = self.remapped_address or self.fb_address if lookup_address: location_geocode = gmaps_api.lookup_string( lookup_address, check_places=check_places) if location_geocode: self.geocode = location_geocode self.final_address = location_geocode.formatted_address() if not self.geocode: self.final_latlng = _get_latlng_from_event(fb_event) if self.final_latlng: self.geocode = gmaps_api.lookup_latlng(self.final_latlng) self.fb_address = formatting.format_geocode(self.geocode) self.final_address = self.final_address or self.remapped_address or self.fb_address if has_overridden_address: self.geocode = None self.overridden_address = db_event.address self.final_address = self.overridden_address if self.final_address != ONLINE_ADDRESS: self.geocode = gmaps_api.lookup_string( self.final_address, check_places=check_places) logging.info("Final address is %r", self.final_address)
def __init__(self, fb_event=None, db_event=None, debug=False): self.exact_from_event = False self.overridden_address = None self.fb_address = None self.remapped_address = None self.final_address = None has_overridden_address = db_event and db_event.address if not has_overridden_address and not fb_event: logging.warning( "Passed a db_event without an address, and no fb_event to pull from: %s" % db_event.id) if (not has_overridden_address and fb_event) or debug: self.final_latlng = _get_latlng_from_event(fb_event) if self.final_latlng: self.exact_from_event = True self.geocode = gmaps_api.get_geocode(latlng=self.final_latlng) self.fb_address = formatting.format_geocode(self.geocode) self.remapped_address = None else: self.fb_address = get_address_for_fb_event(fb_event) self.remapped_address = _get_remapped_address_for( self.fb_address) if self.remapped_address: logging.info("Checking remapped address, which is %r", self.remapped_address) self.final_address = self.remapped_address or self.fb_address if has_overridden_address: self.overridden_address = db_event.address self.final_address = self.overridden_address if not self.exact_from_event: logging.info("Final address is %r", self.final_address) if self.online: self.geocode = None elif self.final_address is not None: self.geocode = gmaps_api.get_geocode( address=self.final_address) else: self.geocode = None
def __init__(self, fb_event=None, db_event=None, debug=False): self.overridden_address = None self.fb_address = None self.remapped_address = None self.final_address = None self.geocode = None has_overridden_address = db_event and db_event.address if not has_overridden_address and not fb_event: logging.warning("Passed a db_event without an address, and no fb_event to pull from: %s" % db_event.id) if (not has_overridden_address and fb_event) or debug: # We try to trust the address *over* the latlong, # because fb uses bing which has less accuracy on some addresses (ie a jingsta address) self.fb_address = get_address_for_fb_event(fb_event) self.remapped_address = _get_remapped_address_for(self.fb_address) if self.remapped_address: logging.info("Checking remapped address, which is %r", self.remapped_address) lookup_address = self.remapped_address or self.fb_address if lookup_address: location_geocode = gmaps_api.lookup_location(lookup_address) if location_geocode: address = clean_address(location_geocode.formatted_address()) self.geocode = gmaps_api.lookup_address(address) self.final_address = location_geocode.formatted_address() if not self.geocode: self.final_latlng = _get_latlng_from_event(fb_event) if self.final_latlng: self.geocode = gmaps_api.lookup_latlng(self.final_latlng) self.fb_address = formatting.format_geocode(self.geocode) self.final_address = self.final_address or self.remapped_address or self.fb_address if has_overridden_address: self.geocode = None self.overridden_address = db_event.address self.final_address = self.overridden_address if self.final_address != ONLINE_ADDRESS: self.geocode = gmaps_api.lookup_address(self.final_address) logging.info("Final address is %r", self.final_address)
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) classified_event = event_classifier.get_classified_event(fb_event, potential_event.language) 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 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) auto_classified = '' if add_result[0]: auto_classified += 'add: %s.\n' % add_result[1] if notadd_result[0]: auto_classified += 'notadd: %s.\n' % notadd_result[1] self.display['auto_classified_types'] = auto_classified 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) location_info = event_locations.LocationInfo(fb_event, 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 fb_event_attending_maybe = get_fb_event(self.fbl, event_id, lookup_type=fb_api.LookupEventAttendingMaybe) matcher = event_attendee_classifier.get_matcher(self.fbl, fb_event, fb_event_attending_maybe) # 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 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.fbl.request(fb_api.LookupEvent, event_id, allow_cache=False) # DISABLE_ATTENDING # self.fbl.request(fb_api.LookupEventAttending, event_id, allow_cache=False) self.finish_preload() try: fb_event = self.fbl.fetched_data(fb_api.LookupEvent, event_id) # DISABLE_ATTENDING fb_event_attending = None # fb_event_attending = fbl.fetched_data(fb_api.LookupEventAttending, event_id) except fb_api.NoFetchedDataException: return self.show_barebones_page(event_id, "No fetched data") if not fb_events.is_public_ish(fb_event): 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.LookupThingFeed, '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... e = eventdata.DBEvent.get_by_id(event_id) if e and e.creating_fb_uid: creating_user = self.fbl.get(fb_api.LookupUser, e.creating_fb_uid) else: creating_user = None potential_event = potential_events.make_potential_event_without_source(event_id, fb_event, fb_event_attending) classified_event = event_classifier.get_classified_event(fb_event, potential_event.language) self.display['classified_event'] = classified_event if classified_event.is_dance_event(): dance_words_str = ', '.join(list(classified_event.dance_matches())) event_words_str = ', '.join(list(classified_event.event_matches())) else: dance_words_str = 'NONE' 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 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) auto_classified = '' if add_result[0]: auto_classified += 'add: %s.\n' % add_result[1] if notadd_result[0]: auto_classified += 'notadd: %s.\n' % notadd_result[1] self.display['auto_classified_types'] = auto_classified styles = categories.find_styles(fb_event) + categories.find_event_types(fb_event) self.display['auto_categorized_types'] = ', '.join(x.public_name for x in styles) location_info = event_locations.LocationInfo(fb_event, db_event=e, debug=True) self.display['location_info'] = location_info fb_geocode = gmaps_api.lookup_address(location_info.fb_address) self.display['fb_geocoded_address'] = formatting.format_geocode(fb_geocode) 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')