示例#1
0
def check(user_id):
    '''
    Add an entry to check.
    '''
    global current_images_dict
    current_images_dict[user_id] = time.time()
    StatsAppend(LineStats.storedImages, len(filecenter.files_in_dir(images_path)))
示例#2
0
def checkForUpdate():
    """
    Checks infinitely for any update
    """
    while True:
        verify_manami_adb()
        numberOfCaches = 0
        for path in caches_path:
            numberOfCaches += len(files_in_dir(path))
        StatsAppend(erina.cacheFilesCount, numberOfCaches)
        sleep(86400) # Checks every day
def clean(keepsetup=False):
    global package_name
    global main_module
    lifeeasy.display_action('Cleaning the package directory', delay=0.1)
    if package_name == '':
        package_name = input('What is the package name? ')
    if main_module == '':
        main_module = input(
            'What is the main module file name (with extension) ? ')
    try:
        if filecenter.exists(lifeeasy.working_dir() + '/' + package_name +
                             '.egg-info'):
            print('Removing .egg-info')
            filecenter.delete(lifeeasy.working_dir() + '/' + package_name +
                              '.egg-info')
        if filecenter.exists(lifeeasy.working_dir() + '/dist'):
            print('Removing dist')
            filecenter.delete(lifeeasy.working_dir() + '/dist')
        if filecenter.exists(lifeeasy.working_dir() + '/build'):
            print('Removing build')
            filecenter.delete(lifeeasy.working_dir() + '/build')
        if filecenter.isdir(lifeeasy.working_dir() + '/' + package_name):
            print("Moving the package to its original location")
            for file in filecenter.files_in_dir(lifeeasy.working_dir() + '/' +
                                                package_name):
                print("Moving " + file)
                if file == '__init__.py':
                    filecenter.move(
                        lifeeasy.working_dir() + '/' + package_name + '/' +
                        file,
                        lifeeasy.working_dir() + '/' + main_module)
                else:
                    filecenter.move(
                        lifeeasy.working_dir() + '/' + package_name + '/' +
                        file,
                        lifeeasy.working_dir() + '/' + file)
        if filecenter.exists(lifeeasy.working_dir() + '/' + package_name):
            print('Deleting the package temp directory')
            filecenter.delete(lifeeasy.working_dir() + '/' + package_name)
        if filecenter.isfile(lifeeasy.working_dir() + '/setup.py'):
            if keepsetup == False:
                print('Deleting setup.py')
                filecenter.delete(lifeeasy.working_dir() + '/setup.py')
        if filecenter.isdir(lifeeasy.working_dir() + '/__pycache__'):
            print('Deleting caches')
            filecenter.delete(lifeeasy.working_dir() + '/__pycache__')
        return 0
    except:
        return 1
示例#4
0
def checkImages():
    '''
    Timeout checking function.
    '''
    global current_images_dict
    number_of_deleted_files = 0 # logging purposes
    for entry in current_images_dict:
        if time.time() - current_images_dict[entry] > LineConfig.images_timeout:
            if filecenter.delete(images_path + entry + '.erina_image') == 0:
                current_images_dict.pop(entry, None)
                number_of_deleted_files += 1 # logging purposes
    ### LOGGING
    if number_of_deleted_files > 0:
        if number_of_deleted_files == 1:
            log("ErinaLine", "[Image Checker] Deleted 1 entry")
        else:
            log("ErinaLine", f'[Image Checker] Deleted {str(number_of_deleted_files)} entries')
        StatsAppend(LineStats.storedImages, len(filecenter.files_in_dir(images_path)))
def nosort():
    global number_of_moved_items
    lifeeasy.display_body(['Chosen mode: No Sorting', 'Completion: 0%'])
    list_of_files_in_cleaning_dir = filecenter.files_in_dir(cleaning_dir)
    lifeeasy.display_body(['Chosen mode: No Sorting', 'Completion: 1%'])
    completion = 0
    for file in list_of_files_in_cleaning_dir:
        completion += len(list_of_files_in_cleaning_dir) / 100 + 1
        lifeeasy.display_body(
            ['Chosen mode: No Sorting', 'Completion: {}%'.format(completion)])
        if file == __file__:
            continue
        if file == destination_dir_name:
            continue
        filecenter.move(cleaning_dir + file, destination_dir)
        number_of_moved_items += 1
    lifeeasy.display_body(['Chosen mode: No Sorting', 'Completion: 100%'])
    goodbye()
def start():
    global cleaning_dir
    global destination_dir
    global destination_dir_name
    global unique_number
    global number_of_items

    lifeeasy.clear()
    if __file__ == '__main__':
        print("What's the folder you want to clean today?")
        cleaning_dir = input('> ')
    else:
        cleaning_dir = lifeeasy.working_dir()
    if cleaning_dir.lower() == 'cancel' or cleaning_dir.lower(
    ) == 'stop' or cleaning_dir.lower() == 'quit' or cleaning_dir.lower(
    ) == 'exit':
        goodbye(nothing=True)
    elif filecenter.isdir(cleaning_dir):
        if cleaning_dir[-1] != '/' or cleaning_dir[-1] != '\\':
            if filecenter.os_name() == 'nt':
                cleaning_dir = cleaning_dir + '\\'
            else:
                cleaning_dir = cleaning_dir + '/'

        for _ in filecenter.files_in_dir(cleaning_dir):
            number_of_items += 1

        destination_dir_name = 'Cleaned'
        while filecenter.exists(cleaning_dir + destination_dir_name):
            destination_dir_name = destination_dir_name + ' ' + str(
                unique_number)
            unique_number += 1
        destination_dir = cleaning_dir + destination_dir_name
        filecenter.make_dir(destination_dir)
        decide_mode()
    else:
        lifeeasy.display_action('It seems like you mistyped the path',
                                delay=0.1)
        print('Please retry entering the path to your folder')
        lifeeasy.sleep(2)
        start()
