def delete_dm(api, dms, logging, testing):
    num_deleted = 0

    try:
        if logging:
            log = open(DELETED, "w")

        for dm in dms:
            dm.print_info()

            if not testing:
                try:
                    api.destroy_direct_message(dm.id)
                    if logging:
                        log.write(dm.text)
                    num_deleted = num_deleted + 1
                except TweepError:
                    print_error("Can't delete {0}".format(dm.text))

        if logging:
            log.close()

        return num_deleted

    except Exception as e:
        handle_exception(delete_dm.__name__, e)
def unfollow(api, users):
    for element in users:
        user = UserName(element)
        user_id = user.get_user_id()
        try:
            api.destroy_friendship(user_id)
            print_unfollow(user.to_string())
        except TweepError:
            print_error("Can't unfollow {0}".format(element))
Beispiel #3
0
def _get_video_files_from_args(files):
    video_files = []

    for f in files:
        if is_video(f):
            video_files.append(f)
        else:
            print_error("{0} is not a video".format(f))

    return video_files
Beispiel #4
0
def _get_video_files_from_args(files):
    video_files = []

    for f in files:
        if is_video(f):
            video_files.append(f)
        else:
            print_error("{0} is not a video".format(f))

    return video_files
Beispiel #5
0
def _get_shows_paths_files():
    video_files = []

    for path in SHOWS_PATHS:
        if os.path.exists(path):
            videos = get_videos(path)
            # TODO: Test this
            video_files.append(list(videos))
        else:
            print_error("{0} does not exists".format(path))

    return video_files
Beispiel #6
0
def _get_shows_paths_files():
    video_files = []

    for path in SHOWS_PATHS:
        if os.path.exists(path):
            videos = get_videos(path)
            # TODO: Test this
            video_files.append(list(videos))
        else:
            print_error("{0} does not exists".format(path))

    return video_files
Beispiel #7
0
def handle_error(error, ext):
    if error.split()[0] == "WARNING:":
        if "outdated" in error:
            ext = True
        print_warning(error.replace("WARNING:", "").strip())
    elif error.split()[0] == "ERROR:":
        print_error(error.replace("ERROR:", "").strip())
    else:
        print(error)

    if ext:
        exit(1)
Beispiel #8
0
def handle_error(error, ext):
    if error.split()[0] == "WARNING:":
        if "outdated" in error:
            ext = True
        print_warning(error.replace("WARNING:", "").strip())
    elif error.split()[0] == "ERROR:":
        print_error(error.replace("ERROR:", "").strip())
    else:
        print(error)

    if ext:
        exit(1)
Beispiel #9
0
def move(destinations, testing):
    """
    move(destinies, bulk_move, debugging, testing)
        Move the series to the known disks for store tv shows.
    Arguments:
        destinations: (string list) Destiny directories.
        testing: (boolean) Indicates if the program is in testing mode.
    """

    files_moved = False
    non_existent_paths = []

    time_ini = time.clock()

    for show_path in SHOWS_PATHS:
        for destination in destinations:
            print_header(destination, testing)
            if os.path.isdir(show_path):
                files = os.listdir(show_path)

                for f in files:
                    this_file = File(show_path, f)

                    if this_file.is_well_formatted():
                        files_moved = True
                        if destination not in FINAL_DISKS:
                            file_dest = os.path.join(destination,
                                                     this_file.file_name)
                            mv(this_file.original_path, file_dest, testing)

                        else:
                            file_dest = Path(f, destination, testing)

                            if file_dest.final_destination:
                                mv(this_file.original_path,
                                   file_dest.final_destination, testing)
                            else:
                                nonexistent_path = os.path.join(
                                    show_path, file_dest.show_name)
                                non_existent_paths = list_handler.append_non_repeated(
                                    nonexistent_path, non_existent_paths)
            else:
                print_error("{0} is not a valid path.".format(show_path))

    if files_moved:
        for path in non_existent_paths:
            print_info("\n\n{0} does not exist.".format(path))

        time_end = time.clock()
        total_time = time_end - time_ini
        print_time(total_time)
    else:
        print_info("No files moved.")
