예제 #1
0
파일: utils.py 프로젝트: dhou/xiaonei-apps
 except:
     logging.error('Unknown error while calling users.getinfo')
     exception = sys.exc_info()[0]
     logging.exception(exception)
     raise
 else:
     birthday = user_info['birthday']
     if birthday:
         year, month, day = birthday.split('-')
         logging.debug('got year: %s, month: %s, day: %s' % (year, month, day))
 try:
     user, created = XnUser.get_or_insert_by_uid(xn.uid, 
                                                 username=user_info['name'], 
                                                 sex=int(user_info['sex']),
                                                 pic_url=user_info['headurl'], 
                                                 birth_year=year,
                                                 birth_month=month,
                                                 birth_day=day,
                                                 home_country=user_info['hometown_location'].get('country',''),
                                                 home_province=user_info['hometown_location'].get('province',''),
                                                 home_city=user_info['hometown_location'].get('city',''))
 except BadValueError, e:
     logging.error('Failed to save user data: %s' % e)
     raise
 except:
     logging.error("Unexpected error while creating user")
     exception = sys.exc_info()[0]
     logging.exception(exception)
     raise
 else:
     logging.debug('got user[created: %s]: %s' % (created,user.username))
     friends = friends_get(xn)
예제 #2
0
파일: views.py 프로젝트: dhou/xiaonei-apps
     logging.debug('no user found in db, getting userinfo again')
     try:
         user_info = xn.users.getInfo(uids=[xn.uid], fields=['name'])[0]
         logging.debug('got userinfo: %s' % user_info)
     except XiaoneiError, e:
         logging.error('Failed calling users.getinfo')
         logging.error(e)
         raise
     except:
         logging.error('Unknown error while calling users.getinfo')
         exception = sys.exc_info()[0]
         logging.exception(exception)
         raise
         
     try:
         user, created = XnUser.get_or_insert_by_uid(xn.uid, username=user_info['name'])
     except BadValueError, e:
         logging.error('Failed to save user data: %s' % e)
         raise
     except:
         logging.error("Unexpected error")
         raise
     else:
         logging.debug('got user[created: %s]: %s' % (created,user.username))
 else:
     logging.debug('user exists in db')
     try:
         if user.friends:
             logging.debug('purge remaining friends data')
             user.friends = None
     except: