def full_name_ascii(self): """ Returns the name of the City in City, State, Province, Country format. Forces ASCII output, which is useful for passing to a geocoder. """ return force_unicode(", ".join(b for b in (asciiDammit(self.city), asciiDammit(self.state), asciiDammit(self.province), asciiDammit(self.get_country_display())) if b))
def _create_or_update_place_for_event(event, upcoming_event_info): """ Adds a Place object and an UpcomingVenue object for the related venue. """ try: upcoming_venue_info = upcoming.venue.getInfo(venue_id=upcoming_event_info['venue_id'])[0] upcoming_metro_info = upcoming.metro.getInfo(metro_id=upcoming_event_info['metro_id'])[0] except: print "\tERROR: There was an error retrieving the Upcoming venue or metro information for this event." return None upcoming_venue, created_upcoming_venue = UpcomingVenue.objects.get_or_create( upcoming_venue_id=upcoming_venue_info['id'], ) if not created_upcoming_venue: place = upcoming_venue.place place.website = upcoming_venue_info['url'] place.description = upcoming_venue_info['description'] place.address1 = upcoming_venue_info['address'] place.phone1 = upcoming_venue_info['phone'] else: place = Place( name = upcoming_venue_info['name'], slug = get_unique_slug_value(Place, slugify(upcoming_venue_info['name']))[:30], website = upcoming_venue_info['url'], description = upcoming_venue_info['description'], address1 = upcoming_venue_info['address'], phone1 = upcoming_venue_info['phone'], phone2 = '', fax = '', ) if len(upcoming_venue_info['zip']) <= 5: place.zip_code = upcoming_venue_info['zip'] # Get the city from flickr's API instead of using Upcoming's data, as Flickr's is MUCH more normalized. place.city = get_city_from_flickr(city_name=upcoming_venue_info['city'], state=upper(upcoming_metro_info['state_code']), country=upcoming_metro_info['country_code']) if place.city: print "\tFound city " + str(place.city) + " using Flickr's places API." else: # If flickr doesn't get us any data, we'll use Upcoming's (shitty) data. print "\t Couldn't find the city in Flickr's API; falling back to Upcoming's." city = upcoming_venue_info['city'], state = upper(upcoming_metro_info['state_code']) if len(upcoming_metro_info['country_code']) == 2: country = upcoming_metro_info['country_code'] else: country = '' city, created_city = City.object.get_or_create( city = city, state = state, country = country, slug = slugify(asciiDammit(city) + " " + asciiDammit(state) + " " + asciiDammit(country)), ) if created_city: city.save() place.city = city place.save() upcoming_venue.place = place upcoming_venue.user_id = upcoming_venue_info['user_id'] upcoming_venue.name = upcoming_venue_info['name'] upcoming_venue.url = upcoming_venue_info['url'] upcoming_venue.private = upcoming_venue_info['private'] upcoming_venue.save() return place