Beispiel #10
0
def move(destinations, testing):
    """
    move(destinies, bulk_move, debugging, testing)
        Move the series to the known disks for store tv shows.
    Arguments:
        destinations: (string list) Destiny directories.
        testing: (boolean) Indicates if the program is in testing mode.
    """

    files_moved = False
    non_existent_paths = []

    time_ini = time.clock()

    for show_path in SHOWS_PATHS:
        for destination in destinations:
            print_header(destination, testing)
            if os.path.isdir(show_path):
                files = os.listdir(show_path)

                for f in files:
                    this_file = File(show_path, f)

                    if this_file.is_well_formatted():
                        files_moved = True
                        if destination not in FINAL_DISKS:
                            file_dest = os.path.join(destination, this_file.file_name)
                            mv(this_file.original_path, file_dest, testing)

                        else:
                            file_dest = Path(f, destination, testing)

                            if file_dest.final_destination:
                                mv(this_file.original_path, file_dest.final_destination, testing)
                            else:
                                nonexistent_path = os.path.join(show_path, file_dest.show_name)
                                non_existent_paths = list_handler.append_non_repeated(nonexistent_path,
                                                                                      non_existent_paths)
            else:
                print_error("{0} is not a valid path.".format(show_path))

    if files_moved:
        for path in non_existent_paths:
            print_info("\n\n{0} does not exist.".format(path))

        time_end = time.clock()
        total_time = time_end - time_ini
        print_time(total_time)
    else:
        print_info("No files moved.")
def mv(orig, dest, testing):
    """
    mv(orig, dest, debugging, testing)
        Moves all the files to the same directory.
    Arguments:
        orig: (string) Directory where the files will be gotten.
        dest: (string) Directory where the files will be moved.
        testing: (boolean) Indicates if the program is in testing mode.s
    """

    try:
        orig_file_name = os.path.basename(orig)
        dest_file_name = os.path.basename(dest)

        print_mv(orig_file_name, dest_file_name)

        if not testing:
            os.rename(orig, dest)
    except Exception as ex:
        print_error(ex)
Beispiel #12
0
def load_plugins():
    loaded_modules = []

    base_path = os.getcwd()
    plugins_path = os.path.join(base_path, "application", "get_subs_plugins")

    print_info("Loading plugins...")

    if os.path.exists(plugins_path):
        plugins = _get_plugins(plugins_path)

        if plugins and len(plugins) > 0:
            loaded_modules = _load_modules(plugins)
            print_info("Plugins loaded")
        else:
            print_info("No plugins found to download subtitles")
    else:
        print_error("Plugins not found")

    return loaded_modules
def mv(orig, dest, testing):
    """
    mv(orig, dest, debugging, testing)
        Moves all the files to the same directory.
    Arguments:
        orig: (string) Directory where the files will be gotten.
        dest: (string) Directory where the files will be moved.
        testing: (boolean) Indicates if the program is in testing mode.s
    """

    try:
        orig_file_name = os.path.basename(orig)
        dest_file_name = os.path.basename(dest)

        print_mv(orig_file_name, dest_file_name)

        if not testing:
            os.rename(orig, dest)
    except Exception as ex:
        print_error(ex)
Beispiel #14
0
def load_plugins():
    loaded_modules = []

    base_path = os.getcwd()
    plugins_path = os.path.join(base_path, "application", "get_subs_plugins")

    print_info("Loading plugins...")

    if os.path.exists(plugins_path):
        plugins = _get_plugins(plugins_path)

        if plugins and len(plugins) > 0:
            loaded_modules = _load_modules(plugins)
            print_info("Plugins loaded")
        else:
            print_info("No plugins found to download subtitles")
    else:
        print_error("Plugins not found")

    return loaded_modules
Beispiel #15
0
def get_metadata(file_path):
    """
    get_metadata(file_path)
        Defined to use the script as a module.

    Arguments:
        file_path: (string) Absolute file path.
    """

    metadata = None

    if file_path.lower().endswith('.pdf'):
        try:
            metadata = Metadata(file_path)
            metadata.print_info()
        except Exception as ex:
            print_exception(ex)
    else:
        print_error('{0} is not a PDF file.'.format(file_path))

    return metadata
Beispiel #16
0
def get_metadata(file_path):
    """
    get_metadata(file_path)
        Defined to use the script as a module.

    Arguments:
        file_path: (string) Absolute file path.
    """

    metadata = None

    if file_path.lower().endswith('.pdf'):
        try:
            metadata = Metadata(file_path)
            metadata.print_info()
        except Exception as ex:
            print_exception(ex)
    else:
        print_error('{0} is not a PDF file.'.format(file_path))

    return metadata
        include_special_chars = args.special_chars

        total_chars = 0
        total_symbols = 0
        frequency = {}

        clear_screen()

        condition_messages.print_info("Analyzing: {0}\n".format(" ".join(text)))

        for word in text:
            for char in word:
                if (char not in SPECIAL_CHARS) or (char in SPECIAL_CHARS and include_special_chars):
                    increment(frequency, char)
                    total_chars = total_chars + 1
            if include_spaces:
                increment(frequency, ' ')
                total_chars = total_chars + 1

        total_symbols = len(frequency)

        condition_messages.print_info("Total chars: {0}".format(total_chars))
        condition_messages.print_info("Chars used: {0}\n".format(total_symbols))
        print_frequency(frequency, total_chars)
        print()
        suggest_cipher(total_symbols, text)

    else:
        condition_messages.print_error("Requires Python {0}".format(REQUIRED_PYTHON_VERSION))
        exit(0)