def add_animes_to_database(auto_analyze=True):
    global anime
    global fps_dict
    global frames_stats_dict
    global queue

    for file in filecenter.files_in_dir(erina_add_animes_path):
        if file == '.DS_Store':
            continue
        if file == '.gitkeep':
            continue
        if filecenter.type_from_extension(filecenter.extension_from_base(file)) == 'Folder':
            anime = file

            if anime == '':
                print('No anime folder found.')
                quit()

            if '-a' in sys.argv or '--auto' in sys.argv or auto_analyze == True:
                anilist_filename = erinacache.anilist_search_caching(anime)
                anilist_id = anilist_filename.replace('.erina', '')
                season = '1'
            else:
                print('What is the AniList ID for ' + anime + '?')
                anilist_id = input('> ')
                print('Which season is it?')
                season = input('> ')



            def analyze_episode(episode):
                """
                Internal Function that is ran by multiple thread to analyze each frame of an anime episode and create a file with its hash.
                Erina Project
                © Anime no Sekai - 2020
                """

                global fps_dict
                global frames_stats_dict
                global queue

                queue += 1
                episode_number = erina_aniep.episode_from_filename(episode, anime)
                
                frames_stats_dict[episode_number] = {'frame': 0, 'total_frames': 0, 'status': 'Starting'}

                video = cv2.VideoCapture(erina_add_animes_path + anime + '/' + episode)

                frame_count = video.get(cv2.CAP_PROP_FRAME_COUNT)
                framerate = video.get(cv2.CAP_PROP_FPS)
                duration = frame_count/framerate

                success, image = video.read()
                
                count = 0
                fps = 0
                start_loop_fps = 0
                end_loop_fps = 0
                start_loop_time = process_time()
                from_dict = {}
                first_frame_dict = {}

                new_database_path = erina_database_path + anime + '/' + episode_number
                if filecenter.isdir(new_database_path) == False:
                    filecenter.make_dir(new_database_path)
                
                skip = False
                while success:
                    if skip == False:
                        hashing_image = Image.fromarray(image)
                        image_hash = imagehash.average_hash(hashing_image)

                        second = count/framerate

                        try:
                            from_second = from_dict[str(image_hash)]
                            at_second = (float(from_second) + second) / 2
                        except:
                            from_dict[str(image_hash)] = second
                            from_second = second
                            at_second = second

                        try:
                            first_frame = first_frame_dict[str(image_hash)]
                        except:
                            first_frame_dict[str(image_hash)] = count
                            first_frame = count
                                
                        database_content = []
                        database_content.append('AniList ID: ' + anilist_id)
                        database_content.append('Anime: ' + anime)
                        database_content.append('Season: ' + season)
                        database_content.append('Episode: ' + episode_number)
                        database_content.append('First Frame: ' + str(first_frame))
                        database_content.append('Last Frame: ' + str(count))
                        database_content.append('From: ' + str(from_second))
                        database_content.append('To: ' + str(second))
                        database_content.append('At: ' + str(at_second))
                        database_content.append('Hash: ' + str(image_hash))
                        database_content.append('Hashing Algorithm: Average Hash (aHash)')
                        database_content.append('Filename: ' + episode)
                        database_content.append('Episode Framerate: ' + str(framerate))
                        database_content.append('Episode Duration: ' + str(duration))
                        database_content.append('Episode Frame Count: ' + str(frame_count))
                        database_content.append('')
                        database_content.append('Analyze Date: ' + str(datetime.timestamp(datetime.today())))
                        
                        lifeeasy.write_file(str(image_hash) + '.erina', database_content, new_database_path)

                    frames_stats_dict[episode_number] = {'frame': count, 'total_frames': frame_count, 'status': 'Active'}
                    
                    count += 1

                    end_loop_fps += 1
                    end_loop_time = process_time()
                    if end_loop_time - start_loop_time > 1:
                        fps = int(end_loop_fps - start_loop_fps)
                        fps_dict[episode_number] = fps
                        start_loop_time = process_time()
                        start_loop_fps = end_loop_fps

                    if skip == True:
                        skip = False
                        success, image = video.read()
                    else:
                        skip = True
                        success = video.grab()
                queue -= 1
                frames_stats_dict[episode_number] = {'frame': count, 'total_frames': frame_count, 'status': 'Done'}
                fps_dict.pop(episode_number, None)


            start_time = process_time()
            for episode in filecenter.files_in_dir(erina_add_animes_path + anime):
                if filecenter.type_from_extension(filecenter.extension_from_base(episode)) != 'Video':
                    continue
                else:
                    print('Opening new thread...')
                    thread = threading.Thread(target=analyze_episode, args=(episode,))
                    thread.daemon = True
                    thread.start()

            stop_command_output = False

            def console_output():
                '''
                Internal Function used to display statistics during processing the images.\n
                Might be disabled and thus main function analyze_episode could be optimized for better performance but I prefer seeing what's going on. 
                '''
                total_fps = 0
                total_frames = 'N/A'
                total_frames_frame = 0
                total_frames_frames = 0
                for element in fps_dict:
                    total_fps += fps_dict[element]
                single_thread_stats = ''
                for element in frames_stats_dict:
                    total_frames_frame += frames_stats_dict[element]['frame']
                    total_frames_frames += frames_stats_dict[element]['total_frames']
                    try:
                        try:
                            thread_percentage = int(frames_stats_dict[element]['frame']) * 100 / int(frames_stats_dict[element]['total_frames'])
                            thread_percentage = round(thread_percentage, 1)
                        except:
                            thread_percentage = 'n/a'
                        try:
                            frames_per_second = str(fps_dict[element])
                        except:
                            frames_per_second = 'n/a'
                        single_thread_stats = single_thread_stats + 'Episode ' + str(element) + ': Frame ' + str(frames_stats_dict[element]['frame']) + '/' + str(int(frames_stats_dict[element]['total_frames'])) + ' (' + str(thread_percentage) + '%) ・ Analyze Speed: ' + frames_per_second + 'FPS ・ Status: ' + frames_stats_dict[element]['status'] + '\n'
                    except:
                        try:
                            thread_percentage = int(frames_stats_dict[element]['frame']) * 100 / int(frames_stats_dict[element]['total_frames'])
                            thread_percentage = round(thread_percentage, 1)
                        except:
                            thread_percentage = 'n/a'
                        single_thread_stats = single_thread_stats + 'Episode ' + str(element) + ': Frame ' + str(frames_stats_dict[element]['frame']) + '/' + str(int(frames_stats_dict[element]['total_frames'])) + ' (' + str(thread_percentage) + '%) ・ Analyze Speed: 0FPS ・ Status: Starting\n'

                try:
                    total_frames_percentage = total_frames_frame * 100 / total_frames_frames
                    total_frames_percentage = round(total_frames_percentage, 2)
                except:
                    total_frames_percentage = 'n/a'
                total_frames = str(total_frames_frame) + '/' + str(int(total_frames_frames))

                lifeeasy.sleep(0.1)
                lifeeasy.clear()
                try:
                    remaining_frames = total_frames_frames - total_frames_frame
                    remaining_time = remaining_frames / int(total_fps)
                    eta = str(timedelta(seconds=remaining_time))
                except:
                    eta = 'N/A'
                print(f'Anime: {anime}\nFrame: {total_frames} ({str(total_frames_percentage)}%)\nAnalyze Speed: {str(total_fps)}FPS\nRemaining Time (ETA): {eta[:-7]}\n\nActive Threads\nーーーーーーーーーーーー\n{single_thread_stats}\nErina Project\n©Anime no Sekai - 2020')
                if stop_command_output == False:
                    thread = threading.Thread(target=console_output)
                    thread.daemon = True
                    thread.start()

            console_output()

            lifeeasy.sleep(3)

            while queue != 0:
                lifeeasy.sleep(1)

            stop_command_output = True

            lifeeasy.sleep(3)

            print('')
            end_time = process_time()
            print('Total time: ' + str(end_time - start_time) + ' seconds')

            if '-a' not in sys.argv and '--auto' not in sys.argv and auto_analyze == False:
                print('')
                print(f'Caching AniList API with the ID {str(anilist_id)}...')
                erinacache.anilist_caching(int(anilist_id))
            print(f'{anime} has been added to the database')
