Example #1
0
    def get (self) :

        if not self.check_logged_in(self.min_perms) :
            self.do_flickr_auth(self.min_perms)
            return
        
        crumb = self.generate_crumb(self.user, 'method=unblock')
        self.assign('unblock_crumb', crumb)

        # fix me: pagination
        
        res = Blocked.blocked_by_user(self.user.nsid)
        blocked = res.fetch(20)

        users = []
        
        for b in blocked :
            users.append(User.get_user_by_nsid(b.blocked_nsid))

        self.assign('blocked_users', users)
        self.assign('count_blocked', len(users))

        #
        
        self.display('blocked.html')
Example #2
0
    def run (self) :

        required = ('user_id',)

        if not self.ensure_args(required) :
            return 

	user_id = self.request.get('user_id')
        
        user = User.get_user_by_nsid(user_id)
        
        if not user :
            self.api_error(1, 'Not a valid user')
            return

        if user.buddyicon_url :
            self.api_ok({'buddyicon_url' : user.buddyicon_url})
            return

        rsp = self.get_people_info(self, user.nsid)

        if not rsp :
            self.api_error(2, 'Failed to retrieve buddyicon')
            return

        if rsp['person']['iconfarm'] == 0 :
            self.api_error(3, 'User has not chosen a buddyicon')
            return
        
        buddyicon = "http://farm%s.static.flickr.com/%s/buddyicons/%s.jpg" % (rsp['person']['iconfarm'], rsp['person']['iconserver'], self.user.nsid)

        User.set_buddyicon_url(user, buddyicon)

        self.api_ok({'buddyicon_url' : buddyicon})
        return
Example #3
0
    def get(self):

        if not self.check_logged_in(self.min_perms):
            self.do_flickr_auth(self.min_perms)
            return

        crumb = self.generate_crumb(self.user, 'method=unblock')
        self.assign('unblock_crumb', crumb)

        # fix me: pagination

        res = Blocked.blocked_by_user(self.user.nsid)
        blocked = res.fetch(20)

        users = []

        for b in blocked:
            users.append(User.get_user_by_nsid(b.blocked_nsid))

        self.assign('blocked_users', users)
        self.assign('count_blocked', len(users))

        #

        self.display('blocked.html')
Example #4
0
    def run (self) :

        required = ('user_id',)

        if not self.ensure_args(required) :
            return 

	user_id = self.request.get('user_id')
        
        user = User.get_user_by_nsid(user_id)
        
        if not user :
            self.api_error(1, 'Not a valid user')
            return

        if user.path_alias :
            self.api_ok({'buddyicon_url' : user.buddyicon_url})
            return

        rsp = self.get_people_info(self, user.nsid)

        if not rsp :
            self.api_error(2, 'Failed to retrieve buddyicon')
            return

        url = rsp['person']['photosurl']['_content']

        if url.endswith("/") :
            url = url[:-1]

        path_alias = os.path.basename(url)

        if path_alias == user.nsid :
            self.api_error(1, 'No path alias defined')

        User.set_path_alias(user, path_alias)

        self.api_ok({'path_alias' : path_alias})
        return
