def print_stats(self): if self.num_logins > 0: print_info("\nSUMMARY ----------------------------------------------------\n") print_info("Total logins: {0}\n".format(self.num_logins)) self.print_usage_stats(self.num_logins, self.types_usage) self.print_top10(self.passwords_usage) self.print_most_common_lengths(self.lengths_usage)
def delete_all_dms(api, logging, testing): print_info("Deleting sent direct messages...") sent = api.sent_direct_messages(count=API_LIMIT) delete_group_dms(api, sent, "sent", logging, testing) received = api.direct_messages(count=API_LIMIT) print_info("Deleting received messages...") delete_group_dms(api, received, "received", logging, testing)
def delete_group_dms(api, raw_dms, type, logging, testing): dms = [] for dm in raw_dms: dms.append(DM(dm.id, dm.text)) num_deleted = delete_dm(api, dms, logging, testing) print_info("{0} {1} direct messages deleted".format(num_deleted, type))
def print_frequency(frequency, total_chars): sorted_frequencies = sorted(frequency, key=frequency.get, reverse=True) print_info("Frequency:") for item in sorted_frequencies: item_frequency_percentage = float( (frequency[item] * 100.0) / total_chars) print_info(" '{0}': {1} ({2:.2f}%)".format(item, frequency[item], item_frequency_percentage))
def check_config(): config_ok = True print_info("Checking config...") if CONSUMER_KEY == "" or CONSUMER_SECRET == "" or ACCESS_TOKEN == "" or ACCESS_TOKEN_SECRET == "": config_ok = False return config_ok
def rename_subtitles(subtitles, path, testing): renamed_subtitles = False for subtitle in subtitles: current_subtitle = Subtitle(path, subtitle, testing) if current_subtitle.new_file_name and (current_subtitle.file_name != current_subtitle.new_file_name): renamed_subtitles = True if not renamed_subtitles: print_info("No subtitles renamed")
def exit_signal_handler(signal, frame): """" exit_signal_handler(signal, frame) Handles an exit signal. Arguments: signal: (int) number of signal. frame: (string) name of the signal handler. """ condition_messages.print_info("Stopped") exit(0)
def rename_videos(videos, path, testing): renamed_videos = False for video in videos: current_video = Video(path, video, testing) if current_video.new_file_name and (current_video.file_name != current_video.new_file_name): renamed_videos = True if not renamed_videos: print_info("No videos renamed")
def delete_ids(api, tweet_ids, testing, logging): tweets = [] print_info("Deleting tweets by ID...") for tweet_id in tweet_ids: tweets.append(Tweet(tweet_id)) num_deleted = delete_tweets(api, tweets, testing, logging) print_info("{0} tweets deleted".format(num_deleted))
def print_most_common_lengths(self, lengths): """ printMostCommonLen(lengths) Displays most common lengths usage. Arguments: lengths: (dictionary) Lengths dictionary. """ if len(lengths) > 0: most_length_usage = collections.Counter(self.lengths_usage).most_common(1)[0] print_info("\nMost length usage: {0} chars ({1} times)".format(most_length_usage[0], most_length_usage[1]))
def delete_blacklisted(api, testing, logging): print_info("Deleting blacklisted tweets...") if os.path.isfile(ARCHIVE): blacklist = parse_archive() if blacklist: num_deleted = delete_tweets(api, blacklist, testing, logging) print_info("{0} tweets deleted".format(num_deleted)) else: handle_error("{0} not found".format(ARCHIVE), True)
def move(destinations, testing): """ move(destinies, bulk_move, debugging, testing) Move the series to the known disks for store tv shows. Arguments: destinations: (string list) Destiny directories. testing: (boolean) Indicates if the program is in testing mode. """ files_moved = False non_existent_paths = [] time_ini = time.clock() for show_path in SHOWS_PATHS: for destination in destinations: print_header(destination, testing) if os.path.isdir(show_path): files = os.listdir(show_path) for f in files: this_file = File(show_path, f) if this_file.is_well_formatted(): files_moved = True if destination not in FINAL_DISKS: file_dest = os.path.join(destination, this_file.file_name) mv(this_file.original_path, file_dest, testing) else: file_dest = Path(f, destination, testing) if file_dest.final_destination: mv(this_file.original_path, file_dest.final_destination, testing) else: nonexistent_path = os.path.join( show_path, file_dest.show_name) non_existent_paths = list_handler.append_non_repeated( nonexistent_path, non_existent_paths) else: print_error("{0} is not a valid path.".format(show_path)) if files_moved: for path in non_existent_paths: print_info("\n\n{0} does not exist.".format(path)) time_end = time.clock() total_time = time_end - time_ini print_time(total_time) else: print_info("No files moved.")
def move(destinations, testing): """ move(destinies, bulk_move, debugging, testing) Move the series to the known disks for store tv shows. Arguments: destinations: (string list) Destiny directories. testing: (boolean) Indicates if the program is in testing mode. """ files_moved = False non_existent_paths = [] time_ini = time.clock() for show_path in SHOWS_PATHS: for destination in destinations: print_header(destination, testing) if os.path.isdir(show_path): files = os.listdir(show_path) for f in files: this_file = File(show_path, f) if this_file.is_well_formatted(): files_moved = True if destination not in FINAL_DISKS: file_dest = os.path.join(destination, this_file.file_name) mv(this_file.original_path, file_dest, testing) else: file_dest = Path(f, destination, testing) if file_dest.final_destination: mv(this_file.original_path, file_dest.final_destination, testing) else: nonexistent_path = os.path.join(show_path, file_dest.show_name) non_existent_paths = list_handler.append_non_repeated(nonexistent_path, non_existent_paths) else: print_error("{0} is not a valid path.".format(show_path)) if files_moved: for path in non_existent_paths: print_info("\n\n{0} does not exist.".format(path)) time_end = time.clock() total_time = time_end - time_ini print_time(total_time) else: print_info("No files moved.")
def _load_modules(plugins): try: loaded_modules = [] for plugin in plugins: plugin_name = os.path.splitext(plugin)[0] plugins_module = ".get_subs_plugins" plugin_relative_path = "{0}.{1}".format(plugins_module, plugin_name) plugin_loaded = importlib.import_module(plugin_relative_path, __package__) loaded_modules.append(plugin_loaded) print_info("\t+ {0} loaded".format(plugin_name)) return loaded_modules except Exception as e: print_exception(e)
def print_top10(self, passwords): """ print_top_10(passwords) Displays Top 10 most used passwords. Arguments: passwords: (dictionary) Password dictionary. """ if len(passwords) > 0: i = 1 print_info("Top 10 used passwords:") top10 = collections.Counter(self.passwords_usage).most_common(10) for pair in top10: print_info("\t{0}) {1} ({2} times)".format(i, pair[0], pair[1])) i = i + 1
def parse_archive(): blacklist = [] try: print_info("Parsing archive...") archive = open(ARCHIVE, "r") reader = csv.reader(archive, delimiter=ARCHIVE_DELIMITER, quotechar=ARCHIVE_QUOTECHAR) for row in reader: tweet = Tweet(row[0], row[5]) if tweet.isBlackListed: blacklist.append(tweet) return blacklist except Exception as e: handle_exception(parse_archive.__name__, e)
def _exists(self): """ _exists(self) Checks if file exists. """ file_exists = False # Check if target data file is a directory # It happens in the real world... if os.path.isdir(self.file_name): print_info('{0} is a dir.'.format(self.file_name)) # Create another data file self.file_name = 'pdfMetadataLog' if os.path.exists(self.file_name): print_info('{0} already exists.'.format(self.file_name)) file_exists = True return file_exists
def check_for_subtitles(videos, subtitles, path, testing): name_pattern = re.compile("^[\w ()]*", re.UNICODE) subtitles_found = False print_info("Checking for subtitles") for video in videos: if OV_STRING in video: match = name_pattern.search(video) if match: video_name = match.group(0) video_name = video_name.replace(OV_STRING, "") video_name = video_name.strip() video_extension = os.path.splitext(video)[1] for subtitle in subtitles: subtitle_original_name = os.path.splitext(subtitle)[0] match = name_pattern.search(subtitle_original_name) if match: subtitle_name = match.group(0).strip() if video_name == subtitle_name: subtitles_found = True new_video_name = subtitle_original_name + video_extension subtitles.remove(subtitle) current_video_path = os.path.join(path, video) new_video_path = os.path.join(path, new_video_name) mv(current_video_path, new_video_path, testing) break if not subtitles_found: print_info("No subtitles found.\n")
def suggest_cipher(symbols, text): cipher = None if ' ' not in text: if symbols == 2: if is_binary(text): cipher = get_instance_of("binary") else: cipher = get_instance_of("baconian") if len(text) == 64: cipher = get_instance_of("base64") else: if symbols == 5 or symbols == 6: cipher = get_instance_of("polybius") if symbols == 25: cipher = "Playfair, Foursquare, Bifid" print_info("Suggested cipher(s): {0}".format(cipher)) if cipher: cipher.print_info()
def play(self, url): try: print_info("Using " + self.name) print_info("Playing {0}".format(url)) command = "{0} \"{1}\"".format(self._get_command(), url) # devnull = open(os.devnull, 'w') p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) p.wait() out, error = p.communicate() if error: handle_error(str(error, ENCODING), False) if out: return str(url.strip(), ENCODING) except Exception as e: handle_exception(e)
def print_usage_stats(total, total_types): """ print_usage_stats(total) Prints the results of the statistical analysis. Arguments: total: (int) total of parsed lines. total_types: (int) total of types. """ very_weak = total_types[SecurityLevel.very_weak] weak = total_types[SecurityLevel.weak] medium = total_types[SecurityLevel.medium] blank = total_types[SecurityLevel.blank] blank_percent = (blank * 100) / total vweak_percent = (very_weak * 100) / total weak_percent = (weak * 100) / total medium_percent = (medium * 100) / total print_info("Blank passwords: {0} ({1:0.2f}%)".format(blank, blank_percent)) print_info("Very weak passwords: {0} ({1:0.2f}%)".format(very_weak, vweak_percent)) print_info("Weak passwords: {0} ({1:0.2f}%)".format(weak, weak_percent)) print_info("Medium passwords: {0} ({1:0.2f}%)\n".format(medium, medium_percent))
def load_plugins(): loaded_modules = [] base_path = os.getcwd() plugins_path = os.path.join(base_path, "application", "get_subs_plugins") print_info("Loading plugins...") if os.path.exists(plugins_path): plugins = _get_plugins(plugins_path) if plugins and len(plugins) > 0: loaded_modules = _load_modules(plugins) print_info("Plugins loaded") else: print_info("No plugins found to download subtitles") else: print_error("Plugins not found") return loaded_modules
def download(self, file_name): # Should return the result of find and download a file (true/false) print_info("\tSearching for {0} in {1}...".format(file_name, self.name, self.url))
parser.add_argument('-c', '--special', dest='special_chars', action='store_true', help='Includes special chars into the analysis') args = parser.parse_args() text = args.text include_spaces = args.spaces include_special_chars = args.special_chars total_chars = 0 total_symbols = 0 frequency = {} clear_screen() condition_messages.print_info("Analyzing: {0}\n".format(" ".join(text))) for word in text: for char in word: if (char not in SPECIAL_CHARS) or (char in SPECIAL_CHARS and include_special_chars): increment(frequency, char) total_chars = total_chars + 1 if include_spaces: increment(frequency, ' ') total_chars = total_chars + 1 total_symbols = len(frequency) condition_messages.print_info("Total chars: {0}".format(total_chars)) condition_messages.print_info("Chars used: {0}\n".format(total_symbols)) print_frequency(frequency, total_chars)
def print_info(self): print_info("Suggested cipher(s): {0}".format(self.name))
def download(self, file_name): # Should return the result of find and download a file (true/false) print_info("\tSearching for {0} in {1}...".format( file_name, self.name, self.url))
total_files = total_files + 1 metadata = get_metadata(argument) if metadata: analyzed_files = analyzed_files + 1 if log_txt: log_txt.write(metadata) if log_csv: log_csv.write(metadata) elif os.path.isdir(argument): analyzed_files, total_files = scan( argument, analyzed_files, total_files, log_txt, log_csv) else: print_error( '{0} is not a valid PDF file or a existing directory.'.format(argument)) if log_txt: print_info('Saved to: {0}'.format(log_txt.file_name)) if log_csv: print_info('Saved to: {0}'.format(log_csv.file_name)) print_info( 'Analyzed files: {0}/{1}'.format(analyzed_files, total_files)) else: print_error('Requires Python {0}'.format(REQUIRED_PYTHON_VERSION)) exit(0)
help="Deletes *ALL* the direct messages") parser.add_argument("-u", "--unfollow", metavar="USER", nargs="+", help="Users to unfollow") parser.add_argument("-id", nargs="+", help="Tweet IDs to delete") args = parser.parse_args() testing = args.testing logging = args.logging clear_screen() interpreter_version = get_interpreter_version() if interpreter_version == REQUIRED_PYTHON_VERSION: clear_screen() print_info("CleanTweetsGood") if check_config(): print_info("Log in...") auth = login() api = get_api(auth) if args.delete_blacklist: delete_blacklisted(api, logging, testing) if args.delete_dms: delete_all_dms(api, logging, testing) if args.unfollow: unfollow(api, args.unfollow)
interpreter = get_interpreter_version() if interpreter == REQUIRED_PYTHON_VERSION: parser = argparse.ArgumentParser( description='Download subtitles for shows') parser.add_argument('files', metavar='files', nargs='*', help='files to download subtitles') parser.add_argument('-l', '--lang', help='subtitles language') args = parser.parse_args() print_info("Getting subtitles") if args.files: video_files = _get_video_files_from_args(args.files) else: video_files = _get_shows_paths_files() if len(video_files) > 0: plugins_loaded = load_plugins() if plugins_loaded: print_info("Downloading subtitles...") for f in video_files: subtitle_found = False
if __name__ == "__main__": video_files = [] signal.signal(signal.SIGINT, exit_signal_handler) interpreter = get_interpreter_version() if interpreter == REQUIRED_PYTHON_VERSION: parser = argparse.ArgumentParser(description='Download subtitles for shows') parser.add_argument('files', metavar='files', nargs='*', help='files to download subtitles') parser.add_argument('-l', '--lang', help='subtitles language') args = parser.parse_args() print_info("Getting subtitles") if args.files: video_files = _get_video_files_from_args(args.files) else: video_files = _get_shows_paths_files() if len(video_files) > 0: plugins_loaded = load_plugins() if plugins_loaded: print_info("Downloading subtitles...") for f in video_files: subtitle_found = False
parser = argparse.ArgumentParser(description="Analyzes a plain text dictionary file for statistical analysis") parser.add_argument("target", help="plain text dictionary file") parser.add_argument("-q", "--quiet", dest="quiet", action="store_true", help="quiet mode") parser.add_argument("-s", "--separator", dest="separator", help="character that separates the accounts from the passwords_usage. (Default ':')") args = parser.parse_args() target = args.target quiet_mode = args.quiet if args.separator: separator = args.separator else: separator = DEFAULT_SEPARATOR print_info("Analyzing: {0}\n".format(target)) if os.path.exists(target) and os.path.isfile(target): try: sumary = Sumary() f = open(target, "r", encoding="UTF-8", errors="ignore") parse_file(f, separator, quiet_mode, sumary) f.close() sumary.print_stats() except Exception as ex: print_error(ex) else: if not os.path.exists(target): print_error("{0} does not exists.".format(target)) exit(1) if not os.path.isfile(target):