예제 #1
0
 def runTest(self):
     e = {'info': {'start_time': '2012-04-18T05:30:00T-0800', 'timezone': 'America/Los_Angeles'}}
     self.assertEqual(dates.parse_fb_start_time(e),
                      datetime.datetime(2012, 4, 18, 5, 30))
     e = {'info': {'start_time': '2012-04-17T13:30:00'}}
     self.assertEqual(dates.parse_fb_start_time(e),
                      datetime.datetime(2012, 4, 17, 13, 30))
예제 #2
0
 def runTest(self):
     e = {
         'info': {
             'start_time': '2012-04-18T05:30:00T-0800',
             'timezone': 'America/Los_Angeles'
         }
     }
     self.assertEqual(dates.parse_fb_start_time(e),
                      datetime.datetime(2012, 4, 18, 5, 30))
     e = {'info': {'start_time': '2012-04-17T13:30:00'}}
     self.assertEqual(dates.parse_fb_start_time(e),
                      datetime.datetime(2012, 4, 17, 13, 30))
def classified_event_from_fb_event(fb_event, language=None):
    return ClassifiedEvent(
        fb_event['info'].get('name', ''),
        fb_event['info'].get('description', ''),
        dates.parse_fb_start_time(fb_event),
        dates.parse_fb_end_time(fb_event),
        language=language
    )
예제 #4
0
    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_event_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[0]:
            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?')

        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_event(fb_event, self.fbl, creating_uid=self.user.fb_uid, creating_method=eventdata.CM_USER)
        self.render_page()
 def set_past_event(self, fb_event):
     if not fb_event:
         past_event = True
     elif fb_event['empty']:
         past_event = True
     else:
         start_time = dates.parse_fb_start_time(fb_event)
         end_time = dates.parse_fb_end_time(fb_event)
         past_event = (dates.TIME_PAST == dates.event_time_period(
             start_time, end_time))
     changed = (self.past_event != past_event)
     self.past_event = past_event
     return changed
예제 #6
0
def _inner_make_event_findable_for_fb_event(db_event, fb_dict, update_geodata):
    """set up any cached fields or bucketing or whatnot for this event"""

    # Update this event with the latest time_period regardless (possibly overwritten below)
    db_event.search_time_period = _event_time_period(db_event)

    if fb_dict['empty'] == fb_api.EMPTY_CAUSE_DELETED:
        # If this event has already past, don't allow it to be deleted. We want to keep history!
        if db_event.end_time and db_event.end_time < datetime.datetime.now(
        ) - datetime.timedelta(days=2):
            return
        # If we don't have a db_event.end_time, then we've got something messed up, so let's delete the event
        db_event.start_time = None
        db_event.end_time = None
        db_event.search_time_period = None
        db_event.address = None
        db_event.actual_city_name = None
        db_event.city_name = None
        db_event.fb_event = fb_dict
        return
    elif fb_dict['empty'] == fb_api.EMPTY_CAUSE_INSUFFICIENT_PERMISSIONS:
        db_event.search_time_period = _event_time_period(db_event)
        # Don't copy the fb_event over, or any of its fields
        return

    # Screw db-normalized form, store this here (and location_geocode down below)
    db_event.fb_event = fb_dict
    if 'owner' in fb_dict['info']:
        db_event.owner_fb_uid = fb_dict['info']['owner']['id']
    else:
        db_event.owner_fb_uid = None

    db_event.attendee_count = _all_attending_count(fb_dict)

    db_event.start_time = dates.parse_fb_start_time(fb_dict)
    db_event.end_time = dates.parse_fb_end_time(fb_dict)
    db_event.search_time_period = _event_time_period(db_event)

    db_event.event_keywords = event_classifier.relevant_keywords(fb_dict)
    db_event.auto_categories = [
        x.index_name for x in categories.find_styles(fb_dict) +
        categories.find_event_types(fb_dict)
    ]

    if update_geodata:
        # Don't use cached/stale geocode when constructing the LocationInfo here
        db_event.location_geocode = None
        location_info = event_locations.LocationInfo(fb_dict,
                                                     db_event=db_event)
        _update_geodata(db_event, location_info)
예제 #7
0
def _inner_make_event_findable_for_fb_event(db_event, fb_dict, update_geodata):
    """set up any cached fields or bucketing or whatnot for this event"""

    # Update this event with the latest time_period regardless (possibly overwritten below)
    db_event.search_time_period = _event_time_period(db_event)

    if fb_dict['empty'] == fb_api.EMPTY_CAUSE_DELETED:
        # If this event has already past, don't allow it to be deleted. We want to keep history!
        if db_event.end_time and db_event.end_time < datetime.datetime.now() - datetime.timedelta(days=2):
            return
        # If we don't have a db_event.end_time, then we've got something messed up, so let's delete the event
        db_event.start_time = None
        db_event.end_time = None
        db_event.search_time_period = None
        db_event.address = None
        db_event.actual_city_name = None
        db_event.city_name = None
        db_event.fb_event = fb_dict
        return
    elif fb_dict['empty'] == fb_api.EMPTY_CAUSE_INSUFFICIENT_PERMISSIONS:
        db_event.search_time_period = _event_time_period(db_event)
        # Don't copy the fb_event over, or any of its fields
        return

    # Screw db-normalized form, store this here (and location_geocode down below)
    db_event.fb_event = fb_dict
    if 'owner' in fb_dict['info']:
        db_event.owner_fb_uid = fb_dict['info']['owner']['id']
    else:
        db_event.owner_fb_uid = None

    db_event.attendee_count = _all_attending_count(fb_dict)

    db_event.start_time = dates.parse_fb_start_time(fb_dict)
    db_event.end_time = dates.parse_fb_end_time(fb_dict)
    db_event.search_time_period = _event_time_period(db_event)

    db_event.event_keywords = event_classifier.relevant_keywords(fb_dict)
    db_event.auto_categories = [x.index_name for x in categories.find_styles(fb_dict) + categories.find_event_types(fb_dict)]

    _inner_cache_photo(db_event)

    if update_geodata:
        # Don't use cached/stale geocode when constructing the LocationInfo here
        db_event.location_geocode = None
        location_info = event_locations.LocationInfo(fb_dict, db_event=db_event)
        _update_geodata(db_event, location_info)
예제 #8
0
    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[0]:
            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?'
            )

        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_event(fb_event,
                                          self.fbl,
                                          creating_uid=self.user.fb_uid,
                                          creating_method=eventdata.CM_USER)
        self.render_page()
def classified_event_from_fb_event(fb_event, language=None):
    return ClassifiedEvent(fb_event['info'].get('name', ''),
                           fb_event['info'].get('description', ''),
                           dates.parse_fb_start_time(fb_event),
                           dates.parse_fb_end_time(fb_event),
                           language=language)