Example #5
0
    def run (self) :

        required = ('crumb', 'suggestion_id', 'geo_perms', 'geo_context')
        
        if not self.ensure_args(required) :
            return 

        if not self.ensure_crumb('method=approve') :
            return

        suggestion_id = self.request.get('suggestion_id')
        suggestion = self.fetch_pending_suggestion(suggestion_id)
        
        if not suggestion:
            return 

        # Here's a potential problem: In order to do this properly
        # we may need to call the Flickr API (6) times and we're
        # doing all of them synchronously there's always the risk
        # that one of them will time out. Some possibilities include
        # doing the machinetag and comment stuff as queued tasks but
        # that probably puts too many eggs in the app engine basket.
        
        # Required:
        # flickr.photos.getInfo
        # flickr.photos.geo.setLocation

        # Possible:
        # flickr.photos.geo.setPerms        
        # flickr.photos.addTags
        # flickr.photos.comments.addComment
        
        #
        # Check to see if the photo has already been geotagged
        #
        
        args = {
            'photo_id' : suggestion.photo_id,
            'auth_token' : self.user.token,
            'check_response' : 1,
            }

        rsp = self.api_call('flickr.photos.getInfo', args)
        
        if not rsp :
            self.api_error(8, 'Unable to retrieve photo information from Flickr')
            return

        if rsp['photo'].has_key('location') :
            Suggestion.reject_all_pending_suggestions_for_photo(suggestion.photo_id)
        
            self.api_error(9, 'Photo has already been geotagged')
            return

        #
        # Also, this is all cloned in Robots/Suggestibot <-- it should probably
        # go in a "library" but the whole thing gets wrapped up in boring
        # object/globals/self nonsense and the fact that there aren't any
        # in Suggestion.py
        #
        
        #
        # Okay! Geotag the f*****g photo!!!
        #

        accuracy = suggestion.accuracy

        if accuracy > 16 :
            accuracy = 16
            
        args = {'photo_id' : suggestion.photo_id,
                'lat' : suggestion.latitude,
                'lon' : suggestion.longitude,
                'accuracy' : accuracy,
                'auth_token' : self.user.token,
                }

        geo_context = self.request.get('geo_context')
        
        if geo_context and int(geo_context) != 0 :
            args['context'] = geo_context
            
        rsp = self.api_call('flickr.photos.geo.setLocation', args)

        if not rsp :
            self.api_error(10, 'Failed to set location: Flickr API call failed')
            
        if rsp['stat'] != 'ok' :
            self.api_error(10, 'Failed to set location: %s (%s)' % (rsp['message'], rsp['code']))
            return

        #
        # Geo perms (it would be better if you could assign perms in setLocation...)
        #

        geoperms = int(self.request.get('geo_perms'))
        default = self.default_geoperms()

        if geoperms != default :

            method = 'flickr.photos.geo.setPerms'

            args = {
                'photo_id' : suggestion.photo_id,
                'auth_token' : self.user.token,
                'is_public' : 0,
                'is_contact' : 0,
                'is_family' : 0,
                'is_friend' : 0
            }
            
            if geoperms == 1 :
                args['is_public'] = 1
            elif geoperms == 2 :
                args['is_contact'] = 1
            elif geoperms == 3 :
                args['is_friend'] = 1
                args['is_family'] = 1
            elif geoperms == 4 :
                args['is_friend'] = 1                                
            elif geoperms == 5 :
                args['is_family'] = 1                
            else :
                pass

            rsp = self.api_call('flickr.photos.geo.setPerms', args)
    
            if rsp['stat'] != 'ok' :
                msg = 'Failed to set location: %s (%s)' % (rsp['message'], rsp['code'])
                self.log(msg, 'warning')
                pass

        #
        # geo:suggestedby= machine tag and comment-y reward
        # comment but only if the geo perms are public
        #

        if geoperms == 1 and suggestion.suggestor_nsid != self.user.nsid :

            suggested_by = suggestion.suggestor_nsid
            suggestor = User.get_user_by_nsid(suggestion.suggestor_nsid)
                    
            if suggestor and suggestor.path_alias :
                suggested_by = suggestor.path_alias

            tags = "geo:suggestedby=%s" % suggested_by
        
            machinetags_args = {
                'photo_id' : suggestion.photo_id,
                'tags' : tags,
                'auth_token' : self.user.token,
                'check_response' : 1,
                }

            rsp = self.api_call('flickr.photos.addTags', machinetags_args)

            # sudo make me a preference

            # TO DO: this should not be called "rewards" but it's early
            # and I haven't had much coffee....
            
            if self.user.nsid in config.rewards :

                suggested_date = suggestion.created.strftime("%B %d, %Y")
                suggestor_name = suggestor.username
                suggestor_url = 'http://www.flickr.com/photos/%s' % suggestor.nsid

                if suggestor.path_alias != '' :
                    suggestor_url = 'http://www.flickr.com/photos/%s' % suggestor.path_alias
                    
                # Note: don't lookup/display the place name for the WOE ID
                # until it's possible to do corrections on approval.

                nearby_url = "http://www.flickr.com/photos/%s/%s/nearby/?by=everyone&taken=recent&sort=distance&page=1&show=detail" % (self.user.nsid, suggestion.photo_id)
                
                comment = """On %s, <a href="%s">%s</a> suggested <a href="%s">where this photo was taken</a>, and they were right!
                """ % (suggested_date, suggestor_url, suggestor_name, nearby_url)

                method = 'flickr.photos.comments.addComment'
            
                comments_args = {
                    'photo_id' : suggestion.photo_id,
                    'comment_text' : comment,
                    'auth_token' : self.user.token,
                }
                
                rsp = self.api_call(method, comments_args)

                if not rsp :
                    logging.error("Failed to post approval comment")

                # TODO, MAYBE: delete initial suggestion comment here?
                
        #
        # Update (possibly do this before setting tags?)
        #
        
        Suggestion.approve_suggestion(suggestion)
        Suggestion.reject_all_pending_suggestions_for_photo(suggestion.photo_id)

        #
        # HAPPY
        #

        photo_owner = self.user.nsid

        if self.user.path_alias :
            photo_owner = self.user.path_alias
            
        photo_url = "http://www.flickr.com/photos/%s/%s" % (photo_owner, suggestion.photo_id)

        #
        
        out = {'photo_url' : photo_url}            
        return self.api_ok(out)
