Telegram-InstaPy-Scheduling icon indicating copy to clipboard operation
Telegram-InstaPy-Scheduling copied to clipboard

LogNow get live logs in Action

Open HCWcoder opened this issue 6 years ago • 2 comments

Thanks to @Tkd-Alex for helping and making this happen.

I would like to share this Function that you can have Live logs sent to your Telegram chat.

Add this Function :

def lognow(bot, update, args):
    if str(update.message.chat_id) in allowed_id:
            message1 = ""
            messagecounter = int( args[1] )
            time.sleep(2)
            for x in range(messagecounter):
                usernames = [ a['username'].lower() for a in users ]
                if not args[0].lower() in usernames:
                    update.message.reply_text("Sorry, username <b>{}</b> is not saved.".format(args[0]), parse_mode='HTML')
                    return
                logsline = 1
                with open('{}/logs/{}/general.log'.format(settings['instapy_folder'], args[0].lower()), "r") as f:
                    lines = f.readlines()
                lines = lines[-(logsline+20):] # Prevent empty lines
                message = '\n'.join(x for x in lines)
                message = clear_lines( '\n'.join(x for x in lines), username=args[0].lower() )
                lines = message.split('\n')[-logsline:]
                message = '\n'.join(x for x in lines)
                if message1 != message:
                    update.message.reply_text(message, parse_mode='HTML')
                    message1 = message
                    time.sleep(2)
                else:
                    time.sleep(4)

ADD dp.add_handler(CommandHandler("lognow", lognow, pass_args=True)) AFTER if __name__ == '__main__':

Usage /lognow username number

Number is the number of logs you wish to get

HCWcoder avatar Dec 19 '18 00:12 HCWcoder

I'm not sure this feature is a good idea. The bot will be a spammer :/

Tkd-Alex avatar Dec 19 '18 14:12 Tkd-Alex

Yes i was testing and its not a good idea 💡

Your totally right

HCWcoder avatar Dec 20 '18 00:12 HCWcoder