Answer the question
In order to leave comments, you need to log in
How to send the user news from the VK group (parsing) when pressing the Inline button?
Python newbie. How to make the news from the VK group sent to the user when the inline button is pressed?
I need the parser to find the keyword (I chose the wall_search method), then send the post record with the keyword to the user when he clicks on the button. The parser should pass text and, if possible, a picture. How to do this?
If you run the parser separately from the bot, then the VK group is parsed perfectly through the debugger.
How to shove a parser into a bot?
Here is the code, please help.
import logging
import config
import requests
from aiogram import Bot, Dispatcher, executor, types
logging.basicConfig(level=logging.INFO)
bot = Bot(token=config.API_TOKEN)
dp = Dispatcher(bot)
@dp.message_handler(commands=['start'])
async def welcome(message):
sti = open("img/what.webp", "rb")
await bot.send_sticker(message.chat.id, sti)
await bot.send_message(message.chat.id, "Привет, меня зовут ПРК-БОТ, я создан для сбора информации с сайта колледжа!")
await bot.send_message(message.chat.id, "Чтобы начать тыкай '/menu'.")
@dp.message_handler(commands=['menu'])
async def main_menu(message):
parser = types.InlineKeyboardMarkup()
button1 = types.InlineKeyboardButton(text='Новости', callback_data='news')
parser.add(button1)
await bot.send_message(message.chat.id, 'Ты перешел в меню! Теперь нажми на любую из кнопок, чтобы найти информацию!', reply_markup=menu)
@dp.callback_query_handler(lambda call: True)
async def parser_vk(call):
if call.data == 'news':
token = "token...."
version = "5.92"
domain = "perm_college_radio"
dop = 20
query = "Внимание"
offset = 0
all_posts = []
while offset < 100:
otvet = requests.get('https://api.vk.com/method/wall.search',
params={
"access_token": token,
"v": version,
"domain": domain,
"count": dop,
'query': query,
'offset': offset
}
)
data = otvet.json()['response']['items']
offset += 20
all_posts.extend(data)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question