Example #6
0
    def post(self, uuid):

        is_api = True

        if not self.ensure_config(uuid):
            self.error('invalid_config', is_api)
            return

        if not self.check_logged_in(self.min_perms):
            self.do_flickr_auth(self.min_perms)
            return

        if not self.validate_crumb(self.user, 'method=approve',
                                   self.request.get('crumb')):
            self.error('invalid_perms', is_api)
            return False

        #
        # args/sig validation
        #

        req_args = ('photo_id', 'lat', 'lon', 'acc', 'context', '_s')
        sig_args = ['photo_id', 'lat', 'lon', 'acc', 'context', 'woeid']

        if not self.ensure_required_args(req_args):
            self.error('missing_args', is_api)
            return

        if not self.ensure_valid_args(req_args):
            self.error('invalid_args', is_api)
            return

        if not self.ensure_robot_sig(sig_args, self.request.get('_s')):
            self.error('invalid_sig')
            return

        args = {
            'photo_id': suggestion.photo_id,
            'auth_token': self.user.token,
            'check_response': 1,
        }

        rsp = self.api_call('flickr.photos.getInfo', args)

        if not rsp:
            self.error('invalid_photo')
            return

        if rsp['photo'].has_key('location'):
            Suggestion.reject_all_pending_suggestions_for_photo(
                suggestion.photo_id)
            self.error('already_geotagged')
            return

        mock = self.generate_mock_suggestion()

        if not mock:
            self.error('invalid suggestion')
            return

        suggestion = Suggestion.create(mock)

        #
        # this is all copy/pasted out of API/Approve <-- it should probably
        # go in a "library" but the whole thing gets wrapped up in boring
        # object/globals/self nonsense and the fact that there aren't any
        # in Suggestion.py
        #

        args = {
            'photo_id': suggestion.photo_id,
            'lat': suggestion.latitude,
            'lon': suggestion.longitude,
            'accuracy': suggestion.accuracy,
            'auth_token': self.user.token,
        }

        geo_context = self.request.get('geo_context')

        if geo_context and int(geo_context) != 0:
            args['context'] = geo_context

        rsp = self.api_call('flickr.photos.geo.setLocation', args)

        if not rsp:
            self.error('Failed to set location: Flickr API call failed',
                       is_api)
            return

        if rsp['stat'] != 'ok':
            self.error(
                'Failed to set location: %s (%s)' %
                (rsp['message'], rsp['code']), is_api)
            return

        geoperms = int(self.request.get('geo_perms'))
        default = self.default_geoperms()

        if geoperms != default:

            method = 'flickr.photos.geo.setPerms'

            args = {
                'photo_id': suggestion.photo_id,
                'auth_token': self.user.token,
                'is_public': 0,
                'is_contact': 0,
                'is_family': 0,
                'is_friend': 0
            }

            if geoperms == 1:
                args['is_public'] = 1
            elif geoperms == 2:
                args['is_contact'] = 1
            elif geoperms == 3:
                args['is_friend'] = 1
                args['is_family'] = 1
            elif geoperms == 4:
                args['is_friend'] = 1
            elif geoperms == 5:
                args['is_family'] = 1
            else:
                pass

            rsp = self.api_call('flickr.photos.geo.setPerms', args)

            if rsp['stat'] != 'ok':
                msg = 'Failed to set location: %s (%s)' % (rsp['message'],
                                                           rsp['code'])
                self.log(msg, 'warning')
                pass

        if geoperms == 1 and suggestion.suggestor_nsid != self.user.nsid:

            suggested_by = suggestion.suggestor_nsid

            suggestor = User.get_user_by_nsid(suggestion.suggestor_nsid)

            if suggestor and suggestor.path_alias:
                suggested_by = suggestor.path_alias

            tags = "geo:suggestedby=%s" % suggested_by

            args = {
                'photo_id': suggestion.photo_id,
                'tags': tags,
                'auth_token': self.user.token,
                'check_response': 1,
            }

            rsp = self.api_call('flickr.photos.addTags', args)

            # sudo make me a preference

            if self.user.nsid == 'brooklyn museum':

                suggested_date = suggestion.date_create
                suggestor_name = suggestor.username
                suggestor_url = 'http://www.flickr.com/photos/%s' % suggestor.nsid

                if suggestor.path_alias != '':
                    suggestor_url = 'http://www.flickr.com/photos/%s' % suggestor.path_alias

                # Note: don't lookup/display the place name for the WOE ID
                # until it's possible to do corrections on approval.

                comment = """On %s, <a href="%s">%s</a> suggested where this photo was taken, and they were right!
                """ % (suggested_date, suggestor_url, suggestor_name)

                method = 'flickr.photos.comments.addComment'

                comments_args = {
                    'photo_id': photo_id,
                    'comment_text': comment,
                    'auth_token': self.user.token,
                }

                rsp = self.api_call(method, args)

        #

        Suggestion.approve_suggestion(suggestion)
        Suggestion.reject_all_pending_suggestions_for_photo(
            suggestion.photo_id)

        #

        photo_owner = self.user.nsid

        if self.user.path_alias:
            photo_owner = self.user.path_alias

        photo_url = "http://www.flickr.com/photos/%s/%s" % (
            photo_owner, suggestion.photo_id)

        return self.ok({'photo_url': photo_url})
