 |

11.09.2023, 22:10
|
|
Участник форума
Регистрация: 08.11.2021
Сообщений: 131
С нами:
2376214
Репутация:
18
|
|
я вроде понимаю, но вроде и нет
|
|
|

11.09.2023, 22:15
|
|
Познавший АНТИЧАТ
Регистрация: 31.07.2021
Сообщений: 1,784
С нами:
2520168
Репутация:
133
|
|
Скинь код текстом а не скрином, так вероятность помощи будет выше
|
|
|

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
)
|
|
|

11.09.2023, 22:29
|
|
Постоянный
Регистрация: 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, больше ниче
|
|
|

11.09.2023, 22:46
|
|
Участник форума
Регистрация: 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
)
|
|
|

12.09.2023, 13:56
|
|
Новичок
Регистрация: 07.06.2023
Сообщений: 0
С нами:
1546818
Репутация:
0
|
|
Сообщение от Vladius
помоги с этим тогда еще пожалуйста)
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.
|
|
|
|
 |
|
Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
|
|
|
|