total_transfer_price = 0 total_uniq_count = 0 total_upgradable_price = 0 total_upgradable_count = 0 convertable_count = 0 convertable_price = 0 for gift in gifts: try: if gift.can_be_transferred: if not gift.transfer_star_count: total_transfer_price += 0 else: total_transfer_price += gift.transfer_star_count total_uniq_count += 1 if gift.can_be_upgraded: total_upgradable_price += gift.prepaid_upgrade_star_count total_upgradable_count += 1 if gift.convert_star_count: now = datetime.now() send_date = datetime.fromtimestamp(gift.send_date) delta = now - send_date days_ago = delta.days if days_ago<7: convertable_price += gift.convert_star_count convertable_count += 1 except AttributeError as e: continue Python total_transfer_price = 0 total_uniq_count = 0 total_upgradable_price = 0 total_upgradable_count = 0 convertable_count = 0 convertable_price = 0 for gift in gifts: try: if gift.can_be_transferred: if not gift.transfer_star_count: total_transfer_price += 0 else: total_transfer_price += gift.transfer_star_count total_uniq_count += 1 if gift.can_be_upgraded: total_upgradable_price += gift.prepaid_upgrade_star_count total_upgradable_count += 1 if gift.convert_star_count: now = datetime.now() send_date = datetime.fromtimestamp(gift.send_date) delta = now - send_date days_ago = delta.days if days_ago<7: convertable_price += gift.convert_star_count convertable_count += 1 except AttributeError as e: continue if gift.convert_star_count не выполняется, а когда ставлю его вначале - выполняется, но не выполняются другие. че за хрень ребята? как фикс?
Y4sperMaglot, c = await bot(GetBusinessAccountGifts(business_connection_id=bus_conn)) gifts = c.gifts for gift in gifts: Код c = await bot(GetBusinessAccountGifts(business_connection_id=bus_conn)) gifts = c.gifts for gift in gifts:
Hollywood, крч вот тут смотри https://core.telegram.org/bots/api#ownedgift, подарки разных типов есть бля и у каждого там поля разные, смотри какие поля у каждого и делай ифы
Hollywood, как раз вот эти OwnedGiftRegular, OwnedGiftUnique и тд из эксепшына твоего, всё там есть в документации
Hollywood, Переписал тебе в более адекватный вид, должно норм работать owned_gifts = await bot(GetBusinessAccountGifts(business_connection_id="")) total_transfer_price = 0 total_uniq_count = 0 total_upgradable_price = 0 total_upgradable_count = 0 convertable_count = 0 convertable_price = 0 for gift in owned_gifts.gifts: if isinstance(gift, OwnedGiftRegular): if gift.prepaid_upgrade_star_count: total_upgradable_price += gift.prepaid_upgrade_star_count total_upgradable_count += 1 if gift.convert_star_count and (datetime.now() - datetime.fromtimestamp(gift.send_date)).days < 7: convertable_price += gift.convert_star_count convertable_count += 1 elif isinstance(gift, OwnedGiftUnique): if gift.transfer_star_count: total_transfer_price += gift.transfer_star_count total_uniq_count += 1 Python owned_gifts = await bot(GetBusinessAccountGifts(business_connection_id="")) total_transfer_price = 0 total_uniq_count = 0 total_upgradable_price = 0 total_upgradable_count = 0 convertable_count = 0 convertable_price = 0 for gift in owned_gifts.gifts: if isinstance(gift, OwnedGiftRegular): if gift.prepaid_upgrade_star_count: total_upgradable_price += gift.prepaid_upgrade_star_count total_upgradable_count += 1 if gift.convert_star_count and (datetime.now() - datetime.fromtimestamp(gift.send_date)).days < 7: convertable_price += gift.convert_star_count convertable_count += 1 elif isinstance(gift, OwnedGiftUnique): if gift.transfer_star_count: total_transfer_price += gift.transfer_star_count total_uniq_count += 1
Hollywood, проверка на тип подарка добавилась бро, просто у одного есть can_be_upgraded, а у другого нет, вот и не работало у тебя