Example #7
0
    def generate_mock_suggestion(self):

        #
        # Get the photo
        #

        method = 'flickr.photos.getInfo'
        photo_id = self.request.get('photo_id')

        args = {
            'photo_id': photo_id,
            'auth_token': self.user.token,
        }

        rsp = self.proxy_api_call(method, args)

        if not rsp or rsp['stat'] != 'ok':
            self.error('no_photoinfo')
            return

        #
        # Ensure the photo is owned by the logged in user
        #

        if rsp['photo']['owner']['nsid'] != self.user.nsid:
            self.error('invalid_owner')
            return

        #
        # Ensure the photo isn't already geotagged
        #

        if rsp['photo'].has_key('location'):
            self.error('already_geotagged')
            return

        suggestor = User.get_user_by_nsid(self.config['flickr_nsid'])

        #
        # get the WOE ID
        #

        woeid = 0

        args = {
            'lat': self.request.get('lat'),
            'lon': self.request.get('lon'),
            'accuracy': self.request.get('acc'),
        }

        ttl = 60 * 60 * 14

        rsp = self.proxy_api_call('flickr.places.findByLatLon', args, ttl)

        if rsp and rsp.has_key(rsp['places']):
            woeid = rsp['places']['place'][0]['woe_id']

        #
# Create a mock suggestion
#

        suggestion = {
            'photo_id': int(photo_id),
            'owner_id': self.user.nsid,
            'suggestor_id': suggestor.nsid,
            'suggestor_name': suggestor.username,
            'latitude': float(self.request.get('lat')),
            'longitude': float(self.request.get('lon')),
            'accuracy': int(self.request.get('acc')),
            'woeid': woeid,
            'context': int(self.request.get('context')),
            # 'created' : 'datetime'
            # 'updated' : 'datetime'
            'status': 1,
            'comment_id': '',
        }

        return suggestion
