Example #1
0
    def connectServer(self):        
        try:
            if self.connec: 
                # Se solicitan las opciones disponibles 
                options = client.sendMesagge(self, "options")
            while self.connec:
                # Se imprime en pantalla las opciones
                request = enquiries.choose('Indica la operación que desea realizar: ', options)

                # Se realiza la acción según la opción seleccionada por el usuario
                if request == "Finalizar":
                    response = client.sendMesagge(self, request)
                    print(response)
                    client.closeConnection(self)
                if request == "Consultar":
                    self.clientSokect.send(request.encode())
                    accountNumber = enquiries.freetext("Ingrese el número de cuenta a consultar:")
                    response = client.sendMesagge(self, accountNumber)
                    print(response["message"])
                    client.closeConnection(self)
                if request == "Agregar cuenta":
                    self.clientSokect.send(request.encode())
                    accountNumber = int(enquiries.freetext("Ingrese el número de cuenta que desea agregar:"))
                    value = enquiries.freetext("Ingrese el valor:")
                    response = client.sendMesagge(self, "{},{}".format(accountNumber, value))
                    print(response["message"])
                    client.closeConnection(self)
        except KeyboardInterrupt:
            # Se finaliza la conexión
            print("\nOperación finalizada por el usuario")
            client.closeConnection(self)
Example #2
0
def delete_files(tg_client, chat_id, files):
    """
        This function deletes the file with id file_id.
    """

    if len(files) == 0:
        return False

    file_log = get_logger()

    question = "\n".join(
        [f"  {caption_text}" for (_, _, caption_text) in files])
    question += "\n\nAre you sure you want to delete these files?"

    if choose(question, ["Yes", "No"]) == "No":
        return False

    task = tg_client.call_method(
        "deleteMessages", {
            "chat_id": chat_id,
            "message_ids": [msg_id for (msg_id, _, _) in files],
            "revoke": True
        })

    print("Deleting... Please wait.")
    task.wait()

    if task.error_info:
        file_log.error("Error showing file %s", task.error_info)
        freetext("Oops... Something went wrong.")
        return False

    freetext("Files deleted.")
    return True
Example #3
0
def search(tg_client, chat_id, _):
    """
        This function searches for uploaded file using the
        RegEx provide by the user.
    """

    search_reg = freetext(
        "Enter the file path to browse for ( RegEx supported )")
    print("Searching...")
    files = []
    file_names = ["Select All"]

    try:
        for (msg_id, file_id, caption) in get_messages(tg_client, chat_id):
            if re_search(search_reg, caption):
                files.append((msg_id, file_id, caption))
                file_names.append(caption)
    except re_error as re_er:
        get_logger().warning("Error searching %s", re_er)

    if len(files) == 0:
        return freetext("No files matched your browse")

    choice = long_choice("Select files", file_names, False)

    if file_names[0] == choice:
        use_files(files, tg_client, chat_id)
    else:
        use_files(files[file_names.index(choice)], tg_client, chat_id)
Example #4
0
def menu_single():
    print_header()
    options = [
        'I want to update ...', 'I want to update mythic of ...',
        'I want to add guild role to ...', 'I want to add meta to ...',
        'I want to back'
    ]
    choice = enquiries.choose('What r u wanna do?: ', options)
    name = enquiries.freetext('Character name: ')
    if choice is options[0]:
        CharacterUpdater.update_character(name)
        return menu_press_enter_and_back()
    if choice is options[1]:
        MythicUpdater.update_mythic_character(name)
        return menu_press_enter_and_back()
    if choice is options[2]:
        role = enquiries.freetext("Type guild role: ")
        CharacterUpdater.update_guild_role(name, int(role))
        return menu_press_enter_and_back()
    if choice is options[3]:
        meta = enquiries.freetext("Type meta text: ")
        CharacterUpdater.update_meta(name, meta)
        return menu_press_enter_and_back()
    if choice is options[4]:
        menu_root()
    pass
Example #5
0
def free(prompt, quiet):
    user_input = freetext(prompt)
    # If we're not being quiet and stdout is not being redirected, write the prompt
    if not quiet and sys.stdout.isatty():
        click.secho(prompt, err=True, bold=True)
    # always print the output
    click.echo(user_input)
Example #6
0
def show_file(tg_client, chat_id, files):
    """
        This function downloads and displays the file
        with id file_id.
    """

    for (msg_id, file_id, caption) in files:

        task = download_file(
            tg_client,
            file_id if file_id else get_file_id(tg_client, chat_id, msg_id))

        if task.error_info is None:
            temp_file = join(gettempdir(), basename(caption))
            move(task.update["local"]["path"], temp_file)
            webbrowser.open(f"file://{temp_file}", new=2)
        else:
            get_logger().error("Error showing file %s", task.error_info)
            freetext("Oops... Something went wrong.")
Example #7
0
def load_data():
    """
        This function tries to read phone number, chat id and
        list of backup folders from DATA_FILE. If they are not
        found it prompts user to enter them.
    """

    try:
        with open(DATA_FILE, "rb") as db_file:
            db_dict = pickle.load(db_file)
            return db_dict["phone_number"], db_dict["chat_id"], db_dict[
                "back_up_folders"]

    except FileNotFoundError:
        ph_no = freetext("Enter your phone number with country code: ")
        print("Select folders to backup.")
        bup_folders = get_folders()
        chat_id = freetext(
            "Enter the chat ID to be used for backup (leave blank if you are unsure): "
        )

        if not chat_id.isnumeric():
            chat_id = None

        os.makedirs(os.path.dirname(DATA_FILE), exist_ok=True)
        os.makedirs(os.path.dirname(FILES_DIR), exist_ok=True)

        with open(DATA_FILE, "wb") as db_file:
            data = {
                "phone_number": ph_no,
                "chat_id": chat_id,
                "back_up_folders": bup_folders
            }
            pickle.dump(data, db_file)

        return ph_no, chat_id, bup_folders
Example #8
0
categories = [
    'Coronavirus', 'Politics', 'Economy', 'Society', 'Sports', 'Lifestyle'
]
choice = enquiries.choose('Choose a category: ', categories)

use_file = enquiries.choose('Use file for emails?', ['yes', 'no'])

email_list = []

if use_file == 'yes':
    with open('emails.txt', 'r') as file:
        f = file.readlines()
        for email in f:
            email_list.append(email.strip())
else:
    recipient = enquiries.freetext('Emails (Use comma to separate emails): ')
    email_list.append(recipient.split(','))
    email_list = email_list[0]

if choice == 'Coronavirus':
    News(choice).send_mail(email_list)
elif choice == 'Politics':
    News(choice).send_mail(email_list)
elif choice == 'Economy':
    News(choice).send_mail(email_list)
elif choice == 'Society':
    News(choice).send_mail(email_list)
elif choice == 'Sports':
    News(choice).send_mail(email_list)
elif choice == 'Lifestyle':
    News(choice).send_mail(email_list)