Ejemplo n.º 1
0
 def get_user_details(self, response):
     """Return user details from Github account"""
     data = {
         USERNAME: response.get('login'),
         'email': response.get('email') or '',
         'fullname': response['name'],
         'last_name': '',
         'url': response.get('blog', ''),
         'description': response.get('bio', ''),
         'picture_url': response.get('avatar_url', '')        
     }
     
     try:
         data['first_name'], data['last_name'] = response['name'].split(' ', 1)
     except:
         data['first_name'] = response.get('name') or 'Annon'
         
     try:
         location = response.get('location', '')
         if location:
             data['location'], _ = Location.create(location)
     except:
         logging.exception('Problem finding location') 
     
     return data
Ejemplo n.º 2
0
    def get_user_details(self, response):
        """Return user details from Github account"""
        data = {
            'username': response.get('login'),
            'email': response.get('email') or '',
            'fullname': response.get('name', 'Secret Agent'),
            'last_name': '',
            'url': response.get('blog', ''),
            'description': response.get('bio', ''),
            'picture_url': response.get('avatar_url', '')
        }

        try:
            names = data['fullname'].split(' ')
            data['first_name'], data['last_name'] = names[0], names[-1]
        except:
            data['first_name'] = data['fullname']

        try:
            location = response.get('location', '')
            if location:
                data['location'], _ = Location.create(location)
        except:
            logging.exception('Problem finding location')

        return data
Ejemplo n.º 3
0
    def handle(self, *args, **options):
        commit = options['commit']
        empty = 0
        fine = 0
        fixable = 0
        bad = []
        for location in Location.objects.all():
            user_count = User.objects.filter(location=location).count()
            if not user_count:
                logging.info("Empty location: %s", location)
                if commit:
                    location.delete()
                    logging.info('Deleted')
                empty += 1
                continue
            l = check_location(location.name)
            if l == location.name:
                logging.info('Location fine: %s', location)
                fine += 1
                continue

            if not commit:
                if l:
                    fixable += 1
                else:
                    bad.append((location, user_count))
                continue
            elif l is not None:
                new_loc = Location.create(l)
                User.objects.filter(location=location).update(location=new_loc)
                user_count = User.objects.filter(location=location).count()
                if not user_count:
                    logging.error("missed users!")
                else:
                    location.delete()
            elif l is None:
                logging.info('Bad location: %s', location)
                location.approved = False
                location.save()

        if not commit:
            [logging.error('Bad Loc: %s, count: %s', l, c) for l, c in bad]
            logging.info('Empty: %s, Fine: %s, fixable: %s',
                         empty, fine, fixable)
            logging.info('Add --commit to fix locations')
Ejemplo n.º 4
0
    def handle(self, *args, **options):
        commit = options['commit']
        empty = 0
        fine = 0
        fixable = 0
        bad = []
        for location in Location.objects.all():
            user_count = User.objects.filter(location=location).count()
            if not user_count:
                logging.info("Empty location: %s", location)
                if commit:
                    location.delete()
                    logging.info('Deleted')
                empty += 1
                continue
            l = check_location(location.name)
            if l == location.name:
                logging.info('Location fine: %s', location)
                fine += 1
                continue

            if not commit:
                if l:
                    fixable += 1
                else:
                    bad.append((location, user_count))
                continue
            elif l is not None:
                new_loc = Location.create(l)
                User.objects.filter(location=location).update(location=new_loc)
                user_count = User.objects.filter(location=location).count()
                if not user_count:
                    logging.error("missed users!")
                else:
                    location.delete()
            elif l is None:
                logging.info('Bad location: %s', location)
                location.approved = False
                location.save()

        if not commit:
            [logging.error('Bad Loc: %s, count: %s', l, c) for l, c in bad]
            logging.info('Empty: %s, Fine: %s, fixable: %s', empty, fine,
                         fixable)
            logging.info('Add --commit to fix locations')
Ejemplo n.º 5
0
 def get_user_details(self, response):
     """Return user details from Twitter account"""
     data = {
         USERNAME: response['screen_name'],
         'email': '',  # not supplied
         'fullname': response['name'],
         'last_name': '',
         'url': response.get('url', ''),
         'description': response.get('description', ''),
         'picture_url': response.get('profile_image_url', '')        
     }
     try:
         data['first_name'], data['last_name'] = response['name'].split(' ', 1)
     except:
         data['first_name'] = response['name']
     try:
         location = response.get('location', '')
         if location:
             data['location'], _ = Location.create(location)
     except:
         logging.exception('Problem finding location') 
     return data