Исходники - Бот Антипаблик | Telegram | End Way - форум программирования и сливов различных скриптов
  • Присоединяйтесь к нам в телеграм канал! EndWay канал | EndSoft канал | EWStudio канал
  • Хочешь поставить скрипт, но не умеешь?
    А может ты хочешь свой скрипт на основе слитого?

    Тогда добро пожаловать в нашу студию разработки!

    Телеграм бот: EWStudioBot
    Телеграм канал: EWStudio

Исходники Бот Антипаблик | Telegram

трахать

endway.su/threads/870/
Автор темы
8 Янв 2023
18
12
0
Сливаю бота, писал для себя на заказ.
Код:
from aiogram import types, Dispatcher, Bot, executor
from aiogram.contrib.fsm_storage.memory import MemoryStorage
import sqlite3 as sql
import logging
import asyncio

token = "СЮДА ВАШ ТОКЕН ИЗ @BotFather"
logging.basicConfig(level=logging.INFO)
bot = Bot(token=token)
storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage)

con = sql.connect('data.db', check_same_thread=False)
cur = con.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS strings(string VARCHAR)")


@dp.message_handler(content_types=["document"])
async def main(message: types.Document):
    if message.document.file_name.endswith(".txt") == True:
        new = 0
        file = await bot.get_file(message.document.file_id)
        file_path = file.file_path
        await bot.download_file(file_path, f"{message.document.file_id}.txt")
        uniq = open(f'uniq_{message.document.file_id}.txt', "w", encoding='utf-8')
        with open(f'{message.document.file_id}.txt', "r", encoding='utf-8') as file:
            for string in file:
                print(string)
                if cur.execute("SELECT string FROM strings WHERE string = ?", (string.strip(), )).fetchone() == None:
                    new += 1
                    cur.execute('INSERT INTO strings VALUES(?)', (string.strip(),))
                    con.commit()
                    uniq.write(string)
                else:
                    pass
                # if string in data:
                #     pass
                # else:
                #     new += 1
                #     cur.execute('INSERT INTO strings VALUES(?)', (string.strip(), ))
                #     con.commit()
                #     uniq.write(string)
        uniq.close()
        try:
            await bot.send_document(message.chat.id, open(f'uniq_{message.document.file_id}.txt', "rb"), caption=f"Уникальных строк: {new}")
        except Exception:
            await bot.send_message(message.chat.id, "Уникальных строк нет :(")

if __name__ == '__main__':
    while True:
        try:
            executor.start_polling(dp, skip_updates=True)
        except Exception as e:
            print(f"УПАЛ. {e}")


Ничего примечательного нет - залил строки, получил уникальные. data.db создается сама, вам ничего делать не нужно




 
Like
  • 5
Реакции: 4 users
Активность:
Пока что здесь никого нет