Guest User

CrossoutGameLogParser

a guest
Nov 7th, 2023
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.66 KB | None | 0 0
  1. import json
  2. import os
  3. import re
  4. from pprint import pprint
  5.  
  6.  
  7. # file
  8. # folder
  9. # os.path.isfile()
  10. # os.path.isdir()
  11.  
  12.  
  13. class CrossoutGameLogParser:
  14.     """
  15.    roadmap:
  16.    загручить БД
  17.    считать папки логов,
  18.        скип если есть есть в бд
  19.    анализ логов,
  20.        новый queueTag
  21.        если левел активен и попадается====== starting level , то чтто багануло
  22.    запись в БД,
  23.        проверка на дубли
  24.  
  25.  
  26.    БД
  27.    '2023.11.05 05.30.09', .......
  28.  
  29.  
  30.    """
  31.  
  32.     def __init__(self):
  33.         self.log_path = 'C:\\Users\\dendy\\OneDrive\\Документы\\My Games\\Crossout\\logs'
  34.         self.log_file = 'game.log'
  35.  
  36.         self.bigdata = {}
  37.  
  38.         # self.run()
  39.  
  40.     def run(self):
  41.         log_folders = os.listdir(self.log_path)
  42.         print(log_folders)
  43.  
  44.         # print(os.listdir('%APPDATA%'))
  45.  
  46.         for _folder in log_folders:
  47.             _file = f'{self.log_path}\\{_folder}\\{self.log_file}'
  48.             print(_file)
  49.             print(os.path.exists(_file))
  50.  
  51.             _data = self.parser(_file, _folder)
  52.             self.bigdata |= _data
  53.  
  54.         print(len(self.bigdata))
  55.  
  56.         with open("gamelog.json", "w", encoding="utf-8") as write_file:
  57.             json.dump(self.bigdata, write_file, sort_keys=True, indent=2)
  58.  
  59.     def parser(self, logfile, _folder=None):
  60.  
  61.         # _skip = []
  62.  
  63.         with open(logfile, "r", encoding='utf-8') as file:
  64.             log_lines = file.readlines()
  65.  
  66.         _folder = _folder[:10]
  67.         _levels_data = {}
  68.         _new_level = False
  69.  
  70.         # обработка строк
  71.         for n, line in enumerate(log_lines):
  72.  
  73.             # NEW level
  74.             if 'starting level' in line:
  75.                 if ('hangar' in line) or ('mainmenu' in line): continue
  76.  
  77.                 mode = line[line.find("' ", 60) + 2: line.find(" client ")]
  78.                 if mode == 'Exploration':
  79.                     continue
  80.  
  81.                 _new_level = True
  82.  
  83.                 print(n, line[:-1])
  84.  
  85.                 time_start = line[:12]
  86.                 print(time_start)
  87.  
  88.                 # string.find(substring,start,end)
  89.                 map = line[line.find('/maps/', 50) + 6:line.find("'", 62)]
  90.                 print(map)
  91.  
  92.                 print(mode)
  93.  
  94.                 continue
  95.  
  96.             if _new_level:
  97.                 if line[25:30] == 'minUR':
  98.                     minUR = line[33:-1]
  99.                     print(minUR)
  100.                     continue
  101.                 if line[25:30] == 'maxUR':
  102.                     maxUR = line[33:-1]
  103.                     print(maxUR)
  104.                     continue
  105.                 if '|   "queueTag":' in line:
  106.                     queueTag = line[36:-1]
  107.                     print(queueTag)
  108.                     continue
  109.                 if line[43:53] == 'gameResult':
  110.                     # print(line)
  111.                     # print(line[43:53])
  112.  
  113.                     time_end = line[:12]
  114.                     print(time_end)
  115.  
  116.                     gameResult = line[55:line.find("' ", 57) - 1]
  117.                     print(gameResult)
  118.  
  119.                     print(log_lines[n + 1][23:-1])
  120.                     profit_line = re.findall(r' [a-zA-Z_]{1,} {1,}[0-9.]{1,}', log_lines[n + 1][23:])
  121.                     print(profit_line)
  122.                     profit = self.profit_line_pars(profit_line)
  123.                     print(profit)
  124.  
  125.                     _new_level = False
  126.  
  127.                     _levels_data.update({f'{_folder} {time_start}': {
  128.                         'date': _folder,
  129.                         'time_start': time_start,
  130.                         'map': map,
  131.                         'mode': mode,
  132.                         'minUR': minUR,
  133.                         'maxUR': maxUR,
  134.                         'queueTag': queueTag,
  135.                         'time_end': time_end,
  136.                         'gameResult': gameResult,
  137.                         'profit': profit
  138.                     }})
  139.  
  140.                     print('')
  141.  
  142.         pprint(_levels_data)
  143.         print(len(_levels_data))
  144.  
  145.         return _levels_data
  146.  
  147.     def profit_line_pars(self, profit_line):
  148.         _result = []
  149.         for profit in profit_line:
  150.             profit = profit.replace("  ", " ")
  151.             profit = profit.strip()
  152.             name = profit[:profit.find(' ')]
  153.             value = profit[profit.find(' ') + 1:]
  154.             print(name, value)
  155.             _result.append((name, value))
  156.         return _result
  157.  
  158.  
  159. # self.data = {}
  160. # # self.url = 'https://www.lamoda.ru/c/5971/shoes-muzhkrossovki/'
  161. # self.url = 'https://www.lamoda.ru/c/2981/shoes-krossovk-kedy-muzhskie/'
  162. # self.name = self.url[24:-1].replace('/', '_')
  163. #
  164. # self.run()
  165. # self.save()
  166.  
  167.  
  168. def main():
  169.     log_path = 'C:\\Users\\dendy\\OneDrive\\Документы\\My Games\\Crossout\\logs'
  170.     log_file = 'game.log'
  171.  
  172.     log_folders = os.listdir(log_path)
  173.     print(log_folders)
  174.  
  175.     # print(os.listdir('%APPDATA%'))
  176.  
  177.     for _folder in log_folders:
  178.         _file = f'{log_path}\\{_folder}\\{log_file}'
  179.         print(_file)
  180.         print(os.path.exists(_file))
  181.  
  182.  
  183. if __name__ == "__main__":
  184.     parser = CrossoutGameLogParser()
  185.     parser.run()
  186.     # parser.parser('C:\\Users\\dendy\\OneDrive\\Документы\\My Games\\Crossout\\logs\\2023.11.05 19.07.27\\game.log',
  187.     # parser.parser('C:\\Users\\dendy\\OneDrive\\Документы\\My Games\\Crossout\\logs\\2023.11.05 20.04.42\\game.log',
  188.     # parser.parser('C:\\Users\\dendy\\OneDrive\\Документы\\My Games\\Crossout\\logs\\2023.11.05 21.35.01\\game.log',
  189.     #               '_test')
  190.     # main()
  191.     # pass
  192.  
Add Comment
Please, Sign In to add comment