Beispiel #1
0
    def get_myspace_viewer_info(self, user_id):
        viewer_info = None
        friends_controller = Friends_controller()
        profile = friends_controller.get_profile_full(user_id)
        if profile:
            logging.info('myspace profile full: %s' % profile)
        profile = friends_controller.get_profile_extended(user_id)
        if profile:
            logging.info('myspace profile ex: %s' % profile)
        profile = friends_controller.get_profile_basic(user_id)
        if profile:
            logging.info('myspace profile basic: %s' % profile)

            viewer_info = {}
            viewer_info['container_user_id'] = user_id
            viewer_info['domain'] = 'myspace.com'
            viewer_info['display_name'] = re.sub(r'[\'\"<>`]', ' ',
                                                 profile['name'])
            viewer_info['profile_url'] = re.sub(r'[\'\"<>`]', ' ',
                                                profile['webUri'])
            viewer_info['profile_image_url'] = re.sub(r'[\'\"<>`]', ' ',
                                                      profile['image'])
        else:
            logging.warn('no myspace profile found for user id %s' % user_id)
        return viewer_info
def update_friends(request, caller_context, container_user):
    
    response = { 'success' : False,
                'message' : 'unknown error'}
    if request.method != "POST":
        response.message ='only POST method is supported'
    else:    
        friends_controller = Friends_controller()
        friends_json = request.raw_post_data
        logging.debug('friends json from update_friends: %s' % friends_json)
        decoder = simplejson.JSONDecoder()
        friends = decoder.decode(friends_json)
        try:
            pyramidController = PyramidController()
            saved, failed = friends_controller.save_container_friends(container_user, friends)
            friend_pyramid_ids = pyramidController.get_friend_pyramid_ids(container_user.character, True)
            response['success'] = True
            response['message'] = 'friend list updated - %d saved, %d failed to save' % (saved, failed) 
            response['friendPyramidCount'] = len(friend_pyramid_ids)
        except Exception, e:
            logging.warn('failed to save friends')
            logging.warn('friends json: %s' % friends_json)
            logging.exception(e)
            response['success'] = False
            response['message'] = 'error saving friends'
def main(request, caller_context, container_user, page=1):
    
    pyramidController = PyramidController()
    chamberController = ChamberController()
    characterController = CharacterController()
    
    current_time = datetime.utcnow() - timedelta(hours = 7) #show Pac time to see if this page gets cached

    if not container_user:
        #user isn't logged in, show some open pyramids
        pyramid_ids = pyramidController.find_open_pyramid_ids(None, 1000)
        if len(pyramid_ids) < 10: # if there are fewer than 10 open pyramids, create one 
            pyramid = pyramidController.create_new_pyramid(4, 3, 100) # 4 total levels, fill 3 levels, $100 price
            pyramid_ids.append(pyramid.key().id())
            logging.debug('created new pyramid: ' + pyramid.to_xml())
        if pyramid_ids:
            pyramid_display, paginator, pyramid_page = get_paged_pyramids(caller_context.config, pyramid_ids, container_user)
        group = 'open'
        return render_to_response('_main.html', locals())

    if caller_context.platform == 'myspace_iframe':
        logging.debug('getting friends from container')
        friends_controller = Friends_controller()
        viewer_friends = friends_controller.refresh_container_friends(container_user)
        encoder = simplejson.JSONEncoder()
        viewer_friends_json = encoder.encode(viewer_friends)

    pyramid_ids = None
    if container_user.character:
        status_bar_dict = characterController.get_status_bar_dict(caller_context.config, container_user.character)
        pyramid_ids = pyramidController.get_character_pyramid_ids(container_user.character, True)
        if pyramid_ids:
            pyramid_display, paginator, pyramid_page = get_paged_pyramids(caller_context.config, pyramid_ids, container_user)
            group = 'joined'
            return render_to_response('_main.html', locals())

    # do this here?  refresh friends?
    #saved, failed = friends_controller.save_container_friends(container_user, viewer_friends)
    #friend_pyramid_ids = pyramidController.get_friend_pyramid_ids(container_user.character, True)

    pyramid_ids = pyramidController.find_open_pyramid_ids(None, 200)
    if pyramid_ids:
        pyramid_display, paginator, pyramid_page = get_paged_pyramids(caller_context.config, pyramid_ids, container_user)
    group = 'open'
    return render_to_response('_main.html', locals())
 def get_myspace_viewer_info(self, user_id):
     viewer_info = None
     friends_controller = Friends_controller()
     profile = friends_controller.get_profile_full(user_id)
     if profile:
         logging.info('myspace profile full: %s' % profile)
     profile = friends_controller.get_profile_extended(user_id)
     if profile:
         logging.info('myspace profile ex: %s' % profile)
     profile = friends_controller.get_profile_basic(user_id)
     if profile:
         logging.info('myspace profile basic: %s' % profile)
         
         viewer_info = {}
         viewer_info['container_user_id'] = user_id
         viewer_info['domain'] = 'myspace.com'
         viewer_info['display_name'] = re.sub(r'[\'\"<>`]', ' ', profile['name'])
         viewer_info['profile_url'] = re.sub(r'[\'\"<>`]', ' ', profile['webUri'])
         viewer_info['profile_image_url'] = re.sub(r'[\'\"<>`]', ' ', profile['image'])
     else:
         logging.warn('no myspace profile found for user id %s' % user_id)
     return viewer_info