def get_friends_tree(api): log.msg("1st call in thread") profiles = yield get_profile_details(api) for profile in profiles: response = get_response(api.friends.get(user_id=profile.profile_id)) profiles = yield get_profile_details(api, *response) returnValue(len(profiles))
def get_profile_details(api, *args): log.msg("2d call in thread") ids = ",".join(map(str, args)) rv = get_response(api.users.get(user_ids=ids)) profiles = [] for profile_data in rv: puid = int(profile_data['uid']) profile = yield Profile.find_one_async(profile_id=puid) if profile is None: profile = yield Profile.create_async(profile_id=puid) yield Profile.update_matched_async( {'id': profile.id}, { 'first_name': profile_data['first_name'], 'last_name': profile_data['last_name'] }) profiles.append(profile) returnValue(profiles)