예제 #1
0
    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_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('/')
예제 #2
0
    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_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('/')
예제 #3
0
    def post(self):
        event_id = self.request.get('event_id')
        remapped_address = self.request.get('remapped_address')
        override_address = self.request.get('override_address')

        if self.request.get('delete'):
            e = eventdata.DBEvent.get_by_id(event_id)
            # This e will be None if the user submits a deletion-form twice
            if e:
                event_updates.delete_event(e)
            self.user.add_message("Event deleted!")
            return self.redirect('/events/admin_edit?event_id=%s' % event_id)

        # We could be looking at a potential event for something that is inaccessable to our admin.
        # So we want to grab the cached value here if possible, which should exist given the admin-edit flow.
        fb_event = self.fbl.get(fb_api.LookupEvent, event_id)
        if self.request.get('background'):
            deferred.defer(add_entities.add_update_event, fb_event, self.fbl, creating_uid=self.user.fb_uid, remapped_address=remapped_address, override_address=override_address, creating_method=eventdata.CM_ADMIN)
            self.response.out.write("<title>Added!</title>Added!")
        else:
            try:
                add_entities.add_update_event(fb_event, self.fbl, creating_uid=self.user.fb_uid, remapped_address=remapped_address, override_address=override_address, creating_method=eventdata.CM_ADMIN)
            except Exception as e:
                logging.exception('Error adding event')
                self.add_error(str(e))
            self.errors_are_fatal()
            self.user.add_message("Changes saved!")
            return self.redirect('/events/admin_edit?event_id=%s' % event_id)
예제 #4
0
 def post(self):
     event_id = self.json_body.get('event_id')
     if not event_id:
         self.add_error('Need to pass event_id argument')
     self.errors_are_fatal()
     fb_event = self.fbl.get(fb_api.LookupEvent, event_id, allow_cache=False)
     add_entities.add_update_event(fb_event, self.fbl, creating_uid=self.fbl.fb_uid, creating_method=eventdata.CM_USER)
     self.write_json_success()
예제 #5
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()
예제 #6
0
 def post(self):
     event_id = self.json_body.get('event_id')
     if not event_id:
         self.add_error('Need to pass event_id argument')
     self.errors_are_fatal()
     fb_event = self.fbl.get(fb_api.LookupEvent,
                             event_id,
                             allow_cache=False)
     add_entities.add_update_event(fb_event,
                                   self.fbl,
                                   creating_uid=self.fbl.fb_uid,
                                   creating_method=eventdata.CM_USER)
     self.write_json_success()
예제 #7
0
    def post(self):
        event_id = self.request.get('event_id')
        remapped_address = self.request.get('remapped_address')
        override_address = self.request.get('override_address')

        if self.request.get('delete'):
            e = eventdata.DBEvent.get_by_id(event_id)
            # This e will be None if the user submits a deletion-form twice
            if e:
                event_updates.delete_event(e)
            self.user.add_message("Event deleted!")
            return self.redirect('/events/admin_edit?event_id=%s' % event_id)

        # We could be looking at a potential event for something that is inaccessable to our admin.
        # So we want to grab the cached value here if possible, which should exist given the admin-edit flow.
        fb_event = get_fb_event(self.fbl, event_id)
        logging.info("Fetched fb_event %s", fb_event)
        if not fb_events.is_public_ish(fb_event):
            self.add_error('Cannot add secret/closed events to dancedeets!')
        self.errors_are_fatal()

        if self.request.get('background'):
            deferred.defer(
                add_entities.add_update_event,
                fb_event,
                self.fbl,
                creating_uid=self.user.fb_uid,
                remapped_address=remapped_address,
                override_address=override_address,
                creating_method=eventdata.CM_ADMIN
            )
            self.response.out.write("<title>Added!</title>Added!")
        else:
            try:
                add_entities.add_update_event(
                    fb_event,
                    self.fbl,
                    creating_uid=self.user.fb_uid,
                    remapped_address=remapped_address,
                    override_address=override_address,
                    creating_method=eventdata.CM_ADMIN
                )
            except Exception as e:
                logging.exception('Error adding event')
                self.add_error(str(e))
            self.errors_are_fatal()
            self.user.add_message("Changes saved!")
            return self.redirect('/events/admin_edit?event_id=%s' % event_id)
예제 #8
0
def create_event(event_id='1000001', start_time=None, location='NYC'):
    if not start_time:
        start_time = datetime.datetime.now()
    fields_str = '%2C'.join(fb_api.OBJ_EVENT_FIELDS)
    base_url = '/v2.2/%s' % event_id
    url = '%s?fields=%s' % (base_url, fields_str)

    picture_url = '%s/picture?redirect=false&type=large' % base_url

    fb_api.FBAPI.results.update({
        url: (200, {
            "name": "Event Title",
            "start_time": start_time.strftime("%Y-%m-%dT%H:%M:%S-0400"),
            "id": event_id,
        }),
        '/?fields=images&ids=%7Bresult%3Dinfo%3A%24.cover.cover_id%7D': (400, {
            'error': {
                'message': 'Cannot specify an empty identifier',
                'code': 2500,
                'type': 'OAuthException'
            }
        }),
        picture_url: (200, {
            "data": {
                "url": "test image url",
            }
        }),
    })

    fbl = fb_api.FBLookup(None, None)
    fb_event = fbl.get(fb_api.LookupEvent, event_id)
    event = add_entities.add_update_event(fb_event,
                                          fbl,
                                          override_address=location)
    return event
예제 #9
0
def create_event(event_id='1000001', start_time=None, location='NYC'):
    if not start_time:
        start_time = datetime.datetime.now()
    fields_str = '%2C'.join(fb_api.OBJ_EVENT_FIELDS)
    base_url = '/v2.8/%s' % event_id
    url = '%s?fields=%s' % (base_url, fields_str)

    picture_url = '%s/picture?redirect=false&type=large' % base_url

    fb_api.FBAPI.results.update({
            url:
                (200, {
                    "name": "Event Title",
                    "start_time": start_time.strftime("%Y-%m-%dT%H:%M:%S-0400"),
                    "id": event_id,
                }),
            '/?fields=images&ids=%7Bresult%3Dinfo%3A%24.cover.cover_id%7D':
                (400, {'error': {'message': 'Cannot specify an empty identifier', 'code': 2500, 'type': 'OAuthException'}}),
            picture_url:
                (200, {
                    "data": {
                        "url": "test: image url",
                    }
                }),
    })


    fbl = fb_api.FBLookup(None, None)
    fb_event = fbl.get(fb_api.LookupEvent, event_id)
    event = add_entities.add_update_event(fb_event, fbl, override_address=location)
    return event
    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_event(fb_event, fbl, creating_method=eventdata.CM_AUTO_WEB)
            except add_entities.AddEventException:
                logging.exception('Error adding event %s', event_id)
예제 #11
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()