Last active
March 20, 2020 17:14
-
-
Save zinthose/ca31b1bf764ec42e49eb57643e44852b to your computer and use it in GitHub Desktop.
Just something I threw together to help a team I work with deal with stupid people submitting log files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re, os, sys | |
# This simple script will scan all log files in a folder to verify the name matches the player name used in the game. | |
# If not, the script will list the logs that don't match the name and prompt to correct using the log specified name. | |
path_to_check = os.getcwd() # <-- Default is current direcctory, this should be changed if the script is not run in the same folder as the log files. | |
log_file_extention = ".log" | |
regular_expression_to_get_actual_in_game_name = r"playerName = (\w+)" | |
the_stupid_list = dict() | |
pattern = re.compile(regular_expression_to_get_actual_in_game_name, re.IGNORECASE) | |
os.chdir(path_to_check) | |
files = os.listdir(path_to_check) | |
print("Please wait as Igor searches for stupid...", end ="") | |
for file in files: | |
print(".", end="") | |
# If file is not a log file, skip it. | |
if file[-4:] != log_file_extention: | |
continue | |
# Read Log Data | |
current_log = open(file) | |
current_log_data = current_log.read() | |
current_log.close() | |
# Search for In Game Name | |
result = pattern.search(current_log_data) | |
if result is None: | |
continue | |
# Converting to uppercase just incase there is an in game stupid | |
in_game_name = result.group(1).upper() | |
# Get File name | |
file_name = file[:-4] | |
# Momment of truth! | |
if file_name != in_game_name: | |
# Doh! Add to the stupid list | |
the_stupid_list[file_name] = in_game_name | |
print("DONE!") | |
# Check if there were stupid people | |
if len(the_stupid_list) == 0: | |
print("\n\nLucky You!\nNo stupid people were found in this batch!\n") | |
sys.exit(0) | |
# Show the Stupid List! | |
print("\n\nAlas there is stupid in these logs!\n\n RESULTS:\n --------\n", the_stupid_list, "\n") | |
# Prompt if we should automatically correct | |
what_do = input("Master... Shall I correct the stupid? (y/N) : ") | |
if what_do.upper() != 'Y': | |
print("\n\nOf course master... I will leave it to you.\n") | |
sys.exit(len(the_stupid_list)) | |
# Fix the stupid! | |
print("\nPlease wait as Igor dose your bidding...", end = "") | |
for log in the_stupid_list: | |
print(".", end ="") | |
os.rename(log + log_file_extention, the_stupid_list[log] + log_file_extention) | |
# print(log, the_stupid_list[log] + log_file_extention) # I left this in here for Debugging | |
print("DONE!\n\nThe Deed is done master!\nI hope master is pleased with Igor.\n") | |
sys.exit() |
ALSO, keep in mind this only accounts for the FIRST player name encountered in the log. If the player changed there name for "reasons" it won;t be seen. I suppose I could edit the script to only get the most recent player name but instructions had a portion that would have caused issue if implemented.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI: Any comments made that could potentially violate the NDA will be deleted.