Example #8
0
    def run(self):

        required = ('crumb', 'suggestion_id', 'geo_perms', 'geo_context')

        if not self.ensure_args(required):
            return

        if not self.ensure_crumb('method=approve'):
            return

        suggestion_id = self.request.get('suggestion_id')
        suggestion = self.fetch_pending_suggestion(suggestion_id)

        if not suggestion:
            return

        # Here's a potential problem: In order to do this properly
        # we may need to call the Flickr API (6) times and we're
        # doing all of them synchronously there's always the risk
        # that one of them will time out. Some possibilities include
        # doing the machinetag and comment stuff as queued tasks but
        # that probably puts too many eggs in the app engine basket.

        # Required:
        # flickr.photos.getInfo
        # flickr.photos.geo.setLocation

        # Possible:
        # flickr.photos.geo.setPerms
        # flickr.photos.addTags
        # flickr.photos.comments.addComment

        #
        # Check to see if the photo has already been geotagged
        #

        args = {
            'photo_id': suggestion.photo_id,
            'auth_token': self.user.token,
            'check_response': 1,
        }

        rsp = self.api_call('flickr.photos.getInfo', args)

        if not rsp:
            self.api_error(8,
                           'Unable to retrieve photo information from Flickr')
            return

        if rsp['photo'].has_key('location'):
            Suggestion.reject_all_pending_suggestions_for_photo(
                suggestion.photo_id)

            self.api_error(9, 'Photo has already been geotagged')
            return

        #
        # Also, this is all cloned in Robots/Suggestibot <-- it should probably
        # go in a "library" but the whole thing gets wrapped up in boring
        # object/globals/self nonsense and the fact that there aren't any
        # in Suggestion.py
        #

        #
        # Okay! Geotag the f*****g photo!!!
        #

        accuracy = suggestion.accuracy

        if accuracy > 16:
            accuracy = 16

        args = {
            'photo_id': suggestion.photo_id,
            'lat': suggestion.latitude,
            'lon': suggestion.longitude,
            'accuracy': accuracy,
            'auth_token': self.user.token,
        }

        geo_context = self.request.get('geo_context')

        if geo_context and int(geo_context) != 0:
            args['context'] = geo_context

        rsp = self.api_call('flickr.photos.geo.setLocation', args)

        if not rsp:
            self.api_error(10,
                           'Failed to set location: Flickr API call failed')

        if rsp['stat'] != 'ok':
            self.api_error(
                10, 'Failed to set location: %s (%s)' %
                (rsp['message'], rsp['code']))
            return

        #
        # Geo perms (it would be better if you could assign perms in setLocation...)
        #

        geoperms = int(self.request.get('geo_perms'))
        default = self.default_geoperms()

        if geoperms != default:

            method = 'flickr.photos.geo.setPerms'

            args = {
                'photo_id': suggestion.photo_id,
                'auth_token': self.user.token,
                'is_public': 0,
                'is_contact': 0,
                'is_family': 0,
                'is_friend': 0
            }

            if geoperms == 1:
                args['is_public'] = 1
            elif geoperms == 2:
                args['is_contact'] = 1
            elif geoperms == 3:
                args['is_friend'] = 1
                args['is_family'] = 1
            elif geoperms == 4:
                args['is_friend'] = 1
            elif geoperms == 5:
                args['is_family'] = 1
            else:
                pass

            rsp = self.api_call('flickr.photos.geo.setPerms', args)

            if rsp['stat'] != 'ok':
                msg = 'Failed to set location: %s (%s)' % (rsp['message'],
                                                           rsp['code'])
                self.log(msg, 'warning')
                pass

        #
        # geo:suggestedby= machine tag and comment-y reward
        # comment but only if the geo perms are public
        #

        if geoperms == 1 and suggestion.suggestor_nsid != self.user.nsid:

            suggested_by = suggestion.suggestor_nsid
            suggestor = User.get_user_by_nsid(suggestion.suggestor_nsid)

            if suggestor and suggestor.path_alias:
                suggested_by = suggestor.path_alias

            tags = "geo:suggestedby=%s" % suggested_by

            machinetags_args = {
                'photo_id': suggestion.photo_id,
                'tags': tags,
                'auth_token': self.user.token,
                'check_response': 1,
            }

            rsp = self.api_call('flickr.photos.addTags', machinetags_args)

            # sudo make me a preference

            # TO DO: this should not be called "rewards" but it's early
            # and I haven't had much coffee....

            if self.user.nsid in config.rewards:

                suggested_date = suggestion.created.strftime("%B %d, %Y")
                suggestor_name = suggestor.username
                suggestor_url = 'http://www.flickr.com/photos/%s' % suggestor.nsid

                if suggestor.path_alias != '':
                    suggestor_url = 'http://www.flickr.com/photos/%s' % suggestor.path_alias

                # Note: don't lookup/display the place name for the WOE ID
                # until it's possible to do corrections on approval.

                nearby_url = "http://www.flickr.com/photos/%s/%s/nearby/?by=everyone&taken=recent&sort=distance&page=1&show=detail" % (
                    self.user.nsid, suggestion.photo_id)

                comment = """On %s, <a href="%s">%s</a> suggested <a href="%s">where this photo was taken</a>, and they were right!
                """ % (suggested_date, suggestor_url, suggestor_name,
                       nearby_url)

                method = 'flickr.photos.comments.addComment'

                comments_args = {
                    'photo_id': suggestion.photo_id,
                    'comment_text': comment,
                    'auth_token': self.user.token,
                }

                rsp = self.api_call(method, comments_args)

                if not rsp:
                    logging.error("Failed to post approval comment")

                # TODO, MAYBE: delete initial suggestion comment here?

        #
        # Update (possibly do this before setting tags?)
        #

        Suggestion.approve_suggestion(suggestion)
        Suggestion.reject_all_pending_suggestions_for_photo(
            suggestion.photo_id)

        #
        # HAPPY
        #

        photo_owner = self.user.nsid

        if self.user.path_alias:
            photo_owner = self.user.path_alias

        photo_url = "http://www.flickr.com/photos/%s/%s" % (
            photo_owner, suggestion.photo_id)

        #

        out = {'photo_url': photo_url}
        return self.api_ok(out)
