コード例 #1
0
def get_single_user_photo(user: User) -> bytearray:
    photos: UserProfilePhotos = user.get_profile_photos()
    result: bytearray = bytearray()

    if len(photos.photos) > 0:
        if len(photos.photos[0]) == 0:
            return bytearray(b"\x00")
        photo: PhotoSize = sorted(
            photos.photos[0], key=itemgetter("width"), reverse=True
        )[0]
        file_photo: File = photo.get_file()
        result = file_photo.download_as_bytearray()

    return result
コード例 #2
0
ファイル: bot.py プロジェクト: luiz-meireles/citadorbot
def get_user_pic(user: User):
    name = user.first_name + " " + user.last_name if user.last_name else user.first_name
    name = name.split(" ")
    formatted_name = format_name(name)

    photos = user.get_profile_photos().photos

    if not photos or not photos[0]:
        return formatted_name

    # first photo, last version (better quality)
    photo_size = photos[0][-1]
    photo = photo_size.get_file().download_as_bytearray()

    return (photo, (photo_size.width, photo_size.height), formatted_name)
コード例 #3
0
ファイル: bot.py プロジェクト: wanderdasouza/citadorbot
def get_user_pic(user: User):
    photos = user.get_profile_photos().photos

    if not photos or not photos[0]:
        return None

    # first photo, last version (better quality)
    photo_size = photos[0][-1]
    photo = photo_size.get_file().download_as_bytearray()

    name = user.first_name + " " + user.last_name if user.last_name else user.first_name
    name = name.split(" ")
    formated_name = name[1].upper() + ", " + name[0] if len(name) > 1 else name[0]

    return (photo, (photo_size.width, photo_size.height), formated_name)