Beispiel #18
0
    signal.signal(signal.SIGINT, exit_signal_handler)

    interpreter = get_interpreter_version()

    if interpreter == REQUIRED_PYTHON_VERSION:

        parser = argparse.ArgumentParser(
            description='Look for repeated chapters')

        parser.add_argument('path',
                            metavar='path',
                            help="path where the files are being sought")

        parser.add_argument("-t",
                            "--test",
                            dest="testing",
                            action="store_true",
                            help="shows the expected output")

        args = parser.parse_args()

        clear_screen()

        print_header(args.path, args.testing)

        search_duplicated_episodes(args.path, args.testing)

    else:
        print_error("Requires Python {0}".format(REQUIRED_PYTHON_VERSION))
        exit(0)
Beispiel #19
0
        print_info("Getting subtitles")

        if args.files:
            video_files = _get_video_files_from_args(args.files)

        else:
            video_files = _get_shows_paths_files()

        if len(video_files) > 0:
            plugins_loaded = load_plugins()

            if plugins_loaded:
                print_info("Downloading subtitles...")

                for f in video_files:
                    subtitle_found = False

                    for plugin in plugins_loaded:
                        subtitle_found = execute_plugin(plugin, f)
                        if subtitle_found:
                            break

                    if not subtitle_found:
                        print_info("\tSubtitle not found")

        else:
            print_error("No files specified")
else:
    print_error("Requires Python {0}".format(REQUIRED_PYTHON_VERSION))
exit(0)
Beispiel #20
0
                total_files = total_files + 1

                metadata = get_metadata(argument)

                if metadata:
                    analyzed_files = analyzed_files + 1

                    if log_txt:
                        log_txt.write(metadata)

                    if log_csv:
                        log_csv.write(metadata)

            elif os.path.isdir(argument):
                analyzed_files, total_files = scan(
                    argument, analyzed_files, total_files, log_txt, log_csv)
            else:
                print_error(
                    '{0} is not a valid PDF file or a existing directory.'.format(argument))

        if log_txt:
            print_info('Saved to: {0}'.format(log_txt.file_name))
        if log_csv:
            print_info('Saved to: {0}'.format(log_csv.file_name))

        print_info(
            'Analyzed files: {0}/{1}'.format(analyzed_files, total_files))
    else:
        print_error('Requires Python {0}'.format(REQUIRED_PYTHON_VERSION))
        exit(0)
Beispiel #21
0
                            help="Runs a single test showing the output.")

        args = parser.parse_args()
        testing = args.test
        destination_path = args.path

        paths = []

        clear_screen()

        if destination_path:
            if os.path.isdir(destination_path):
                paths.append(destination_path)
                move(paths, testing)
            else:
                print_error("{0} is not a directory.".format(destination_path))

        else:
            buffer_disks_mounted = get_mounted_disks(BUFFER_DISKS)
            final_disks_mounted = get_mounted_disks(FINAL_DISKS)

            if buffer_disks_mounted or final_disks_mounted:
                paths = buffer_disks_mounted + final_disks_mounted
                move(paths, testing)
            else:
                print_error("No mounted disks found.")

    else:
        print_error("Requires Python {0}".format(REQUIRED_PYTHON_VERSION))
        exit(0)
Beispiel #22
0
        parser = argparse.ArgumentParser(prog="CLITube")
        parser = argparse.ArgumentParser(
            description=
            "Script to watch youtube videos from CLI in a video player")
        parser.add_argument("youtube_url",
                            metavar="YOUTUBE_VIDEO_URL",
                            nargs=1,
                            help="URL of the video on youtube.")
        args = parser.parse_args()

        user_url = args.youtube_url[0]

        match = YOUTUBE_VIDEO_PATTERN.search(user_url)

        if match:
            user_url = match.group(0)

            youtubedl = Youtubedl(user_url)
            video_player = get_instance_of(VIDEO_PLAYER)

            print_header()
            print_fetching(user_url)
            real_video_url = youtubedl.get_url()
            video_player.play(real_video_url)
        else:
            print_error('{0} is not a youtube video'.format(user_url))
            exit(0)
    else:
        print_error('Requires Python {0}'.format(REQUIRED_PYTHON_VERSION))
        exit(0)