def createAPIKey():
    tokenResult = createRandomID(32)
    if tokenResult + ".erina" in files_in_dir(
            erina_dir + "/ErinaServer/Erina/auth/apiAuth"):
        tokenResult = createAPIKey()
    return tokenResult
def sort_by_type():
    global number_of_moved_items
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 0%'])
    # _ are spaces
    # è are slashes (replaced by & for path compatibility)
    # Images_3D needs to be changed to 3D Images
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 1%'])

    Archives = []
    Audios = []
    Backups = []
    eBooks = []
    Database_Files = []
    Developers = []
    Disk_Images = []
    Encoded_Files = []
    ApplicationsèExecutables = []
    Fonts = []
    Images_3D = []
    Plugins = []
    PresetsèSettings = []
    Images = []
    Raw_Images = []
    ROMèGame_Files = []
    Spreadsheets = []
    System_Files = []
    Text_FilesèDocuments = []
    Vector_Images = []
    Videos = []
    Web_Documents = []
    Folders = []
    Other = []
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 2%'])

    list_of_files_in_cleaning_dir = filecenter.files_in_dir(cleaning_dir)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 5%'])
    completion = 0
    for file in list_of_files_in_cleaning_dir:
        completion += len(list_of_files_in_cleaning_dir) / 75 + 5
        lifeeasy.display_body([
            'Chosen mode: Type Sorting', 'Completion: {}%'.format(completion)
        ])
        if file == __file__:
            continue
        if file == destination_dir_name:
            continue
        file_type = filecenter.type_from_extension(
            filecenter.extension_from_base(file))
        if file_type == 'Archive':
            Archives.append(file)
        elif file_type == 'Audio':
            Audios.append(file)
        elif file_type == 'Backup':
            Backups.append(file)
        elif file_type == 'eBook':
            eBooks.append(file)
        elif file_type == 'Database File':
            Database_Files.append(file)
        elif file_type == 'Developer':
            Developers.append(file)
        elif file_type == 'Disk Image':
            Disk_Images.append(file)
        elif file_type == 'Encoded File':
            Encoded_Files.append(file)
        elif file_type == 'Application/Executable':
            ApplicationsèExecutables.append(file)
        elif file_type == 'Font':
            Fonts.append(file)
        elif file_type == '3D Image':
            Images_3D.append(file)
        elif file_type == 'Plugin':
            Plugins.append(file)
        elif file_type == 'Preset/Settings':
            PresetsèSettings.append(file)
        elif file_type == 'Image':
            Images.append(file)
        elif file_type == 'Raw Image':
            Raw_Images.append(file)
        elif file_type == 'ROM/Game File':
            ROMèGame_Files.append(file)
        elif file_type == 'Spreadsheet':
            Spreadsheets.append(file)
        elif file_type == 'System File':
            System_Files.append(file)
        elif file_type == 'Text File/Document':
            Text_FilesèDocuments.append(file)
        elif file_type == 'Vector Image':
            Vector_Images.append(file)
        elif file_type == 'Video':
            Videos.append(file)
        elif file_type == 'Web Document':
            Web_Documents.append(file)
        elif file_type == 'Folder':
            Folders.append(file)
        elif file_type == 'Document':
            Text_FilesèDocuments.append(file)
        else:
            Other.append(file)
        number_of_moved_items += 1

    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 76%'])
    if len(Archives) != 0:
        archives_path = filecenter.make_dir(destination_dir + '/Archives')
        for file in Archives:
            filecenter.move(cleaning_dir + file, archives_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 77%'])
    if len(Audios) != 0:
        Audios_path = filecenter.make_dir(destination_dir + '/Audios')
        for file in Audios:
            filecenter.move(cleaning_dir + file, Audios_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 78%'])
    if len(Backups) != 0:
        Backups_path = filecenter.make_dir(destination_dir + '/Backups')
        for file in Backups:
            filecenter.move(cleaning_dir + file, Backups_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 79%'])
    if len(eBooks) != 0:
        eBooks_path = filecenter.make_dir(destination_dir + '/eBooks')
        for file in eBooks:
            filecenter.move(cleaning_dir + file, eBooks_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 80%'])
    if len(Database_Files) != 0:
        Database_Files_path = filecenter.make_dir(destination_dir +
                                                  '/Database Files')
        for file in Database_Files:
            filecenter.move(cleaning_dir + file, Database_Files_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 81%'])
    if len(Developers) != 0:
        Developers_path = filecenter.make_dir(destination_dir + '/Developers')
        for file in Developers:
            filecenter.move(cleaning_dir + file, Developers_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 82%'])
    if len(Disk_Images) != 0:
        Disk_Images_path = filecenter.make_dir(destination_dir +
                                               '/Disk Images')
        for file in Disk_Images:
            filecenter.move(cleaning_dir + file, Disk_Images_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 83%'])
    if len(Encoded_Files) != 0:
        Encoded_Files_path = filecenter.make_dir(destination_dir +
                                                 '/Encoded Files')
        for file in Encoded_Files:
            filecenter.move(cleaning_dir + file, Encoded_Files_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 84%'])
    if len(ApplicationsèExecutables) != 0:
        ApplicationsèExecutables_path = filecenter.make_dir(
            destination_dir + '/Applications & Executables')
        for file in ApplicationsèExecutables:
            filecenter.move(cleaning_dir + file, ApplicationsèExecutables_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 85%'])
    if len(Fonts) != 0:
        Fonts_path = filecenter.make_dir(destination_dir + '/Fonts')
        for file in Fonts:
            filecenter.move(cleaning_dir + file, Fonts_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 86%'])
    if len(Images_3D) != 0:
        Images_3D_path = filecenter.make_dir(destination_dir + '/3D Images')
        for file in Images_3D:
            filecenter.move(cleaning_dir + file, Images_3D_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 87%'])
    if len(Plugins) != 0:
        Plugins_path = filecenter.make_dir(destination_dir + '/Plugins')
        for file in Plugins:
            filecenter.move(cleaning_dir + file, Plugins_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 88%'])
    if len(PresetsèSettings) != 0:
        PresetsèSettings_path = filecenter.make_dir(destination_dir +
                                                    '/Presets & Settings')
        for file in PresetsèSettings:
            filecenter.move(cleaning_dir + file, PresetsèSettings_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 89%'])
    if len(Images) != 0:
        Images_path = filecenter.make_dir(destination_dir + '/Images')
        for file in Images:
            filecenter.move(cleaning_dir + file, Images_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 90%'])
    if len(Raw_Images) != 0:
        Raw_Images_path = filecenter.make_dir(destination_dir + '/Raw Images')
        for file in Raw_Images:
            filecenter.move(cleaning_dir + file, Raw_Images_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 91%'])
    if len(ROMèGame_Files) != 0:
        ROMèGame_Files_path = filecenter.make_dir(destination_dir +
                                                  '/ROM & Game Files')
        for file in ROMèGame_Files:
            filecenter.move(cleaning_dir + file, ROMèGame_Files_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 92%'])
    if len(Spreadsheets) != 0:
        Spreadsheets_path = filecenter.make_dir(destination_dir +
                                                '/Spreadsheets')
        for file in Spreadsheets:
            filecenter.move(cleaning_dir + file, Spreadsheets_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 93%'])
    if len(System_Files) != 0:
        System_Files_path = filecenter.make_dir(destination_dir +
                                                '/System Files')
        for file in System_Files:
            filecenter.move(cleaning_dir + file, System_Files_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 94%'])
    if len(Text_FilesèDocuments) != 0:
        Text_FilesèDocuments_path = filecenter.make_dir(
            destination_dir + '/Text Files & Documents')
        for file in Text_FilesèDocuments:
            filecenter.move(cleaning_dir + file, Text_FilesèDocuments_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 95%'])
    if len(Vector_Images) != 0:
        Vector_Images_path = filecenter.make_dir(destination_dir +
                                                 '/Vector Images')
        for file in Vector_Images:
            filecenter.move(cleaning_dir + file, Vector_Images_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 96%'])
    if len(Videos) != 0:
        Videos_path = filecenter.make_dir(destination_dir + '/Videos')
        for file in Videos:
            filecenter.move(cleaning_dir + file, Videos_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 97%'])
    if len(Web_Documents) != 0:
        Web_Documents_path = filecenter.make_dir(destination_dir +
                                                 '/Web Documents')
        for file in Web_Documents:
            filecenter.move(cleaning_dir + file, Web_Documents_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 98%'])
    if len(Folders) != 0:
        Folders_path = filecenter.make_dir(destination_dir + '/Folders')
        for file in Folders:
            filecenter.move(cleaning_dir + file, Folders_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 99%'])
    if len(Other) != 0:
        Other_path = filecenter.make_dir(destination_dir + '/Other')
        for file in Other:
            filecenter.move(cleaning_dir + file, Other_path)
    lifeeasy.display_body(['Chosen mode: Type Sorting', 'Completion: 100%'])
    goodbye()
示例#10
0
def module_verification():
    global main_module
    global package_name
    if package_name == '':
        print(
            'What is the name of the module that you want to verify/package?')
        package_name = input('> ')
    try:
        lifeeasy.display_action('Verification of the module', delay=0.1)
        if filecenter.isdir(lifeeasy.working_dir() + '/' + package_name):
            if filecenter.isfile(lifeeasy.working_dir() + '/' + package_name +
                                 '/__init__.py'):
                main_module = '__init__.py'
                print("It's all good!")
            else:
                if filecenter.isfile(lifeeasy.working_dir() + '/__init__.py'):
                    main_module = '__init__.py'
                    for file in filecenter.files_in_dir(
                            lifeeasy.working_dir()):
                        if file == 'setup.py':
                            continue
                        if filecenter.extension_from_base(file) == '.py':
                            filecenter.move(
                                lifeeasy.working_dir() + file,
                                lifeeasy.working_dir() + '/' + package_name +
                                '/' + file)
                else:
                    init_file = input(
                        'Write the name of the main module file (with the extension): '
                    )
                    main_module = init_file
                    filecenter.move(
                        lifeeasy.working_dir() + '/' + init_file,
                        lifeeasy.working_dir() + '/' + package_name +
                        '/__init__.py')
                    for file in filecenter.files_in_dir(
                            lifeeasy.working_dir()):
                        if file == 'setup.py':
                            continue
                        if filecenter.extension_from_base(file) == '.py':
                            filecenter.move(
                                lifeeasy.working_dir() + file,
                                lifeeasy.working_dir() + '/' + package_name +
                                '/' + file)
            print(
                'Make sure to move all the files used by your package in the folder "'
                + package_name + '"')
            input('Press [enter] to coninue...')

        else:
            filecenter.make_dir(lifeeasy.working_dir() + '/' + package_name)
            if filecenter.isfile(lifeeasy.working_dir() + '/__init__.py'):
                main_module = '__init__.py'
                for file in filecenter.files_in_dir(lifeeasy.working_dir()):
                    if file == 'setup.py':
                        continue
                    if filecenter.extension_from_base(file) == '.py':
                        filecenter.move(
                            lifeeasy.working_dir() + file,
                            lifeeasy.working_dir() + '/' + package_name + '/' +
                            file)
            else:
                init_file = input(
                    'Write the name of the main module file (with the extension): '
                )
                main_module = init_file
                filecenter.move(
                    lifeeasy.working_dir() + '/' + init_file,
                    lifeeasy.working_dir() + '/' + package_name +
                    '/__init__.py')
                for file in filecenter.files_in_dir(lifeeasy.working_dir()):
                    if file == 'setup.py':
                        continue
                    if filecenter.extension_from_base(file) == '.py':
                        filecenter.move(
                            lifeeasy.working_dir() + file,
                            lifeeasy.working_dir() + '/' + package_name + '/' +
                            file)
            print(
                'Make sure to move all the files used by your package in the folder "'
                + package_name + '"')
            input('Press [enter] to coninue...')
        return 0
    except:
        return 1
示例#11
0
def returnStats():
    results = {}

    ### BLOCKING EACH FILE AND GETTING ITS CONTENT
    erina_stats.api.searchEndpointCall.blocking = True
    api_searchEndpointCall = erina_stats.api.searchEndpointCall.readlines()
    erina_stats.api.searchEndpointCall.blocking = False
    erina_stats.db.erinaDatabaseLookups.blocking = True
    db_erinaDatabaseLookups = erina_stats.db.erinaDatabaseLookups.readlines()
    erina_stats.db.erinaDatabaseLookups.blocking = False
    erina_stats.db.manamiDBTitleVectorLookups.blocking = True
    db_manamiDBTitleVectorLookups = erina_stats.db.manamiDBTitleVectorLookups.readlines(
    )
    erina_stats.db.manamiDBTitleVectorLookups.blocking = False
    erina_stats.discord.descriptionHit.blocking = True
    discord_descriptionHit = erina_stats.discord.descriptionHit.readlines()
    erina_stats.discord.descriptionHit.blocking = False
    erina_stats.discord.imageSearchHit.blocking = True
    discord_imageSearchHit = erina_stats.discord.imageSearchHit.readlines()
    erina_stats.discord.imageSearchHit.blocking = False
    erina_stats.discord.infoHit.blocking = True
    discord_infoHit = erina_stats.discord.infoHit.readlines()
    erina_stats.discord.infoHit.blocking = False
    erina_stats.erinahash.createdBase64String.blocking = True
    erinahash_createdBase64String = erina_stats.erinahash.createdBase64String.readlines(
    )
    erina_stats.erinahash.createdBase64String.blocking = False
    erina_stats.erinahash.createdHashes.blocking = True
    erinahash_createdHashes = erina_stats.erinahash.createdHashes.readlines()
    erina_stats.erinahash.createdHashes.blocking = False
    erina_stats.erina.cacheFilesCount.blocking = True
    erina_cacheFilesCount = erina_stats.erina.cacheFilesCount.readlines()
    erina_stats.erina.cacheFilesCount.blocking = False
    erina_stats.erina.erinaParsingCount.blocking = True
    erina_erinaParsingCount = erina_stats.erina.erinaParsingCount.readlines()
    erina_stats.erina.erinaParsingCount.blocking = False
    erina_stats.erina.errorsCount.blocking = True
    erina_errorsCount = erina_stats.erina.errorsCount.readlines()
    erina_stats.erina.errorsCount.blocking = False
    erina_stats.external.anilistAPICalls.blocking = True
    external_anilistAPICalls = erina_stats.external.anilistAPICalls.readlines()
    erina_stats.external.anilistAPICalls.blocking = False
    erina_stats.external.iqdbCalls.blocking = True
    external_iqdbCalls = erina_stats.external.iqdbCalls.readlines()
    erina_stats.external.iqdbCalls.blocking = False
    erina_stats.external.saucenaoAPICalls.blocking = True
    external_saucenaoAPICalls = erina_stats.external.saucenaoAPICalls.readlines(
    )
    erina_stats.external.saucenaoAPICalls.blocking = False
    erina_stats.external.tracemoeAPICalls.blocking = True
    external_tracemoeAPICalls = erina_stats.external.tracemoeAPICalls.readlines(
    )
    erina_stats.external.tracemoeAPICalls.blocking = False
    erina_stats.line.descriptionHit.blocking = True
    line_descriptionHit = erina_stats.line.descriptionHit.readlines()
    erina_stats.line.descriptionHit.blocking = False
    erina_stats.line.imageSearchHit.blocking = True
    line_imageSearchHit = erina_stats.line.imageSearchHit.readlines()
    erina_stats.line.imageSearchHit.blocking = False
    erina_stats.line.infoHit.blocking = True
    line_infoHit = erina_stats.line.infoHit.readlines()
    erina_stats.line.infoHit.blocking = False
    erina_stats.line.storedImages.blocking = True
    line_storedImages = erina_stats.line.storedImages.readlines()
    erina_stats.line.storedImages.blocking = False
    erina_stats.search.anilistIDSearchCount.blocking = True
    search_anilistIDSearchCount = erina_stats.search.anilistIDSearchCount.readlines(
    )
    erina_stats.search.anilistIDSearchCount.blocking = False
    erina_stats.search.imageSearchCount.blocking = True
    search_imageSearchCount = erina_stats.search.imageSearchCount.readlines()
    erina_stats.search.imageSearchCount.blocking = False
    erina_stats.search.titleSearchCount.blocking = True
    search_titleSearchCount = erina_stats.search.titleSearchCount.readlines()
    erina_stats.search.titleSearchCount.blocking = False
    erina_stats.twitter.askingHit.blocking = True
    twitter_askingHit = erina_stats.twitter.askingHit.readlines()
    erina_stats.twitter.askingHit.blocking = False
    erina_stats.twitter.directMessagingHit.blocking = True
    twitter_directMessagingHit = erina_stats.twitter.directMessagingHit.readlines(
    )
    erina_stats.twitter.directMessagingHit.blocking = False
    erina_stats.twitter.responsePolarity.blocking = True
    twitter_responsePolarity = erina_stats.twitter.responsePolarity.readlines()
    erina_stats.twitter.responsePolarity.blocking = False
    erina_stats.twitter.responses.blocking = True
    twitter_responses = erina_stats.twitter.responses.readlines()
    erina_stats.twitter.responses.blocking = False
    erina_stats.twitter.streamHit.blocking = True
    twitter_streamHit = erina_stats.twitter.streamHit.readlines()
    erina_stats.twitter.streamHit.blocking = False

    results["search"] = {}
    results["search"]["searchCount"] = {}
    results["search"]["searchCount"]["values"] = {}
    results["search"]["searchCount"]["success"] = True

    def _retrieveStats(category, subcategory, data):

        currentTime = datetime.fromtimestamp(time())

        # INIT RESULTS FOR THE CATEGORY
        if category not in results:
            results[category] = {}

        if subcategory not in results[category]:
            results[category][subcategory] = {}

        results[category][subcategory]["success"] = False
        results[category][subcategory]["values"] = {}

        if data is not None and len(data) > 0:  # IF THERE IS DATA

            #### ADDING A VALUE
            def addValue(timestamp, data=None):
                """
                Adds a value to the results
                """
                timestamp = timestamp.timestamp()
                if data is None:
                    if timestamp in results[category][subcategory]["values"]:
                        results[category][subcategory]["values"][
                            timestamp] += 1
                    else:
                        results[category][subcategory]["values"][timestamp] = 1

                    if category == "search" and subcategory in [
                            "anilistIDSearchCount", "titleSearchCount",
                            "imageSearchCount"
                    ]:
                        if timestamp in results["search"]["searchCount"][
                                "values"]:
                            results["search"]["searchCount"]["values"][
                                timestamp] += 1
                        else:
                            results["search"]["searchCount"]["values"][
                                timestamp] = 1

                elif subcategory in [
                        "manamiDBTitleVectorLookups", "erinaDatabaseLookups"
                ]:
                    if timestamp in results[category][subcategory]["values"]:
                        results[category][subcategory]["values"][
                            timestamp] += convert_to_int(
                                element.split("    ")[1])
                    else:
                        results[category][subcategory]["values"][
                            timestamp] = convert_to_int(
                                element.split("    ")[1])
                elif subcategory == "cacheFilesCount":
                    results[category][subcategory]["values"][
                        timestamp] = convert_to_int(element.split("    ")[1])
                elif subcategory == "responsePolarity":
                    if timestamp in results[category][subcategory]["values"]:
                        results[category][subcategory]["values"][
                            timestamp].append(
                                convert_to_float(element.split("    ")[1]))
                    else:
                        results[category][subcategory]["values"][timestamp] = [
                            convert_to_float(element.split("    ")[1])
                        ]

            firstElementTimestamp = returnTimestamp(data[0])
            if firstElementTimestamp is not None:
                results[category][subcategory]["success"] = True
                if firstElementTimestamp.month == currentTime.month:
                    if firstElementTimestamp.day == currentTime.day:
                        if firstElementTimestamp.hour == currentTime.hour:
                            if firstElementTimestamp.minute == currentTime.minute:
                                for element in data:
                                    try:
                                        currentTimestamp = returnTimestamp(
                                            element).replace(microsecond=0)
                                        if subcategory in [
                                                "manamiDBTitleVectorLookups",
                                                "erinaDatabaseLookups",
                                                "responsePolarity",
                                                "storedImages",
                                                "cacheFilesCount"
                                        ]:
                                            addValue(currentTimestamp, element)
                                        else:
                                            addValue(currentTimestamp)
                                    except:
                                        pass
                            else:
                                for element in data:
                                    try:
                                        currentTimestamp = returnTimestamp(
                                            element).replace(microsecond=0,
                                                             second=0)
                                        if subcategory in [
                                                "manamiDBTitleVectorLookups",
                                                "erinaDatabaseLookups",
                                                "responsePolarity",
                                                "storedImages",
                                                "cacheFilesCount"
                                        ]:
                                            addValue(currentTimestamp, element)
                                        else:
                                            addValue(currentTimestamp)
                                    except:
                                        pass
                        else:
                            for element in data:
                                try:
                                    currentTimestamp = returnTimestamp(
                                        element).replace(microsecond=0,
                                                         second=0,
                                                         minute=0)
                                    if subcategory in [
                                            "manamiDBTitleVectorLookups",
                                            "erinaDatabaseLookups",
                                            "responsePolarity", "storedImages",
                                            "cacheFilesCount"
                                    ]:
                                        addValue(currentTimestamp, element)
                                    else:
                                        addValue(currentTimestamp)
                                except:
                                    pass
                    else:
                        for element in data:
                            try:
                                currentTimestamp = returnTimestamp(
                                    element).replace(microsecond=0,
                                                     second=0,
                                                     minute=0,
                                                     hour=0)
                                if subcategory in [
                                        "manamiDBTitleVectorLookups",
                                        "erinaDatabaseLookups",
                                        "responsePolarity", "storedImages",
                                        "cacheFilesCount"
                                ]:
                                    addValue(currentTimestamp, element)
                                else:
                                    addValue(currentTimestamp)
                            except:
                                pass
                else:
                    for element in data:
                        try:
                            currentTimestamp = returnTimestamp(
                                element).replace(microsecond=0,
                                                 second=0,
                                                 minute=0,
                                                 hour=0,
                                                 day=1)
                            if subcategory in [
                                    "manamiDBTitleVectorLookups",
                                    "erinaDatabaseLookups", "responsePolarity",
                                    "storedImages", "cacheFilesCount"
                            ]:
                                addValue(currentTimestamp, element)
                            else:
                                addValue(currentTimestamp)
                        except:
                            pass
            else:
                results[category][subcategory]["success"] = False
                return False

        else:
            results[category][subcategory]["values"] = {}
            for i in range(10):
                results[category][subcategory]["values"][currentTime.replace(
                    microsecond=0, second=0, minute=0).timestamp() -
                                                         (86400 * i)] = 0
            results[category][subcategory]["success"] = True
            return False

        return True

    _retrieveStats('api', 'searchEndpointCall', api_searchEndpointCall)
    _retrieveStats('db', 'erinaDatabaseLookups', db_erinaDatabaseLookups)
    _retrieveStats('db', 'manamiDBTitleVectorLookups',
                   db_manamiDBTitleVectorLookups)
    _retrieveStats('discord', 'descriptionHit', discord_descriptionHit)
    _retrieveStats('discord', 'imageSearchHit', discord_imageSearchHit)
    _retrieveStats('discord', 'infoHit', discord_infoHit)
    _retrieveStats('erinahash', 'createdBase64String',
                   erinahash_createdBase64String)
    _retrieveStats('erinahash', 'createdHashes', erinahash_createdHashes)
    _retrieveStats('erina', 'cacheFilesCount', erina_cacheFilesCount)
    _retrieveStats('erina', 'erinaParsingCount', erina_erinaParsingCount)
    _retrieveStats('erina', 'errorsCount', erina_errorsCount)
    _retrieveStats('external', 'anilistAPICalls', external_anilistAPICalls)
    _retrieveStats('external', 'iqdbCalls', external_iqdbCalls)
    _retrieveStats('external', 'saucenaoAPICalls', external_saucenaoAPICalls)
    _retrieveStats('external', 'tracemoeAPICalls', external_tracemoeAPICalls)
    _retrieveStats('line', 'descriptionHit', line_descriptionHit)
    _retrieveStats('line', 'imageSearchHit', line_imageSearchHit)
    _retrieveStats('line', 'infoHit', line_infoHit)
    _retrieveStats('line', 'storedImages', line_storedImages)
    _retrieveStats('search', 'anilistIDSearchCount',
                   search_anilistIDSearchCount)
    _retrieveStats('search', 'imageSearchCount', search_imageSearchCount)
    _retrieveStats('search', 'titleSearchCount', search_titleSearchCount)
    _retrieveStats('twitter', 'askingHit', twitter_askingHit)
    _retrieveStats('twitter', 'directMessagingHit', twitter_directMessagingHit)
    _retrieveStats('twitter', 'responses', twitter_responses)
    _retrieveStats('twitter', 'streamHit', twitter_streamHit)
    polarityHasValue = _retrieveStats('twitter', 'responsePolarity',
                                      twitter_responsePolarity)
    if polarityHasValue:
        for key in results["twitter"]["responsePolarity"]["values"]:
            currentState = results["twitter"]["responsePolarity"]["values"][
                key]
            results["twitter"]["responsePolarity"]["values"][key] = sum(
                currentState) / len(currentState)

    animeSearchStats = {}
    for line in search_titleSearchCount:
        currentAnime = str(line.split("    ")[1]).replace("\n",
                                                          "").capitalize()
        if currentAnime in animeSearchStats:
            animeSearchStats[currentAnime] += 1
        else:
            animeSearchStats[currentAnime] = 1

    for line in search_anilistIDSearchCount:
        currentAnime = str(line.split("    ")[1])
        if isfile(erina_dir + "/ErinaCaches/AniList_Cache/" + currentAnime +
                  ".erina"):
            currentAnime = str(
                AnilistCache(
                    TextFile(erina_dir + "/ErinaCaches/AniList_Cache/" +
                             currentAnime + ".erina").read()).title)
            if currentAnime in animeSearchStats:
                animeSearchStats[currentAnime] += 1
            else:
                animeSearchStats[currentAnime] = 1

    animeSearchRank = []

    for anime in sorted(animeSearchStats,
                        key=animeSearchStats.get,
                        reverse=True):
        animeSearchRank.append({anime: animeSearchStats[anime]})

    results["animeSearchRank"] = animeSearchRank

    searchCountKeys = sorted(results["search"]["searchCount"]["values"].keys())
    finalSearchCountResult = {}
    for timestamp in searchCountKeys:
        finalSearchCountResult[timestamp] = results["search"]["searchCount"][
            "values"][timestamp]

    results["search"]["searchCount"]["values"] = finalSearchCountResult

    results["uptime"] = env_information.startTime

    #### User Defined Endpoints
    for file in files_in_dir(erina_dir + "/Erina/stats/userdefinedStats"):
        if extension_from_base(file) == ".erinalog":
            data = TextFile(erina_dir + "/Erina/stats/userdefinedStats/" +
                            file).readlines()
            _retrieveStats("userDefinedEndpoints", file[:-9], data)

    return results