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')
async def on_message(message): ''' When the bot receives a message ''' #await message.add_reaction(roger_reaction) # REACT TO SHOW THAT THE BOT HAS UNDESTAND HIS COMMAND if message.author.id == client.user.id: return if message.content.startswith('.erina'): # ERINA SPECIFIC COMMAND userCommand = utils.removeSpaceBefore(str(message.content)[6:]) commandLength = len(userCommand.split(" ")[0]) command, commandSimilarity = searchCommand( userCommand.split(" ")[0].lower()) if commandSimilarity < 0.75: await message.channel.send("Sorry, this command is not available.") return else: if command == "search": query = utils.removeSpaceBefore(userCommand[commandLength:]) log( "ErinaDiscord", "New info hit from @" + str(message.author) + " (asking for " + str(query) + ")") StatsAppend(DiscordStats.infoHit, f"{str(query)} >>> {str(message.author)}") anime, thumbnail, discordResponse = Parser.makeInfoResponse( erinasearch.searchAnime(query)) if discordResponse is not None: newEmbed = discord.Embed(title='Anime Info', colour=discord.Colour.blue()) newEmbed.add_field(name=anime.capitalize(), value=discordResponse) if thumbnail is not None: newEmbed.set_thumbnail(url=thumbnail) await message.channel.send(embed=newEmbed) else: await message.channel.send( "An error occured while searching for your anime: " + query) elif command == "description": query = utils.removeSpaceBefore(userCommand[commandLength:]) log( "ErinaDiscord", "New description hit from @" + str(message.author) + " (asking for " + str(query) + ")") StatsAppend(DiscordStats.descriptionHit, f"{str(query)} >>> {str(message.author)}") anime, thumbnail, discordResponse = Parser.makeDescriptionResponse( erinasearch.searchAnime(query)) if discordResponse is not None: newEmbed = discord.Embed( title=f'Anime Description: {str(anime)}', colour=discord.Colour.blue()) newEmbed.add_field(name=anime.capitalize(), value=discordResponse) if thumbnail is not None: newEmbed.set_thumbnail(url=thumbnail) await message.channel.send(embed=newEmbed) else: await message.channel.send( "An error occured while searching for your anime: " + query) elif command == "dev": await StaticResponse.erinadev(message.channel) elif command == "donate": await StaticResponse.erinadonate(message.channel) elif command == "help": await StaticResponse.erinahelp(message.channel, message.author) elif command == "stats": await StaticResponse.erinastats(message.channel, client) elif command == "invite": await StaticResponse.erinainvite(message.channel) else: if any([ flag in str(message.content).lower() for flag in (config.Discord.flags if str(config.Discord.flags). replace(" ", "") not in ["None", "", "[]"] else config.Erina.flags) ]): listOfResults = [] #await message.add_reaction(roger_reaction) # REACT TO SHOW THAT THE BOT HAS UNDESTAND HIS COMMAND log("ErinaDiscord", "New image search from @" + str(message.author)) StatsAppend(DiscordStats.imageSearchHit, f"{str(message.author)}") for file in message.attachments: if filecenter.type_from_extension( filecenter.extension_from_base(file.filename) ) == 'Image': # If the file is an image current_anime = Parser.makeImageResponse( erinasearch.imageSearch( file.url)) # Get infos about the anime listOfResults.append( current_anime) # Append to the results list else: message_history = await message.channel.history( limit=5 ).flatten() # Search from the last 3 messages a picture for message in message_history: for file in message.attachments: if filecenter.type_from_extension( filecenter.extension_from_base(file.filename) ) == 'Image': # If the file is an image current_anime = Parser.makeImageResponse( erinasearch.imageSearch( file.url)) # Get infos about the anime listOfResults.append( current_anime) # Append to the results list if len(listOfResults) == 0: await message.channel.send("Sorry, I couldn't find anything..." ) elif len(listOfResults) == 1: title, thumbnail, reply = listOfResults[0] if reply is None: await message.channel.send( "An error occured while retrieving information on the anime..." ) await message.channel.send(f"It seems to be {title}!") newEmbed = discord.Embed(title='Anime Info', colour=discord.Colour.blue()) newEmbed.add_field(name=title.capitalize(), value=reply) if thumbnail is not None: newEmbed.set_thumbnail(url=thumbnail) await message.channel.send(embed=newEmbed) await asyncio.sleep(1) else: for iteration, result in enumerate(listOfResults): number = '' if iteration == 0: number = '1st' elif iteration == 1: number = '2nd' elif iteration == 2: number = '3rd' else: number = f'{str(iteration)}th' title, thumbnail, reply = result if reply is None: await message.channel.send( f"An error occured while searching for the {number} anime" ) await message.channel.send( f"The {number} anime seems to be {title}!") newEmbed = discord.Embed(title='Anime Info', colour=discord.Colour.blue()) newEmbed.add_field(name=title.capitalize(), value=reply) if thumbnail is not None: newEmbed.set_thumbnail(url=thumbnail) await message.channel.send(embed=newEmbed) await asyncio.sleep(1) return
def episode_from_filename(filename, anime_title='', list_of_alternative_titles=[]): """ Extracting an anime episode number from a filename. Erina Project\n © Anime no Sekai - 2020 """ # removing the file extension file_extension = filecenter.extension_from_base(filename) episode = filename.replace(file_extension, '') # replacing the title by nothing episode = episode.replace(anime_title, '') # replacing alternative titles by nothing for title in list_of_alternative_titles: episode = episode.replace(title, '') # data list_of_anime_raw_team = [ 'Ohys-Raws', 'Abystoma', 'VCB-Studio', 'Snow-Raws', 'Fullmetal', 'Shark-Raws', 'FY-Raws', 'LowPower-Raws', 'Moe-Raws', 'Moozzi2', 'JKG', 'Okay-Raws', 'Centaurea-Raws', 'Anime Land', 'Cornflower Studio', 'BeatZ', 'jibaketa', 'Pandoratv-raws', 'FumeiRaws', 'Chilled', 'Renascent', 'UCCUSS', 'ReinForce', '◯PMan', 'PPP-Raws', 'Squirrel', 'YuushaNi', 'meow', 'tribute', 'tG1R0', 'Kentaraws', 'hworm', 'Bastard-Raws', 'DDD', 'Beatrice-Raws', 'TardRaws', 'KTXP', 'Leopard-Raws' ] list_of_unwanted_digits = [ '1280x720', '720', '1280', '1920', '1080', '1920x1080', 'x264', '10 bits', 'bs11', '720p', '1080p', '10bits', 'x265', 'x.265', 'x.264', 'x2', 'x1', 'x3', 'hi10p', '10p', 'eac3', '10bit', '10 bit', '110c26b0', '640x480', '640', '480', '480p', 'yuv420p10', 'p10', '420', 'h265', 'h264', '1920x1036', '1036', 'mpeg2', 'mpeg4', '1440', '1440x1080', 'ac3', '486p', 'Part 1', 'Part 2', 'Part 3', 'Part 4', 'Part 5', 'Part 6', 'Part 7', 'Part 8', 'Part 9', 'Part 10', 'of 1', 'of 2', 'of 3', 'of 4', 'of 5', 'of 6', 'of 7', 'of 8', 'of 9', 'of 10', ] video_extensions = [ 'arcut', 'prproj', 'aep', 'wot', 'swf', 'pz', 'dmx', 'mkv', 'psv', 'sfd', 'piv', 'fcp', 'mp4', 'rmvb', 'veg', 'sfvidcap', 'ncor', 'vem', 'd2v', 'wmmp', 'm1v', 'viv', 'izz', 'ale', 'cpvc', 'mpv', 'ser', 'bk2', 'jtv', 'webm', 'meta', 'aec', 'wlmp', 'mswmm', 'msdvd', 'rec', 'bik', 'dcr', 'scm', 'mxf', 'srt', 'wpl', 'scm', 'dir', 'dzm', 'fbr', 'db2', 'str', 'vtt', 'dcr', 'amc', 'dmsm', 'rcd', 'wmv', 'aepx', '3gp', 'mj2', 'dpa', 'camproj', 'vob', 'vp6', 'mpeg', 'bin', 'ts', 'mpv2', 'mk3d', 'm15', 'sbt', 'pac', 'ifo', 'hdmov', 'mp4infovid', 'video', 'avi', 'vid', 'mani', 'asf', 'swi', 'photoshow', 'kdenlive', 'ssf', 'trec', 'pns', 'mvd', 'psh', 'rms', 'trp', 'dat', 'aaf', 'aegraphic', 'amx', 'flv', 'mpg', 'gts', 'zmv', 'ismv', '3gp2', 'flc', 'vpj', 'vsp', 'usm', 'siv', 'rum', 'mpeg4', 'm2ts', 'tvshow', 'swt', 'wvm', '264', 'mse', 'evo', 'rcut', 'rm', 'dxr', 'mts', 'cine', 'wp3', 'f4p', 'avchd', 'gvi', 'sbk', 'm2t', 'pds', 'scc', 'mproj', 'dv4', 'mvp', 'pmf', 'mp4v', 'vro', 'playlist', 'dmsm3d', 'dream', 'mob', 'tpd', 'aqt', 'dzt', 'ivr', 'rdb', 'smv', 'tix', 'dav', 'mnv', 'movie', '264', 'm2p', 'mmv', 'm4v', 'mov', 'cpi', 'gfp', 'dzp', 'stx', 'h264', 'dvr', '3g2', 'ircp', 'avv', 'screenflow', 'cst', 'axv', 'vc1', 'qtch', 'lvix', 'inp', 'awlive', 'ffd', 'camv', 'bnp', 'izzy', 'avb', 'wcp', 'fbr', 'mys', 'm75', 'dmb', 'avs', 'vr', 'sbz', 'zm3', 'mpe', 'camrec', 'xvid', 'ogv', 'vp3', 'mp2v', '3mm', '60d', 'tp', 'dash', 'hevc', 'bsf', 'kmv', 'f4v', 'bu', 'yuv', 'vgz', 'psb', '3gpp', 'exo', 'wm', 'g2m', 'vep', 'osp', 'ddat', 'spl', '890', 'bdmv', 'dvr-ms', 'dv', 'r3d', 'jdr', 'sfera', 'ism', 'mvp', 'xml', 'moi', 'mvex', 'sqz', 'hdv', 'dck', 'int', 'jss', 'qtl', 'smk', 'n3r', 'dnc', 'm4u', '3gpp2', 'aetx', 'rsx', 'tsp', 'mp21', 'rmd', 'mgv', 'lrv', 'rv', 'divx', 'k3g', 'ogx', 'f4m', 'mtv', 'lrec', 'wmd', 'clpi', 'roq', 'cme', 'snagproj', 'mve', 'bdt3', 'g64', '3p2', 'lsx', 'mpeg2', 'vcr', 'flic', 'dv-avi', 'rmp', 'qtz', 'tvs', 'fli', 'm2a', 'tsv', 'mpeg1', 'xesc', 'vcpf', 'moov', 'ivf', 'tdt', 'v264', 'ced', 'dmsd', 'f4f', 'wmx', 'dpg', 'nfv', 'wvx', 'ogm', 'xmv', 'wxp', 'irf', 'arf', 'nvc', '787', 'wtv', 'ajp', 'ftc', 'mpl', 'mjp', 'bdm', 'asx', 'tivo', 'theater', 'dvx', 'd3v', 'vivo', 'cvc', 'm4e', 'ssm', 'mjpg', 'nsv', 'msh', 'm21', 'ave', 'vse', 'imovielibrary', 'movie', 'avp', 'san', 'bvr', 'jmv', 'otrkey', 'dvdmedia', 'mpsub', 'crec', 'tda3mt', 'avd', 'nuv', 'vlab', 'pgi', 'rcrec', 'smil', 'wfsp', 'sec', 'zeg', 'prel', 'vcv', 'vbc', 'sdv', 'rvid', 'vdr', 'ttxt', 'g64x', 'sedprj', 'orv', 'rvl', 'plproj', 'jts', 'mpgindex', 'xlmv', 'ismc', 'cmproj', 'prtl', 'ppj', 'cmmtpl', 'pxv', 'fpdx', 'tod', 'evo', 'zm1', 'zm2', 'flh', 'gom', 'axm', 'm21', 'mt2s', 'gifv', 'mvc', 'y4m', 'box', 'gxf', 'par', 'edl', 'w32', 'rmd', 'm2v', 'mod', 'amv', 'qt', 'xel', 'av', 'viewlet', 'qtm', 'yog', 'am', 'wsve', 'thp', 'pvr', 'clk', 'vp7', 'pssd', 'bmk', 'tpr', 'fcproject', 'gcs', 'm1pg', 'seq', 'vdx', 'aet', 'vdo', 'fcarch', 'blz', 'byu', 'sec', 'vfw', 'mpl', 'tvlayer', 'bmc', 'vs4', 'proqc', 'imovieproj', 'scn', 'anim', 'mpg4', 'mpls', 'smi', 'modd', 'hkm', 'tp0', 'nut', 'cmrec', 'gl', 'qsv', 'rmv', 'mqv', 'cmmp', 'usf', 'aecap', 'ismclip', 'pro', 'imovieproject', 'dmss', 'iva', 'bix', 'ffm', 'xej', 'insv', 'svi', 'xfl', 'rcproject', 'ezt', 'vf', 'mpg2', 'ivs', 'lsf', 'fvt', 'cip', 'imoviemobile', 'fbz', 'dce', 'avm', 'exp', 'stl', 'vix', 'tdx', 'eyetv', 'ravi', 'avs', 'moff', 'smi', 'mp21', 'gvp', 'vfz', 'rp', 'bik2', 'pjs', 'bdt2', 'qtindex', 'mxv', 'rts', 'cx3', 'dmsd3d', 'ktn', 'pro4dvd', 'pro5dvd', 'mvb', 'mvy', 'dad', 'mjpeg', 'tvrecording', 'anx', 'ntp', 'vmlf', 'avr', 'wgi', 'pva', 'dif', 'mpf', 'eye', 'tid', 'vmlt', 'sml', 'dlx', 'flx', 'bs4', 'cmv', 'jnr', 'vsh', 'av3', 'avc', 'grasp', 'vft', 'cel', 'pmv', 'dsy', 'rts' ] ### this list of video extensions comes from my python module filecenter. audio_extensions = [ 'sdt', 'amxd', 'minigsf', 'nbs', 'fev', 'pcg', 'mp3', 'flp', 'rns', 'ply', 'rgrp', 'bun', '4mp', 'apl', 'band', 'aimppl', 'wow', '5xe', 'ust', 'xfs', 'nkm', 'dm', 'mui', 'mscx', 'nki', 'rex', 'l', 'flac', 'sfk', 'm4r', 'sf2', 'bww', 'toc', 'ovw', 'omx', 'mmlp', 'mti', 'sng', 'phy', 'rmj', 'qcp', 'ftmx', 'pek', 'h5b', 'vsq', 'h5s', 'vpw', 'omg', 'cgrp', 'vyf', 'f4a', 'bidule', 'isma', 'mtm', 'caff', 'wus', 'efs', 'trak', 'igp', 'gsf', 'itls', 'wproj', 'rol', 'sbi', 'sds', 'dsm', 'slp', 'zpa', 'afc', 'dmse', 'dmsa', 'mdr', 'cwb', 'omf', 'syw', 'sngx', 'gsm', 'sph', 'mmpz', 'als', 'dtm', 'aup', 'm3u', 'dff', 'vdj', 'gp5', 'wfp', 'mka', 'mid', 'uax', 'asd', 'vlc', 'aud', 'ang', 'tg', 'saf', 'sdat', 'wav', 'flm', 'abm', 'dcf', 'sty', 'w01', 'ogg', 'mscz', 'dsf', 'midi', 'sfpack', 'oma', 'alc', 'rip', 'sfl', 'act', 'm4a', 'copy', 'kt3', 'uni', 'acd-zip', 'mtf', 'pla', 'wpk', 'emx', 'pcast', 'ckb', 'sgp', 'mux', 'm3u8', 'ac3', 'rx2', 'vsqx', 'gpk', 'ptx', 'sesx', 'ftm', 'frg', 'sd', 'uw', 'pandora', 'cdo', 'q1', 'ram', 'stm', 'logic', 'oga', 'mo3', 'emd', 'wax', 'acm', 'ds', 'wma', 'pts', 'dct', 'iti', 'ptt', 's3i', 'ncw', 'kmp', 'sd', 'vgm', 'ins', 'rmx', 'cwt', 'f32', 'mpu', 'akp', 'vag', 's3m', 'pkf', '3ga', 'bnk', 'sib', 'rso', 'aac', 'aif', 'mtp', 'amr', 'abc', 'cdr', 'aa3', 'acd', 'opus', 'at3', 'b4s', 'wrk', 'vmd', '669', 'dfc', 'ins', 'mus', 'syx', 'xspf', 'dra', 'vqf', 'svd', 'caf', 'mod', 'gbs', 'cda', 'vox', 'iff', 'odm', 'mmm', 'mx3', 'acp', 'lof', 'mx5template', 'wvc', 'amf', 'rcy', 'ppcx', 'h0', 'sbg', 'rta', 'ssnd', 'nml', 'nkx', 'wfm', 'gpbank', 'cdda', 'sseq', 'agm', 'vpl', 'dtshd', 'mbr', 'bdd', 'sxt', 'g726', 'emp', 'ptxt', 'psm', 'logicx', 'rti', 'ptm', 'wave', 'conform', 'cwp', 'sng', 'mxl', 'aob', 'mpa', 'mogg', 'med', 'a2m', 'aiff', 'wtpt', 'bwg', 'cidb', 'cts', 'm4b', 'gpx', 'fsb', 'sns', 'vip', 'wpp', 'ra', 'shn', 'xm', 'smf', 'nwc', 'wve', 'okt', 'yookoo', 'ics', 'w64', 'syh', 'gsflib', 'zvd', 'pk', 'nra', 'xa', 'nrt', 'fpa', 'sou', 'miniusf', 'xrns', 'aa', 'wem', 'dss', 'csh', 'dig', 'fdp', 'tak', 'cpr', 'musx', 'mus', 'swa', 'npl', 'tak', 'igr', 'aria', 'uwf', 'agr', 'dvf', 'mpga', 'lwv', 'mpdp', 'mx5', 'myr', 'mu3', 'krz', 'rsn', 'smp', 'nvf', 'wv', 'kar', 'u', 'peak', 'nkc', 'ape', 'brstm', 'acd-bak', 'cfa', 'dls', 'dts', 'vpm', 'mmf', 'sc2', 'hbe', 'vmo', 'pca', 'g721', 'stap', 'gig', 'ssm', 'vc3', 'fzv', 'lso', 'mdc', 'fzf', 'ds2', 'm5p', 'efv', 'nsa', 'pna', 'usflib', 'wfb', 'obw', 'ab', 'ntn', 'sppack', 'narrative', 'gbproj', 'amz', 'jam', 'cdlx', 'note', 'au', 'raw', 'k26', 'mt2', 'ksc', 'rmi', 'voxal', 'smp', 'sprg', 'sseq', 'h4b', 'm4p', 'msmpl_bank', 'hsb', 'groove', 'esps', 'psf', 'sma', 'sap', 'ftm', 'dcm', 'efk', 'drg', 'bwf', 'hca', 'efq', 'f2r', 'koz', 'koz', 'tta', 'wut', 'xmu', 'song', 'ma1', 'cws', 'sfz', 'f3r', 'seq', 'aax', 'vb', 'mxmf', 'ksf', '5xb', 'rfl', 'mts', 'ots', 'mmp', 'a2b', '8svx', 'adt', 'ptf', 'nmsv', 'mpc', 'pno', 'usf', 'avastsounds', 'pac', 'rng', 'adg', 'xmf', 'syn', 'ove', 'snd', 'vpr', 'adv', 'vrf', 'sbk', 'voc', 'dmc', 'prg', 'r1m', 'rbs', 'psy', 'expressionmap', 'vtx', 'ovw', 'dewf', 'la', '5xs', 'its', 'mp2', 'g723', 'all', 'slx', 'fsc', 'ppc', 'vgz', 's3z', 'rvx', 'kpl', 'bap', 'mgv', 'ult', 'zpl', 'nkb', 'a2i', 'pho', 'aifc', 'stx', 'kfn', 'psf1', 'mux', 'vap', 'h5e', 'adts', 'f64', 'sd2f', 'snd', 'dwd', 'wfd', 'ofr', 'rbs', 'sfs', 'efa', 'sfap0', 'mx4', 'wtpl', 'wwu', 'td0', 'minipsf2', 'psf2', 'ariax', 'iaa', 'xsp', 'rts', 'nks', 'fsm', 'ses', 'smpx', 'ams', 'svx', 'df2', 'ay', 'rax', 'exs', 'pvc', 'cpt', 'mte', 'ckf', 'dmf', 'scs11', 'ptcop', 'jspf', 'sd2', 'ams', 'hdp', 'cel', 'snd', 'txw', 'minipsf', 'vmf', 'msv', 'pbf', 'vmf' ] ### this list of audio extensions comes from my python module filecenter. list_of_years = [ 1950, 1951, 1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959, 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, 2032, 2033, 2034, 2035, 2036, 2037, 2038, 2039, 2040, 2041, 2042, 2043, 2044, 2045, 2046, 2047, 2048, 2049, 2050 ] # lowercase everything for a more efficient search episode = episode.lower() # iterating and replacing by nothing content of lists for team in list_of_anime_raw_team: episode = episode.replace(team.lower(), '') for unwanted in list_of_unwanted_digits: episode = episode.replace(unwanted, '') for extension in video_extensions: episode = episode.replace(extension, '') for extension in audio_extensions: episode = episode.replace(extension, '') for year in list_of_years: episode = episode.replace(str(year), '') types = [ 'OVA', 'OAD', 'SP', 'OP', 'ED', 'NCOP', 'NCED', 'EX', 'CM', 'PV', 'Preview', 'Yokoku', 'メニュー', 'Menu', 'エンディング', 'Movie', '予告', 'OPENING', 'opening', 'Opening', 'ENDING', 'Ending', 'ending' ] found_type = '' for element in types: if element.lower() in episode: found_type = element break # deleting everything other than digit episode = re.sub('[^0123456789一二三四五六七八九十]', '', episode) episode_without_kanjis = re.sub('[^0123456789]', '', episode) episode_without_digits = re.sub('[^一二三四五六七八九十]', '', episode) if len(episode_without_digits) != 0 and len(episode_without_kanjis) == 0: episode = str(kanjis_to_digit(episode_without_digits)) if found_type != '': episode = str(found_type) + ' ' + str(episode) if episode == '': return '0' return episode
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()
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
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