Beispiel #23
0
        print_info("Getting subtitles")

        if args.files:
            video_files = _get_video_files_from_args(args.files)

        else:
            video_files = _get_shows_paths_files()

        if len(video_files) > 0:
                plugins_loaded = load_plugins()

                if plugins_loaded:
                    print_info("Downloading subtitles...")

                    for f in video_files:
                        subtitle_found = False

                        for plugin in plugins_loaded:
                            subtitle_found = execute_plugin(plugin, f)
                            if subtitle_found:
                                break

                        if not subtitle_found:
                            print_info("\tSubtitle not found")

        else:
            print_error("No files specified")
else:
    print_error("Requires Python {0}".format(REQUIRED_PYTHON_VERSION))
exit(0)
        args = parser.parse_args()

        if args.in_file:
            if os.path.isfile(args.in_file):
                in_file = args.in_file

                clear_screen()

                print_header(in_file, args.from_file, args.test)

                if args.from_file:

                    if os.path.isfile(args.from_file):
                        from_file = args.from_file

                        search_in_files(in_file, from_file)

                    else:
                        print_error("{0} is not a file.".format(args.from_file))
                        sys.exit(-1)
                else:
                    search_in_file(in_file)

            else:
                print_error("{0} is not a file.".format(args.in_file))
                sys.exit(-1)
    else:
        print_error("Requires Python {0}".format(REQUIRED_PYTHON_VERSION))
        exit(0)
        args = parser.parse_args()

        if args.in_file:
            if os.path.isfile(args.in_file):
                in_file = args.in_file

                clear_screen()

                print_header(in_file, args.from_file, args.test)

                if args.from_file:

                    if os.path.isfile(args.from_file):
                        from_file = args.from_file

                        search_in_files(in_file, from_file)

                    else:
                        print_error("{0} is not a file.".format(
                            args.from_file))
                        sys.exit(-1)
                else:
                    search_in_file(in_file)

            else:
                print_error("{0} is not a file.".format(args.in_file))
                sys.exit(-1)
    else:
        print_error("Requires Python {0}".format(REQUIRED_PYTHON_VERSION))
        exit(0)
Beispiel #26
0
from domain.youtubedl import Youtubedl
from presentation.utils.screen import clear_screen

if __name__ == "__main__":
    signal.signal(signal.SIGINT, exit_signal_handler)

    clear_screen()

    interpreter_version = get_interpreter_version()

    if interpreter_version == REQUIRED_PYTHON_VERSION:

        parser = argparse.ArgumentParser(prog="CLITube")
        parser = argparse.ArgumentParser(description="Script to watch youtube videos from CLI in a video player")
        parser.add_argument("youtube_url", metavar="YOUTUBE_VIDEO_URL", nargs=1, help="URL of the video on youtube.")
        args = parser.parse_args()

        youtube_url = args.youtube_url[0]

        youtubedl = Youtubedl(youtube_url)
        video_player = get_instance_of(VIDEO_PLAYER)

        print_header()
        print_fetching(youtube_url)
        url = youtubedl.get_url()
        video_player.play(url)

    else:
        print_error('Requires Python {0}'.format(REQUIRED_PYTHON_VERSION))
        exit(0)
def handle_error(err, ext):
    print_error(err.decode("UTF-8"))

    if ext:
        exit(1)
        target = args.target
        quiet_mode = args.quiet

        if args.separator:
            separator = args.separator
        else:
            separator = DEFAULT_SEPARATOR

        print_info("Analyzing: {0}\n".format(target))

        if os.path.exists(target) and os.path.isfile(target):
            try:
                sumary = Sumary()
                f = open(target, "r", encoding="UTF-8", errors="ignore")
                parse_file(f, separator, quiet_mode, sumary)
                f.close()
                sumary.print_stats()
            except Exception as ex:
                print_error(ex)
        else:
            if not os.path.exists(target):
                print_error("{0} does not exists.".format(target))
                exit(1)
            if not os.path.isfile(target):
                print_error("{0} is a directory.".format(target))
                exit(1)
    else:
        print_error("Requires Python {0}".format(REQUIRED_PYTHON_VERSION))
        exit(0)