Просмотр полной версии : help me please
vladsharik
11.09.2023, 22:10
https://forum.antichat.xyz/attachments/28376806/img_c9613ee60c.png
https://forum.antichat.xyz/attachments/28376806/img_a0aca57b5f.png
я вроде понимаю, но вроде и нет
Скинь код текстом а не скрином, так вероятность помощи будет выше
vladsharik
11.09.2023, 22:16
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
)
MrDorlik
11.09.2023, 22:29
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, больше ниче
vladsharik
11.09.2023, 22:46
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
)
Python_newbie
12.09.2023, 13:56
помоги с этим тогда еще пожалуйста)
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
)
Перед 'send_post_to_telegram' нужен await, если функция get_new_posts ассинхронная то так-же нужен await.
vBulletin® v3.8.14, Copyright ©2000-2026, vBulletin Solutions, Inc. Перевод: zCarot