Advertisement
mimky

Logs.TF Stats Calculator v3

Jun 7th, 2021 (edited)
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 27.19 KB | None | 0 0
  1. import requests
  2. import re
  3. import time
  4. import sys
  5. import os
  6. import threading
  7. import datetime
  8. import calendar
  9. from concurrent.futures import ThreadPoolExecutor, as_completed
  10. from progress.spinner import Spinner
  11. from sty import fg, bg, ef, rs
  12. from sty import Style, RgbFg
  13.  
  14. fg.redder = Style(RgbFg(255,60,60))
  15. os.system('cls' if os.name == 'nt' else 'clear')
  16. print(fg.redder + "\nCreated by: Mimky" + fg.rs)
  17.  
  18. SID64 = input("Enter SteamID64: ")
  19.  
  20. try:
  21.     SID3 = 'U:1:' + (str(int(SID64) - 76561197960265728))
  22. except ValueError:
  23.     print('\nInputted Steam ID was not an Integer.')
  24.     input('\n\nPress Enter to Quit...')
  25.     sys.exit()
  26.    
  27. logs_prof = 'https://logs.tf/profile/' + SID64
  28. logs = requests.get(logs_prof).text
  29.  
  30. results = re.search('<p>(.*?)</p>', logs)
  31. p_name = re.search('<title>(.*?)</title>', logs)
  32.  
  33. try:
  34.     log_count = int(''.join(i for i in results.group(1) if i.isdigit()))
  35.     if log_count > 10000:
  36.         log_count = 10000
  37. except:
  38.     print('\nInvald Steam ID or No Logs on Account.')
  39.     input('\n\nPress Enter to Quit...')
  40.     sys.exit()
  41.  
  42. if log_count > 25:
  43.     total_pages = int(log_count / 25) + 1
  44. else:
  45.     total_pages = 1
  46.  
  47. print('\n\n' + str(total_pages) + ' Pages and ' + str(log_count) + ' Logs Found for Player: ' + p_name.group(1)[:-10])
  48.  
  49. def create_dates():
  50.     global start_date_lst_int
  51.     global end_date_lst_int
  52.     global curdate
  53.     global end_date_epoch
  54.     global start_date_epoch
  55.     global firstdate
  56.     start_date_lst_int = None
  57.     end_date_lst_int = None
  58.     curdate = None
  59.     end_date_epoch = None
  60.     start_date_epoch = None
  61.     firstdate = False
  62.    
  63. def create_variables1():
  64.     global gamemode_dic
  65.     global gamemode_printed
  66.     gamemode_printed = False
  67.    
  68.     gamemode_dic = {
  69.     '1' : '[ 1 ] Sixes',
  70.     '2' : '[ 2 ] Highlander',
  71.     '3' : '[ 3 ] Prolander',
  72.     '4' : '[ 4 ] Fours',
  73.     '5' : '[ 5 ] Bball / Ultiduo'
  74.     }
  75.    
  76. def create_variables2():
  77.  
  78.     global mercenary_dic
  79.     mercenary_dic = {
  80.     '1' : '[ 1 ] Scout',
  81.     '2' : '[ 2 ] Soldier',
  82.     '3' : '[ 3 ] Pyro',
  83.     '4' : '[ 4 ] Demoman',
  84.     '5' : '[ 5 ] Heavy',
  85.     '6' : '[ 6 ] Engineer',
  86.     '7' : '[ 7 ] Medic',
  87.     '8' : '[ 8 ] Sniper',
  88.     '9' : '[ 9 ] Spy'
  89.     }
  90.  
  91. create_dates()
  92. create_variables1()
  93. create_variables2()
  94.  
  95. def print_sorter(string):
  96.     string1 = ''
  97.     for i in string:
  98.         if i in map(chr, range(97, 123)) or i in map(chr, range(65, 91)) or i == ' ' or i == '/':
  99.             string1 += i
  100.     string2 = string1.split('   ')
  101.     for i in string2:
  102.         if i == '':
  103.             string2.remove(i)
  104.     string3 = [x.strip(' ') for x in string2]
  105.     return (', '.join(string3))
  106.    
  107. def ask_filter_input():
  108.     global filter_input
  109.     filter_input = input('Would you like to filter your search? (y/n)\n> ')
  110.     if filter_input not in ['y', 'n']:
  111.         ask_filter_input()
  112. ask_filter_input()
  113.  
  114. if filter_input == 'y':
  115.    
  116.     class Daterange:
  117.            
  118.         @classmethod
  119.         def daterangeerror(cls, error_code):
  120.             os.system('cls' if os.name == 'nt' else 'clear')
  121.             print(fg.redder + "\nCreated by: Mimky" + fg.rs)
  122.             print('\nError occured while inputting dates.')
  123.             if error_code == 1:
  124.                 print('Error Message - Invalid End Date Input.')
  125.             if error_code == 2:
  126.                 print('Error Message - Start Date cannot be later than End Date.')
  127.             if error_code == 3:
  128.                 print('Error Message - Invalid Start Date Input.')
  129.             create_dates()
  130.             exittomenu2()
  131.            
  132.         @classmethod
  133.         def daterangeend(cls):
  134.             global end_date_epoch
  135.             global end_date_lst_int
  136.             global curdate
  137.             global firstdate
  138.             print('Enter an End Date (leave blank for current date):')
  139.             end_date_inp = input('\n> ')
  140.             if not end_date_inp:
  141.                 end_date_epoch = time.time()
  142.                 curdate = time.strftime("%m-%d-%Y").split('-')
  143.                 print('Date Range Successfully Defined.')
  144.                 exittomenu1()
  145.                 return
  146.             end_date_lst_str = end_date_inp.split('/')
  147.             try:
  148.                 end_date_lst_int = list(map(int, end_date_lst_str))
  149.                 end_date_epoch = int(datetime.datetime(end_date_lst_int[-1],end_date_lst_int[-3],end_date_lst_int[-2]).timestamp())
  150.             except:
  151.                 cls.daterangeerror(1)
  152.                 return
  153.            
  154.             if not firstdate:
  155.                 if (start_date_epoch > end_date_epoch):
  156.                     cls.daterangeerror(2)
  157.             print('Date Range Successfully Defined.')
  158.             exittomenu1()
  159.            
  160.         @classmethod
  161.         def daterangestart(cls):
  162.             global start_date_lst_int
  163.             global start_date_epoch
  164.             global firstdate
  165.             os.system('cls' if os.name == 'nt' else 'clear')
  166.             print(fg.redder + "\nCreated by: Mimky" + fg.rs)
  167.             print("Enter a Start Date. \nExample: 6/30/2015 = June 30, 2015 (leave blank for first log's date):")
  168.             start_date_inp = input('\n> ')
  169.             if not start_date_inp:
  170.                 start_date_epoch = 'first'
  171.                 firstdate = True
  172.                 cls.daterangeend()
  173.                 return
  174.             start_date_lst_str = start_date_inp.split('/')
  175.             try:
  176.                 start_date_lst_int = list(map(int, start_date_lst_str))
  177.                 start_date_epoch = int(datetime.datetime(start_date_lst_int[-1],start_date_lst_int[-3],start_date_lst_int[-2]).timestamp())
  178.             except:
  179.                 cls.daterangeerror(3)
  180.             if start_date_epoch > time.time():
  181.                 cls.daterangeerror(2)
  182.             else:
  183.                 cls.daterangeend()
  184.            
  185.        
  186.    
  187.     class Gamemode:
  188.  
  189.             @classmethod
  190.             def gamemode_error(cls):
  191.                 os.system('cls' if os.name == 'nt' else 'clear')
  192.                 print(fg.redder + "\nCreated by: Mimky" + fg.rs)
  193.                 print('\nError occured while filtering gamemodes.')
  194.                 print('Error Message - Gamemode List cannot be empty. List has been reset.')
  195.                
  196.                 create_variables1()
  197.                 exittomenu2()
  198.                
  199.             @classmethod
  200.             def gamemode_interface(cls):
  201.                 os.system('cls' if os.name == 'nt' else 'clear')
  202.                 print(fg.redder + "\nCreated by: Mimky" + fg.rs)
  203.                 if all(value == '' for value in gamemode_dic.values()):
  204.                     cls.gamemode_error()
  205.                     return
  206.                 print('Iteration will show logs with these classes:')
  207.                 for display in gamemode_dic.values():
  208.                     print(display)
  209.                 gamemode_selection = input("\nTo REMOVE a gamemode: Pick 1 - 5 or leave blank to exit.\n> ")
  210.                 if not gamemode_selection:
  211.                     menu()
  212.                     return
  213.                 if gamemode_selection not in ['1', '2', '3', '4', '5']:
  214.                     cls.gamemode_interface()
  215.                     return
  216.                 else:
  217.                     gamemode_dic[gamemode_selection] = ''
  218.                     cls.gamemode_interface()
  219.                
  220.  
  221.     class Mercenary:
  222.  
  223.             @classmethod
  224.             def mercenary_error(cls):
  225.                 os.system('cls' if os.name == 'nt' else 'clear')
  226.                 print(fg.redder + "\nCreated by: Mimky" + fg.rs)
  227.                 print('\nError occured while filtering classes.')
  228.                 print('Error Message - Class List cannot be empty. List has been reset.')
  229.                 create_variables2()
  230.                 exittomenu2()
  231.                
  232.             @classmethod
  233.             def mercenary_interface(cls):
  234.                 os.system('cls' if os.name == 'nt' else 'clear')
  235.                 print(fg.redder + "\nCreated by: Mimky" + fg.rs)
  236.                 if all(value == '' for value in mercenary_dic.values()):
  237.                     cls.mercenary_error()
  238.                     return
  239.                 print('Iteration will show logs with these gamemodes:')
  240.                 for display in mercenary_dic.values():
  241.                     print(display)
  242.                 mercenary_selection = input("\nTo REMOVE a class: Pick 1 - 9 or leave blank to exit.\n> ")
  243.                 if not mercenary_selection:
  244.                     menu()
  245.                     return
  246.                 if mercenary_selection not in ['1', '2', '3', '4', '5', '6', '7', '8', '9']:
  247.                     cls.mercenary_interface()
  248.                 else:
  249.                     mercenary_dic[mercenary_selection] = ''
  250.                     cls.mercenary_interface()
  251.    
  252.     def selection(number_filter):
  253.         global start_date_lst_int
  254.         global end_date_lst_int
  255.         global curdate
  256.         global gamemode_dic
  257.         global mercenary_dic
  258.        
  259.         global firstdate
  260.         global gamemode_printed
  261.        
  262.         if number_filter not in ['1', '2', '3', '4']:
  263.             menu()
  264.         if number_filter == '1':
  265.             Daterange.daterangestart()
  266.            
  267.         if number_filter == '2':
  268.             Gamemode.gamemode_interface()
  269.            
  270.         if number_filter == '3':
  271.             Mercenary.mercenary_interface()
  272.            
  273.         if number_filter == '4':
  274.             os.system('cls' if os.name == 'nt' else 'clear')
  275.             print(fg.redder + "\nCreated by: Mimky" + fg.rs)
  276.            
  277.             if start_date_lst_int is not None and end_date_lst_int is not None:
  278.                 print('Date Range: ' + calendar.month_name[start_date_lst_int[-3]] + ' ' + str(start_date_lst_int[-2]) + ', ' + str(start_date_lst_int[-1]) + ' - ' + calendar.month_name[end_date_lst_int[-3]] + ' ' + str(end_date_lst_int[-2]) + ', ' + str(end_date_lst_int[-1]))
  279.                    
  280.             elif curdate is not None:
  281.                 if not firstdate:
  282.                     print('Date Range: ' + calendar.month_name[start_date_lst_int[-3]] + ' ' + str(start_date_lst_int[-2]) + ', ' + str(start_date_lst_int[-1]) + ' - ' + calendar.month_name[int(curdate[0])] + ' ' + str(curdate[1]) + ', ' + str(curdate[2]))
  283.                 else:
  284.                     create_dates()
  285.                     print('Date Range: All')
  286.                    
  287.                    
  288.             elif firstdate and end_date_lst_int is not None:
  289.                 print('Date Range: First Log - ' + calendar.month_name[end_date_lst_int[-3]] + ' ' + str(end_date_lst_int[-2]) + ', ' + str(end_date_lst_int[-1]))
  290.             else:
  291.                 print('Date Range: All')
  292.            
  293.             gamemode_printed = False
  294.             for value in gamemode_dic.values():
  295.                 if value == '':
  296.                     search_gamemodes = "".join(str(value) for value in gamemode_dic.values())
  297.                     gamemode_printed = True
  298.                     print('Gamemodes: ' + print_sorter(search_gamemodes))
  299.                     break
  300.                 else:
  301.                     pass
  302.             if not gamemode_printed:
  303.                 print('Gamemodes: All')
  304.  
  305.             mercenary_printed = False
  306.             for value in mercenary_dic.values():
  307.                 if value == '':
  308.                     search_mercenarys = "".join(str(value) for value in mercenary_dic.values())
  309.                     mercenary_printed = True
  310.                     print('Classes: ' + print_sorter(search_mercenarys))
  311.                     break
  312.                 else:
  313.                     pass
  314.             if not mercenary_printed:
  315.                 print('Classes: All')
  316.            
  317.            
  318.             def ask_confirmed():
  319.                 global confirmed
  320.                 confirmed = input('\nPlease confirm the settings above (y/n)\n> ')
  321.                 if confirmed not in ['y', 'n']:
  322.                     ask_confirmed()
  323.             ask_confirmed()
  324.                
  325.             if confirmed == 'n':
  326.                 create_variables1()
  327.                 create_variables2()
  328.                 create_dates()
  329.                 print('\nAll Inputs Reset.')
  330.                 exittomenu1()
  331.            
  332.                
  333.     def exittomenu1():
  334.         sys.stdout.write('Exiting to Menu in 3')
  335.         sys.stdout.flush()
  336.         time.sleep(1)
  337.         for i in range(2, 0, -1):
  338.             sys.stdout.write('\b')
  339.             sys.stdout.write(str(i))
  340.             sys.stdout.flush()
  341.             time.sleep(1)
  342.         menu()
  343.     def exittomenu2():
  344.         sys.stdout.write('Exiting to Menu in 5')
  345.         sys.stdout.flush()
  346.         time.sleep(1)
  347.         for i in range(4, 0, -1):
  348.             sys.stdout.write('\b')
  349.             sys.stdout.write(str(i))
  350.             sys.stdout.flush()
  351.             time.sleep(1)
  352.         menu()
  353.        
  354.     def menu():
  355.         os.system('cls' if os.name == 'nt' else 'clear')
  356.         print(fg.redder + "\nCreated by: Mimky" + fg.rs)
  357.         print('''Pick a number.
  358. [ 1 ] Specificy Date Range
  359. [ 2 ] Gamemode Seperation
  360. [ 3 ] Class Seperation
  361. [ 4 ] Finish
  362. ''')
  363.         number_filter = input('> ')
  364.         selection(number_filter)
  365.        
  366.     menu()
  367.  
  368. start_time = time.time()
  369. if filter_input == 'y':
  370.     spinner = Spinner('Preparing for Iteration based on Current Settings ')
  371. else:
  372.     spinner = Spinner('Preparing for Iteration ')
  373. spinning = True
  374. def start_spin():
  375.     while spinning:
  376.         spinner.next()
  377.         time.sleep(0.1)
  378.     else:
  379.         sys.exit()
  380. t1 = threading.Thread(target=start_spin)
  381. t1.start()
  382.  
  383. def log_id_finder(seperated_logs):
  384.     global all_log_ids
  385.     all_log_ids = []
  386.     search_term_start = '''            "id": '''
  387.     search_term_end = ''','''
  388.     for i in seperated_logs:
  389.         log_id_search = re.search(search_term_start + '(.*?)' + search_term_end, i)
  390.         all_log_ids.append(log_id_search.group(1))
  391.  
  392.  
  393. logsid_prof = requests.get('''https://logs.tf/api/v1/log?player=''' + SID64 + '&limit=10000').text
  394.  
  395. search1 = re.compile('''        {''' + r'(.*?)' + '''        }''', re.DOTALL)
  396. search2 = search1.findall(logsid_prof)
  397.    
  398. custom_date_search = False
  399.  
  400. if start_date_epoch is not None:
  401.     custom_date_search = True
  402.    
  403.     date_search = re.compile('''"date": ''' + r'(.*?)' + ''',''', re.DOTALL)
  404.     date_lst_str = date_search.findall(logsid_prof)
  405.     date_lst = list(map(int, date_lst_str))
  406.     if start_date_epoch == 'first':
  407.         start_date_epoch = date_lst[-1] - 86400
  408.     date_lst_search = []
  409.    
  410.     for i in date_lst:
  411.         if start_date_epoch <= i <= end_date_epoch:
  412.             date_lst_search.append('''"date": ''' + str(i) + ',')
  413.            
  414.     custom_search1 = []
  415.     for i in search2:
  416.         if any(ele in i for ele in date_lst_search):
  417.             custom_search1.append(i)
  418.    
  419. if gamemode_printed:
  420.     gamemode_search_lst = []
  421.     gamemode_players_search = []
  422.    
  423.     def add_game_search(playcount):
  424.         gamemode_players_search.append('''            "players": ''' + playcount)
  425.        
  426.     for key in gamemode_dic.keys():
  427.         if gamemode_dic[key] != '':
  428.             gamemode_search_lst.append(key)
  429.     for i in gamemode_search_lst:
  430.         if i == '1':
  431.             add_game_search('11')
  432.             add_game_search('12')
  433.             add_game_search('13')
  434.         if i == '2':
  435.             add_game_search('17')
  436.             add_game_search('18')
  437.             add_game_search('19')
  438.         if i == '3':
  439.             add_game_search('13')
  440.             add_game_search('14')
  441.             add_game_search('15')
  442.         if i == '4':
  443.             add_game_search('8')
  444.             add_game_search('9')
  445.         if i == '5':
  446.             add_game_search('4')
  447.            
  448.    
  449.     if custom_date_search:
  450.         custom_search2 = []
  451.         for i in custom_search1:
  452.             if any(ele in i for ele in gamemode_players_search):
  453.                 custom_search2.append(i)
  454.         log_id_finder(custom_search2)
  455.     else:
  456.         custom_search1 = []
  457.         for i in search2:
  458.             if any(ele in i for ele in gamemode_players_search):
  459.                 custom_search1.append(i)
  460.         log_id_finder(custom_search1)
  461.        
  462. elif custom_date_search:
  463.     log_id_finder(custom_search1)
  464.    
  465. else:
  466.     log_id_finder(search2)
  467.    
  468. def epoch_time_converter(total_time, col):
  469.     time = total_time % (24 * 3600)
  470.     hour = total_time // 3600
  471.     total_time %= 3600
  472.     minutes = total_time // 60
  473.     total_time %= 60
  474.     seconds = total_time
  475.     if col is False:
  476.         return(str(int(hour)) + ' hours ' + str(int(minutes)) + ' minutes ' + str(int(seconds)) + ' seconds.')
  477.     else:
  478.         return(fg.yellow + str(int(hour)) + fg.rs + ' hours ' + fg.yellow + str(int(minutes)) + fg.rs + ' minutes ' + fg.yellow + str(int(seconds)) + fg.rs + ' seconds.')
  479.    
  480. eta = len(all_log_ids) * 0.2
  481. print('\n\nEstimated Search Time: ' + epoch_time_converter(eta, False))
  482.  
  483. mercenary_custom = False
  484. search_mercenarys = "".join(str(value) for value in mercenary_dic.values())
  485. search_mercenarys2 = print_sorter(search_mercenarys).split(', ')
  486. custom_class_lst = [x.lower() for x in search_mercenarys2]
  487. for i in custom_class_lst:
  488.     if i == 'heavy':
  489.         custom_class_lst.remove(i)
  490.         custom_class_lst.append('heavyweapons')
  491.  
  492. def start_iteration():
  493.    
  494.     scout_dict = {"time": [], "kills": [], "deaths": [], "dmg": []}
  495.     soldier_dict = {"time": [], "kills": [], "deaths": [], "dmg": []}
  496.     pyro_dict = {"time": [], "kills": [], "deaths": [], "dmg": []}
  497.     demoman_dict = {"time": [], "kills": [], "deaths": [], "dmg": []}
  498.     heavyweapons_dict = {"time": [], "kills": [], "deaths": [], "dmg": []}
  499.     engineer_dict = {"time": [], "kills": [], "deaths": [], "dmg": []}
  500.     medic_dict = {"time": [], "kills": [], "deaths": [], "dmg": [], "healing": [], "drops": [], "charges": []}
  501.     sniper_dict = {"time": [], "kills": [], "deaths": [], "dmg": []}
  502.     spy_dict = {"time": [], "kills": [], "deaths": [], "dmg": []}
  503.    
  504.     scout_lst = []
  505.     soldier_lst = []
  506.     pyro_lst = []
  507.     demoman_lst = []
  508.     heavyweapons_lst = []
  509.     engineer_lst = []
  510.     medic_lst = []
  511.     sniper_lst = []
  512.     spy_lst = []
  513.    
  514.     class_lst_search = [scout_lst, soldier_lst, pyro_lst, demoman_lst, heavyweapons_lst, engineer_lst, medic_lst, sniper_lst, spy_lst]
  515.     class_dict_search = [scout_dict, soldier_dict, pyro_dict, demoman_dict, heavyweapons_dict, engineer_dict, medic_dict, sniper_dict, spy_dict]
  516.     cap_lst = []
  517.    
  518.     global counter
  519.     global log_removal
  520.     global cooldown_check
  521.     counter = 0
  522.     log_removal = 0
  523.     cooldown_check = False
  524.     x2 = []
  525.     x3 = []
  526.    
  527.     print('\n')
  528.    
  529.    
  530.     def multithread_it(log_id):
  531.         global counter
  532.         global log_removal
  533.         global cooldown_check
  534.        
  535.         while True:
  536.             if not cooldown_check:
  537.                 break
  538.             else:
  539.                 time.sleep(0.25)
  540.  
  541.         counter += 1
  542.         log_printer = 'https://logs.tf/json/' + log_id
  543.         print("\nGrabbing logs from: " "{} ({}%)".format(log_printer, round(100*counter/len(all_log_ids), 1)), end = '')
  544.         log_iterator = requests.get(log_printer).text
  545.        
  546.         flagger = False
  547.         while True:
  548.             if not cooldown_check:
  549.                 if not flagger:
  550.                     break
  551.                 else:
  552.                     log_iterator = requests.get(log_printer).text
  553.                     break
  554.             else:
  555.                 flagger = True
  556.                 time.sleep(0.25)
  557.                
  558.         if "429 Too Many Requests" in log_iterator:
  559.             cooldown_check = True
  560.             print(fg.yellow + ' Cooling Down (Logs.tf Data Request Overflow).' + fg.rs)
  561.             time.sleep(2.25)
  562.             cooldown_check = False
  563.             log_iterator = requests.get(log_printer).text
  564.        
  565.         x1 = re.search(SID3 + '(.*?)' + 'U:1:', log_iterator)
  566.         try:
  567.             x2.append(x1.group(1))
  568.         except AttributeError:
  569.             print(fg.red + ' ERROR: Log appears to be broken / outdated (skipped).' + fg.rs)
  570.             log_removal += 1
  571.  
  572.                    
  573.     processes = []
  574.     with ThreadPoolExecutor(max_workers=10) as executor:
  575.         for i in all_log_ids:
  576.             processes.append(executor.submit(multithread_it, i))
  577.  
  578.  
  579.     for i in x2:
  580.         y1 = re.search('''"cpc": ''' + '(.*?)' + ''', "''', i)
  581.         y2 = y1.group(1)
  582.         cap_lst.append(y2)
  583.         y3 = i.split('''"type": "''')
  584.         y3.pop(0)
  585.         for e in y3:
  586.             if any(ele in e for ele in custom_class_lst):
  587.                 x3.append(e)
  588.  
  589.     for i in x3:
  590.         y4 = i.split('''", ''')[0]
  591.         try:
  592.             eval(y4 + '_lst').append(i)
  593.         except NameError:
  594.             pass
  595.    
  596.     for i in class_lst_search:
  597.         for e in i:
  598.             w1 = re.search('''"total_time": ''' + '(.*?)' + '''}''', e)
  599.             w2 = re.search('''"kills": ''' + '(.*?)' + ''', "''', e)
  600.             w3 = re.search('''"deaths": ''' + '(.*?)' + ''', "''', e)
  601.             w4 = re.search('''"dmg": ''' + '(.*?)' + ''', "''', e)
  602.             try:
  603.                 z1 = w1.group(1)
  604.                 z2 = w2.group(1)
  605.                 z3 = w3.group(1)
  606.                 z4 = w4.group(1)
  607.             except AttributeError:
  608.                 continue
  609.             class_dict_name1 = [k for k, v in locals().items() if v == i][0]
  610.             class_dict_name2 = class_dict_name1.split('_', 1)
  611.             class_dict = eval(class_dict_name2[0] + '_dict')
  612.            
  613.             class_dict["time"].append(z1)
  614.             class_dict["kills"].append(z2)
  615.             class_dict["deaths"].append(z3)
  616.             class_dict["dmg"].append(z4)
  617.  
  618.             if class_dict_name2[0] == "medic":
  619.                 w5 = re.search('''"heal": ''' + '(.*?)' + ''',''', e)
  620.                 w6 = re.search('''"drops": ''' + '(.*?)' + ''',''', e)
  621.                 w7 = re.search('''"ubertypes": {"''' + '(.*?)' + '''}''', e)
  622.                 try:
  623.                     z5 = w5.group(1)
  624.                     z6 = w6.group(1)
  625.                     z7 = w7.group(1)
  626.                 except AttributeError:
  627.                     continue
  628.                    
  629.                 class_dict["healing"].append(z5)
  630.                 class_dict["drops"].append(z6)
  631.                
  632.                 z8 = z7.split(',')
  633.                 for f in z8:
  634.                         numeric_filter = filter(str.isdigit, f)
  635.                         charge_uses = "".join(numeric_filter)
  636.                         class_dict["charges"].append(charge_uses)
  637.                    
  638.  
  639.     os.system('cls' if os.name == 'nt' else 'clear')
  640.     print(fg.redder + "\nCreated by: Mimky\n" + fg.rs)
  641.    
  642.     complete_time = 0
  643.     complete_kills = 0
  644.     complete_deaths = 0
  645.     complete_damage = 0
  646.  
  647.     fg.lightgreen = Style(RgbFg(102,255,102))
  648.     fg.lightred = Style(RgbFg(255,102,102))
  649.     fg.lightpurple = Style(RgbFg(153,51,255))
  650.     fg.lightblue = Style(RgbFg(135,206,235))
  651.     fg.bluerr = Style(RgbFg(0, 150, 255))
  652.     fg.lightyellow = Style(RgbFg(255,255,51))
  653.     fg.pink = Style(RgbFg(255,105,180))
  654.    
  655.     class_name_printer = 0
  656.    
  657.     def confirm_quit():
  658.         confirmed = input()
  659.         confirm_quit()
  660.    
  661.     for dict in class_dict_search:
  662.        
  663.         total_time = sum(list(map(int, dict["time"])))
  664.         total_kills = sum(list(map(int, dict["kills"])))
  665.         total_deaths = sum(list(map(int, dict["deaths"])))
  666.         total_damage = sum(list(map(int, dict["dmg"])))
  667.        
  668.         try:
  669.             avg_kills = total_kills / (total_time / 1800)
  670.             avg_deaths = total_deaths / (total_time / 1800)
  671.             total_dpm = total_damage / (total_time / 60)
  672.             total_kd = avg_kills / avg_deaths
  673.         except ZeroDivisionError:
  674.             continue
  675.        
  676.         class_name1 = [k for k, v in locals().items() if v == dict][0]
  677.         class_name2 = class_name1.split('_', 1)
  678.         class_name3 = class_name2[0]
  679.         if class_name3 not in custom_class_lst:
  680.             continue
  681.        
  682.         class_name_printer += 1
  683.         class_name = class_name3.upper()
  684.         if class_name == 'HEAVYWEAPONS':
  685.             class_name = 'HEAVY'
  686.  
  687.         complete_time += total_time
  688.         complete_kills += total_kills
  689.         complete_deaths += total_deaths
  690.         complete_damage += total_damage
  691.  
  692.         print(class_name + ':\n')
  693.         print('\tTotal Kills:  ' + fg.green + str(total_kills) + fg.rs)
  694.         print('\tTotal Deaths: ' + fg.red + str(total_deaths) + fg.rs)
  695.         print('\tTotal Damage: ' + fg.bluerr + str(total_damage) + fg.rs)
  696.  
  697.         print('\n\tAverage Kills (Per 30 Minutes):  ' + fg.lightgreen + str(round(avg_kills, 2)) + fg.rs)
  698.         print('\tAverage Deaths (Per 30 Minutes): ' + fg.lightred + str(round(avg_deaths, 2)) + fg.rs)
  699.        
  700.         print('\n\tTotal DPM: ' + fg.lightblue + str(round(total_dpm, 2)) + fg.rs)
  701.         print('\tTotal K/D: ' + fg.lightpurple + str(round(total_kd, 2)) + fg.rs)
  702.         if class_name == 'MEDIC':
  703.             total_healing = sum(list(map(int, dict["healing"])))
  704.             total_drops = sum(list(map(int, dict["drops"])))
  705.             charges = sum(list(map(int, dict["charges"])))
  706.        
  707.             print('\n\tTotal Healing: ' + fg.pink + str(total_healing) + fg.rs)
  708.             print('\tTotal Drops: ' + fg.pink + str(total_drops) + fg.rs)
  709.             print('\tTotal Charges: ' + fg.pink + str(charges) + fg.rs)
  710.         print('\tTotal Time Played: ' + epoch_time_converter(total_time, True) + '\n\n')
  711.        
  712.     end_time = time.time() - start_time
  713.     total_caps = sum(list(map(int, cap_lst)))
  714.     if class_name_printer > 1:
  715.         try:
  716.             print('\nOverall Stats:\n')
  717.             print('\tCombined Kills:  ' + fg.green + str(complete_kills) + fg.rs)
  718.             print('\tCombined Deaths: ' + fg.red + str(complete_deaths) + fg.rs)
  719.             print('\tCombined Damage: ' + fg.bluerr + str(complete_damage) + fg.rs)
  720.            
  721.             print('\n\tMedian Kills (Per 30 Minutes):  ' + fg.lightgreen + str(round(complete_kills / (complete_time / 1800), 2)) + fg.rs)
  722.             print('\tMedian Deaths (Per 30 Minutes): ' + fg.lightred + str(round(complete_deaths / (complete_time / 1800), 2)) + fg.rs)
  723.        
  724.             print('\n\tCombined DPM: ' + fg.lightblue + str(round(complete_damage / (complete_time / 60), 2)) + fg.rs)
  725.             print('\tCombined K/D: ' + fg.lightpurple + str(round(complete_kills / complete_deaths, 2)) + fg.rs)
  726.             print('\tCombined Time Played: ' + epoch_time_converter(complete_time, True))
  727.             print('\n\tTotal Caps: ' + fg.lightyellow + str(total_caps) + fg.rs + ' in ' + (str((len(all_log_ids)) - log_removal)) + ' logs.')
  728.             print('\n\nTotal Time Elapsed: ' + epoch_time_converter(end_time, True))
  729.  
  730.         except ZeroDivisionError:
  731.             os.system('cls' if os.name == 'nt' else 'clear')
  732.             print(fg.redder + "\nCreated by: Mimky\n" + fg.rs)
  733.             print('ZeroDivisionError occurred.\nLog list is invalid.')
  734.             print('Total Time Elapsed: ' + epoch_time_converter(end_time, True))
  735.  
  736.     else:
  737.         print('Total Caps: ' + fg.lightyellow + str(total_caps) + fg.rs + ' in ' + (str((len(all_log_ids)) - log_removal)) + ' logs.')
  738.         print('\nTotal Time Elapsed: ' + epoch_time_converter(end_time, True))
  739.     confirm_quit()
  740.        
  741. spinning = False
  742. start_iteration()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement