M
M
Maria Hoffman2022-01-20 19:09:36
Parsing
Maria Hoffman, 2022-01-20 19:09:36

Asynchrony when parsing instagram accounts for bots in telegrams, how to do it?

There is a bot that, using the library for instagram, accepts an account and parses subscriber accounts and checks them for entry into business accounts and sees if there is an avatar. My task is to speed up parsing and at the same time bypass Instagram blocking for suspicious actions. Is it possible to make the looping process asynchronous? I write on pyTelegramBotAPI, but it's not a problem to rewrite on aiogram. When checking an account with 50-100 subscribers, there are no problems with time, but with a larger load, the bot can not cope

from telebot import *
import instaloader
import time
import config

bot = telebot.TeleBot(config.token)

@bot.message_handler(commands=['start'])  # command handler for /start
def welcome(message):
    bot.send_message(message.chat.id,
                     'Добро пожаловать!\nОтправь мне никнейм Instagram—аккаунта, и я пришлю тебе его анализ'
                     '\nВнимание! Действует ограничение по времени (аккаунты можно присылать раз в 10 минут)')
@bot.message_handler(content_types=['text'])
def search(message):
    try:
        msg = message.text
        nickname = msg
        bot.send_message(message.chat.id, f'Анализ пользователя {nickname}'
                         f'\nПроцесс может занять некоторое время, пожалуйста, подождите')

        L = instaloader.Instaloader()
        L.login(config.nick, config.password)  # (login)

        # NICK FROM USER
        Profile = instaloader.Profile.from_username(L.context, nickname)

        # Create list of followers
        followers_list = []
        for followers in Profile.get_followers():
            followers_list.append(followers.username)

        bot.send_message(message.chat.id, f'Пользователь {nickname}'
                                          f'\nКоличество подписчиков: {len(followers_list)}')

        # Checking followers without pic
        followers_pic = []
        followers_no_pic = []
        for acc in followers_list:
            account = instaloader.Profile.from_username(L.context, acc)
            account.profile_pic_url
            followers_pic.append(account.profile_pic_url)
            # time.sleep(0.1)
        for no_pic in followers_pic:
            if "https://instagram" in no_pic:
                followers_no_pic.append(no_pic)
            else:
                pass
            # time.sleep(0.1)
        bot.send_message(message.chat.id, f'\nИз них без аватарок: {len(followers_no_pic)}')

        # Checking the list of subscribers on existing business accounts
        check_business = []
        for accounts in followers_list:
            business = instaloader.Profile.from_username(L.context, accounts)
            if business.is_business_account is True:
                check_business.append(business.is_business_account)
            else:
                pass


        bot.send_message(message.chat.id, f'\nБизнес-аккаунтов: {len(check_business)}')
        time.sleep(600)


    except:
        bot.send_message(message.chat.id, 'Не понял! Попробуй еще раз')


bot.polling(none_stop=True, interval=0)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2022-01-20
@bacon

My task is to speed up parsing and at the same time bypass Instagram blocking for suspicious actions.
Asynchrony will help speed up the parsing process, or rather, not even the parsing itself, but minimizes the downtime when waiting for network responses, but will not help in any way "bypass Instagram blocking"

P
Puma Thailand, 2022-01-21
@opium

I didn’t quite understand why there is asynchrony here, just make multithreading, add a proxy, and if you need to, log in with some kind of ak in the stream to reduce bans and increase limits

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question