Пример #1
0
def execargs():
    if sys.argv[0] == '-h' or sys.argv[0] == '--help' or sys.argv[0] == '/?':
        funcs.help()
    elif sys.argv[0] == '-c':
        database.load()
        for k in database.database.keys():
            print(k)
    elif sys.argv[0] == '-w':
        if not funcs.areUsure():
            print('failed')
        database.database = {}
        database.dump()
        print('\nok\n')
    elif sys.argv[0] == '-a' and len(sys.argv) == 3 and os.path.exists(
            sys.argv[2]):
        database.load()
        with open(sys.argv[2], 'r', encoding='utf-8') as f:
            database.addCountedWords(process.count(f.read()), sys.argv[1])
        database.dump()
        print('\nok\n')
    elif sys.argv[0] == '-p' and len(sys.argv) == 2 and os.path.exists(
            sys.argv[1]):
        database.load()
        scores = process.getscores(sys.argv[1])
        for cat in scores.keys():
            print(f'{cat}\t:\t{scores[cat]}')
Пример #2
0
def doc(client, message):
    res = message.reply_text("**Analysing file...**", True)
    mimmetype = message.document.mime_type
    if mimmetype in mmtypes:
        dts = dt(message.chat.id)
        if not today_date == dts:
            update(message.chat.id, 0, "free")
        status_bot = check(message.chat.id)
        counts = count(message.chat.id)
        if status_bot is None:
            update(message.chat.id, 0, "free")
        elif status_bot == "free":
            update(message.chat.id, counts, "waiting")
            message.reply_chat_action("typing")
            res.edit(text="choose the destination language",
                     reply_markup=InlineKeyboardMarkup(langs)
                     )
        else:
            res.edit(err1)
    else:
        res.edit(err2)
Пример #3
0
def main():
    global changes
    database.load()
    while True:
        funcs.clear()
        funcs.menu()
        ans = input('your choice : ')
        if ans == 'e':
            if changes == '':
                exit()
            q = input(
                'there are some unsaved changes. do you want to save them ??? (y/n)'
            )
            if q == 'n':
                exit()
            elif q == 'y':
                database.dump()
                exit()
        elif ans == 'a':
            pth = input('enter file name to add to database : ')
            with open(pth, 'r', encoding='utf-8') as f:
                cat = input('category name : ')
                database.addCountedWords(process.count(f.read()), cat)
                changes += f'Add {pth} to database[{cat}].\n'
                input(
                    'new file added successfully\npress enter to continue ...')
        elif ans == 'd':
            """if not funcs.areUsure():
                input('press enter to continue ...')
                continue"""
            database.dump()
            changes = ''
            input('ok\npress enter to continue ...')
        elif ans == 'l':
            if changes == '':
                input('no changes detected !!!\npress enter to continue ...')
                continue
            if not funcs.areUsure():
                input('press enter to continue ...')
                continue
            database.load()
            input('ok\npress enter to continue ...')
        elif ans == 'w':
            if not funcs.areUsure():
                input('press enter to continue ...')
                continue
            database.database = {}
            database.dump()
            input('ok\npress enter to continue ...')
        elif ans == 'p':
            pth = input('enter file name : ')
            scores = process.getscores(pth)
            print()
            for cat in scores.keys():
                print(f'{cat}\t:\t{scores[cat]}')
            print()
            input('\npress enter to continue ...')
        elif ans == 'c':
            print()
            for k in database.database.keys():
                print(k)
            input('\npress enter to continue ...')
Пример #4
0
def data(client, callback_query):
    then = time.time()
    rslt = callback_query.data
    if rslt == "about":
        callback_query.message.edit(
            text=about,
            disable_web_page_preview=True,
            reply_markup=InlineKeyboardMarkup([[
                InlineKeyboardButton("📬 Give Feedback 📬", url="t.me/ab_wolf")
            ]]),
        )
    elif rslt == "close":
        callback_query.message.delete()
    elif rslt == "help":
        callback_query.message.edit(
            text=help_text,
            reply_markup=InlineKeyboardMarkup(
                [[InlineKeyboardButton("close",
                                       callback_data="♻️ CLOSE ♻️")]]),
        )
    else:
        lang = rslt
        msg = callback_query.message
        message = msg.reply_to_message
        location = os.path.join("./FILES", str(message.chat.id))
        if not os.path.isdir(location):
            os.makedirs(location)
        file_path = location + "/" + message.document.file_name
        subdir = client.download_media(message=message, file_name=file_path)
        translator = Translator()
        outfile = f"{subdir.replace('.srt', '')}_{lang}.srt"
        msg.delete()
        counts = count(message.chat.id)
        if counts > 10:
            message.reply_text(err3)
            os.remove(subdir)
            update(message.chat.id, counts, "free")
        else:
            tr = message.reply_text(f"Translating to {lang}", True)
            counts += 1
            update(message.chat.id, counts, "waiting")
            process_failed = False
            try:
                with io.open(subdir, "r", encoding="utf-8") as file:
                    try:
                        subtitle = file.readlines()
                    except Exception:
                        tr.edit(err4)
                        update(message.chat.id, counts, "free")

                    subtitle[0] = "1\n"
                    with io.open(outfile, "w", encoding="utf-8") as f:
                        total = len(subtitle)
                        done = 0

                        for i in range(total):
                            diff = time.time() - then
                            if subtitle[i][0].isdigit():
                                f.write("\n" + subtitle[i])
                                done += 1
                            else:
                                try:
                                    receive = translator.translate(subtitle[i],
                                                                   dest=lang)
                                    f.write(receive.text + "\n")
                                    done += 1
                                except Exception:
                                    pass

                            speed = done / diff
                            percentage = round(done * 100 / total, 2)
                            eta = format_time(int((total - done) / speed))
                            if done % 20 == 0:
                                try:
                                    tr.edit(text=eta_text.format(
                                        message.document.file_name,
                                        done,
                                        total,
                                        percentage,
                                        round(speed),
                                        eta,
                                        "".join([
                                            "▓" for i in range(
                                                math.floor(percentage / 7))
                                        ]),
                                        "".join([
                                            "░" for i in
                                            range(14 -
                                                  math.floor(percentage / 7))
                                        ]),
                                    ))
                                except Exception:
                                    pass
            except Exception:
                tr.edit(err5)
                counts -= 1
                update(message.chat.id, counts, "free")
                process_failed = True
            if process_failed is not True:
                tr.delete()
                if os.path.exists(outfile):
                    message.reply_document(document=outfile,
                                           thumb="logo.jpg",
                                           quote=True,
                                           caption=caption)
                    update(message.chat.id, counts, "free")
                    insertlog()
                    updateFile()
                    os.remove(subdir)
                    os.remove(outfile)
                else:
                    pass