
11.09.2023, 22:16
|
|
Участник форума
Регистрация: 08.11.2021
Сообщений: 131
С нами:
2376214
Репутация:
18
|
|
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
)
|
|
|