def get_user_info(access_token): url = common.create_method_url('users.get', access_token, fields="photo_200_orig") res = common.make_method_request(url)[0] user_name = res['first_name'] + ' ' + res['last_name'] profile_photo_src = res['photo_200_orig'] return dict(user_name=user_name, profile_photo_src=profile_photo_src)
def retrieve_albums(access_token, album_ids): albums = dict.fromkeys(album_ids, None) url = common.create_method_url(GET_ALBUMS, access_token, album_ids=','.join(map(str, album_ids))) json = common.make_method_request(url) items = json['items'] for item in items: album = Album(int(item['id']), item['title']) albums[album.uid] = album return albums
def retrieve_audio_albums(access_token): albums = {} offset = 0 while True: url = common.create_method_url(GET_ALBUMS, access_token, count=MAX_AUDIO_TO_RETURN, offset=offset) json = common.make_method_request(url) items = json['items'] for item in items: album = AudioAlbum(int(item['id']), str(item['title'])) albums[album.uid] = album offset += len(json['items']) if int(json['count']) - offset == 0: break return albums
def get_all_audio(access_token): result = [] offset = 0 while True: url = common.create_method_url(GET_AUDIO, access_token, count=MAX_AUDIO_TO_RETURN, offset=offset) json = common.make_method_request(url) parse_audio(json['items'], result.append) offset += len(json['items']) if int(json['count']) - offset == 0: break albums = retrieve_audio_albums(access_token) # inject albums into audio objects for audio in result: if audio.album_id != 0: audio.album = albums[audio.album_id] return result[:10]
def get_all_photos(access_token): result = [] offset = 0 while True: url = common.create_method_url(GET_ALL, access_token, count=MAX_PHOTOS_TO_RETURN, offset=offset) json = common.make_method_request(url) parse_photos(json['items'], result.append) offset += len(json['items']) if int(json['count']) - offset == 0: break # retrieve albums album_ids = set([photo.album_id for photo in result]) albums = retrieve_albums(access_token, album_ids) # inject albums into photo objects for photo in result: photo.album = albums[photo.album_id] return result
def get_audio_count(access_token, user_id): url = common.create_method_url(GET_AUDIO_COUNT, access_token, owner_id=user_id) res = common.make_request(url) return int(res['response'])
def get_all_photos_count(access_token): url = common.create_method_url(GET_ALL, access_token) res = common.make_method_request(url) return int(res['count'])
def get_photo_albums_count(access_token): url = common.create_method_url(GET_ALBUMS_COUNT, access_token) res = common.make_request(url) return int(res['response'])