ANTICHAT

ANTICHAT (https://forum.antichat.xyz/index.php)
-   Общие вопросы программирования (https://forum.antichat.xyz/forumdisplay.php?f=206)
-   -   help me please (https://forum.antichat.xyz/showthread.php?t=1489022)

vladsharik 11.09.2023 22:10

https://forum.antichat.xyz/attachmen...c9613ee60c.png

https://forum.antichat.xyz/attachmen...a0aca57b5f.png

я вроде понимаю, но вроде и нет

kjor32 11.09.2023 22:15

Скинь код текстом а не скрином, так вероятность помощи будет выше

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

Цитата:

Сообщение от 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, больше ниче

vladsharik 11.09.2023 22:46

Цитата:

Сообщение от 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
)


Python_newbie 12.09.2023 13:56

Цитата:

Сообщение от 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.


Время: 23:35