Тема: help me please
Показать сообщение отдельно

  #4  
Старый 11.09.2023, 22:29
MrDorlik
Постоянный
Регистрация: 20.02.2022
Сообщений: 946
С нами: 2226127

Репутация: 68


По умолчанию

Цитата:
Сообщение от Vladius  

Python:





Код:
def
send_post_to_telegram
(
bot_token
,
chat_id
,
post
)
:
bot
=
Bot
(
token
=
bot_token
)
text
=
post
[
'text'
]
attachments
=
post
.
get
(
'attachments'
,
[
]
)
message
=
f"New post from VK:\n\n{text}"
for
attachment
in
attachments
:
if
attachment
[
'type'
]
==
'photo'
:
photo
=
attachment
[
'photo'
]
photo_url
=
sorted
(
photo
[
'sizes'
]
,
key
=
lambda
x
:
x
[
'width'
]
)
[
-
1
]
[
'url'
]
bot
.
send_photo
(
chat_id
=
chat_id
,
photo
=
photo_url
,
caption
=
message
)
elif
attachment
[
'type'
]
==
'video'
:
video
=
attachment
[
'video'
]
video_url
=
video
[
'player'
]
bot
.
send_video
(
chat_id
=
chat_id
,
video
=
video_url
,
caption
=
message
)

Python:





Код:
async
def
send_post_to_telegram
(
bot_token
,
chat_id
,
post
)
:
bot
=
Bot
(
token
=
bot_token
)
text
=
post
[
'text'
]
attachments
=
post
.
get
(
'attachments'
,
[
]
)
message
=
f"New post from VK:\n\n{text}"
for
attachment
in
attachments
:
if
attachment
[
'type'
]
==
'photo'
:
photo
=
attachment
[
'photo'
]
photo_url
=
sorted
(
photo
[
'sizes'
]
,
key
=
lambda
x
:
x
[
'width'
]
)
[
-
1
]
[
'url'
]
await
bot
.
send_photo
(
chat_id
=
chat_id
,
photo
=
photo_url
,
caption
=
message
)
elif
attachment
[
'type'
]
==
'video'
:
video
=
attachment
[
'video'
]
video_url
=
video
[
'player'
]
await
bot
.
send_video
(
chat_id
=
chat_id
,
video
=
video_url
,
caption
=
message
)


async def и await, больше ниче
 
Ответить с цитированием