Example #9
0
    def post (self, uuid) :

        is_api = True

        if not self.ensure_config(uuid) :
            self.error('invalid_config', is_api)
            return
        
        if not self.check_logged_in(self.min_perms) :
            self.do_flickr_auth(self.min_perms)
            return

        if not self.validate_crumb(self.user, 'method=approve', self.request.get('crumb')) :
            self.error('invalid_perms', is_api)
            return False

        #
        # args/sig validation
        #

        req_args = ('photo_id', 'lat', 'lon', 'acc', 'context', '_s')
        sig_args = ['photo_id', 'lat', 'lon', 'acc', 'context', 'woeid']

        if not self.ensure_required_args(req_args) :
            self.error('missing_args', is_api)
            return

        if not self.ensure_valid_args(req_args) :
            self.error('invalid_args', is_api)
            return

        if not self.ensure_robot_sig(sig_args, self.request.get('_s')) :
            self.error('invalid_sig')
            return    

        args = {
            'photo_id' : suggestion.photo_id,
            'auth_token' : self.user.token,
            'check_response' : 1,
            }

        rsp = self.api_call('flickr.photos.getInfo', args)
        
        if not rsp :
            self.error('invalid_photo')
            return

        if rsp['photo'].has_key('location') :
            Suggestion.reject_all_pending_suggestions_for_photo(suggestion.photo_id)
            self.error('already_geotagged')
            return
        
        mock = self.generate_mock_suggestion()

        if not mock :
            self.error('invalid suggestion')
            return
        
        suggestion = Suggestion.create(mock)

        #
        # this is all copy/pasted out of API/Approve <-- it should probably
        # go in a "library" but the whole thing gets wrapped up in boring
        # object/globals/self nonsense and the fact that there aren't any
        # in Suggestion.py
        #
                    
        args = {'photo_id' : suggestion.photo_id,
                'lat' : suggestion.latitude,
                'lon' : suggestion.longitude,
                'accuracy' : suggestion.accuracy,
                'auth_token' : self.user.token,
                }

        geo_context = self.request.get('geo_context')
        
        if geo_context and int(geo_context) != 0 :
            args['context'] = geo_context
            
        rsp = self.api_call('flickr.photos.geo.setLocation', args)

        if not rsp :
            self.error('Failed to set location: Flickr API call failed', is_api)
            return
        
        if rsp['stat'] != 'ok' :
            self.error('Failed to set location: %s (%s)' % (rsp['message'], rsp['code']), is_api)
            return

        geoperms = int(self.request.get('geo_perms'))
        default = self.default_geoperms()

        if geoperms != default :

            method = 'flickr.photos.geo.setPerms'

            args = {
                'photo_id' : suggestion.photo_id,
                'auth_token' : self.user.token,
                'is_public' : 0,
                'is_contact' : 0,
                'is_family' : 0,
                'is_friend' : 0
            }
            
            if geoperms == 1 :
                args['is_public'] = 1
            elif geoperms == 2 :
                args['is_contact'] = 1
            elif geoperms == 3 :
                args['is_friend'] = 1
                args['is_family'] = 1
            elif geoperms == 4 :
                args['is_friend'] = 1                                
            elif geoperms == 5 :
                args['is_family'] = 1                
            else :
                pass

            rsp = self.api_call('flickr.photos.geo.setPerms', args)
    
            if rsp['stat'] != 'ok' :
                msg = 'Failed to set location: %s (%s)' % (rsp['message'], rsp['code'])
                self.log(msg, 'warning')
                pass
        
        if geoperms == 1 and suggestion.suggestor_nsid != self.user.nsid :

            suggested_by = suggestion.suggestor_nsid

            suggestor = User.get_user_by_nsid(suggestion.suggestor_nsid)
                    
            if suggestor and suggestor.path_alias :
                suggested_by = suggestor.path_alias
            
            tags = "geo:suggestedby=%s" % suggested_by
        
            args = {
                'photo_id' : suggestion.photo_id,
                'tags' : tags,
                'auth_token' : self.user.token,
                'check_response' : 1,
                }
        
            rsp = self.api_call('flickr.photos.addTags', args)

            # sudo make me a preference
            
            if self.user.nsid == 'brooklyn museum' :

                suggested_date = suggestion.date_create
                suggestor_name = suggestor.username
                suggestor_url = 'http://www.flickr.com/photos/%s' % suggestor.nsid

                if suggestor.path_alias != '' :
                    suggestor_url = 'http://www.flickr.com/photos/%s' % suggestor.path_alias
                    
                # Note: don't lookup/display the place name for the WOE ID
                # until it's possible to do corrections on approval.
                
                comment = """On %s, <a href="%s">%s</a> suggested where this photo was taken, and they were right!
                """ % (suggested_date, suggestor_url, suggestor_name)

                method = 'flickr.photos.comments.addComment'
            
                comments_args = {
                    'photo_id' : photo_id,
                    'comment_text' : comment,
                    'auth_token' : self.user.token,
                }
                
                rsp = self.api_call(method, args)

        #
        
        Suggestion.approve_suggestion(suggestion)
        Suggestion.reject_all_pending_suggestions_for_photo(suggestion.photo_id)
        
        #
        
        photo_owner = self.user.nsid

        if self.user.path_alias :
            photo_owner = self.user.path_alias
            
        photo_url = "http://www.flickr.com/photos/%s/%s" % (photo_owner, suggestion.photo_id)

        return self.ok({'photo_url' : photo_url})
