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

  #5  
Старый 11.09.2023, 22:46
vladsharik
Участник форума
Регистрация: 08.11.2021
Сообщений: 131
С нами: 2376214

Репутация: 18
По умолчанию

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

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, больше ниче
помоги с этим тогда еще пожалуйста)

Python:





Код:
while
True
:
new_posts
=
get_new_posts
(
access_token
,
group_id
,
last_post_id
)
if
new_posts
:
last_post_id
=
new_posts
[
0
]
[
'id'
]
for
post
in
new_posts
:
send_post_to_telegram
(
bot_token
,
chat_id
,
post
)
time
.
sleep
(
60
)
 
Ответить с цитированием