help me please

vladsharik

Участник
Автор темы
132
19
1694455572464.png

1694455838559.png

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

vladsharik

Участник
Автор темы
132
19
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

Известный
977
392
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

Участник
Автор темы
132
19
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
6
помоги с этим тогда еще пожалуйста)
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.