Example #10
0
    def generate_mock_suggestion (self) :

        #
        # Get the photo
        #

        method = 'flickr.photos.getInfo'
        photo_id = self.request.get('photo_id')        
        
        args = {
            'photo_id' : photo_id,
            'auth_token' : self.user.token,
            }
        
        rsp = self.proxy_api_call(method, args)

        if not rsp or rsp['stat'] != 'ok' :
            self.error('no_photoinfo')
            return

        #
        # Ensure the photo is owned by the logged in user
        #
        
        if rsp['photo']['owner']['nsid'] != self.user.nsid :
            self.error('invalid_owner')
            return

        #
        # Ensure the photo isn't already geotagged
        #

        if rsp['photo'].has_key('location') :
            self.error('already_geotagged')
            return

        suggestor = User.get_user_by_nsid(self.config['flickr_nsid'])
        
        #
        # get the WOE ID
        #

        woeid = 0    

        args = {
            'lat' : self.request.get('lat'),
            'lon' : self.request.get('lon'),
            'accuracy' : self.request.get('acc'),            
        }

        ttl = 60 * 60 * 14
        
        rsp = self.proxy_api_call('flickr.places.findByLatLon', args, ttl)

        if rsp and rsp.has_key(rsp['places']) :
            woeid = rsp['places']['place'][0]['woe_id']

        #
	# Create a mock suggestion
        #
            
        suggestion = {
            'photo_id' : int(photo_id),
            'owner_id' : self.user.nsid,
            'suggestor_id' : suggestor.nsid,
            'suggestor_name' : suggestor.username,
            'latitude' : float(self.request.get('lat')),
            'longitude' : float(self.request.get('lon')),
            'accuracy' : int(self.request.get('acc')),  
            'woeid' : woeid,
            'context' : int(self.request.get('context')),
            # 'created' : 'datetime'
            # 'updated' : 'datetime'
            'status' : 1,
            'comment_id' : '',
            }

        return suggestion