Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import os
- import re
- from pprint import pprint
- # file
- # folder
- # os.path.isfile()
- # os.path.isdir()
- class CrossoutGameLogParser:
- """
- roadmap:
- загручить БД
- считать папки логов,
- скип если есть есть в бд
- анализ логов,
- новый queueTag
- если левел активен и попадается====== starting level , то чтто багануло
- запись в БД,
- проверка на дубли
- БД
- '2023.11.05 05.30.09', .......
- """
- def __init__(self):
- self.log_path = 'C:\\Users\\dendy\\OneDrive\\Документы\\My Games\\Crossout\\logs'
- self.log_file = 'game.log'
- self.bigdata = {}
- # self.run()
- def run(self):
- log_folders = os.listdir(self.log_path)
- print(log_folders)
- # print(os.listdir('%APPDATA%'))
- for _folder in log_folders:
- _file = f'{self.log_path}\\{_folder}\\{self.log_file}'
- print(_file)
- print(os.path.exists(_file))
- _data = self.parser(_file, _folder)
- self.bigdata |= _data
- print(len(self.bigdata))
- with open("gamelog.json", "w", encoding="utf-8") as write_file:
- json.dump(self.bigdata, write_file, sort_keys=True, indent=2)
- def parser(self, logfile, _folder=None):
- # _skip = []
- with open(logfile, "r", encoding='utf-8') as file:
- log_lines = file.readlines()
- _folder = _folder[:10]
- _levels_data = {}
- _new_level = False
- # обработка строк
- for n, line in enumerate(log_lines):
- # NEW level
- if 'starting level' in line:
- if ('hangar' in line) or ('mainmenu' in line): continue
- mode = line[line.find("' ", 60) + 2: line.find(" client ")]
- if mode == 'Exploration':
- continue
- _new_level = True
- print(n, line[:-1])
- time_start = line[:12]
- print(time_start)
- # string.find(substring,start,end)
- map = line[line.find('/maps/', 50) + 6:line.find("'", 62)]
- print(map)
- print(mode)
- continue
- if _new_level:
- if line[25:30] == 'minUR':
- minUR = line[33:-1]
- print(minUR)
- continue
- if line[25:30] == 'maxUR':
- maxUR = line[33:-1]
- print(maxUR)
- continue
- if '| "queueTag":' in line:
- queueTag = line[36:-1]
- print(queueTag)
- continue
- if line[43:53] == 'gameResult':
- # print(line)
- # print(line[43:53])
- time_end = line[:12]
- print(time_end)
- gameResult = line[55:line.find("' ", 57) - 1]
- print(gameResult)
- print(log_lines[n + 1][23:-1])
- profit_line = re.findall(r' [a-zA-Z_]{1,} {1,}[0-9.]{1,}', log_lines[n + 1][23:])
- print(profit_line)
- profit = self.profit_line_pars(profit_line)
- print(profit)
- _new_level = False
- _levels_data.update({f'{_folder} {time_start}': {
- 'date': _folder,
- 'time_start': time_start,
- 'map': map,
- 'mode': mode,
- 'minUR': minUR,
- 'maxUR': maxUR,
- 'queueTag': queueTag,
- 'time_end': time_end,
- 'gameResult': gameResult,
- 'profit': profit
- }})
- print('')
- pprint(_levels_data)
- print(len(_levels_data))
- return _levels_data
- def profit_line_pars(self, profit_line):
- _result = []
- for profit in profit_line:
- profit = profit.replace(" ", " ")
- profit = profit.strip()
- name = profit[:profit.find(' ')]
- value = profit[profit.find(' ') + 1:]
- print(name, value)
- _result.append((name, value))
- return _result
- # self.data = {}
- # # self.url = 'https://www.lamoda.ru/c/5971/shoes-muzhkrossovki/'
- # self.url = 'https://www.lamoda.ru/c/2981/shoes-krossovk-kedy-muzhskie/'
- # self.name = self.url[24:-1].replace('/', '_')
- #
- # self.run()
- # self.save()
- def main():
- log_path = 'C:\\Users\\dendy\\OneDrive\\Документы\\My Games\\Crossout\\logs'
- log_file = 'game.log'
- log_folders = os.listdir(log_path)
- print(log_folders)
- # print(os.listdir('%APPDATA%'))
- for _folder in log_folders:
- _file = f'{log_path}\\{_folder}\\{log_file}'
- print(_file)
- print(os.path.exists(_file))
- if __name__ == "__main__":
- parser = CrossoutGameLogParser()
- parser.run()
- # parser.parser('C:\\Users\\dendy\\OneDrive\\Документы\\My Games\\Crossout\\logs\\2023.11.05 19.07.27\\game.log',
- # parser.parser('C:\\Users\\dendy\\OneDrive\\Документы\\My Games\\Crossout\\logs\\2023.11.05 20.04.42\\game.log',
- # parser.parser('C:\\Users\\dendy\\OneDrive\\Документы\\My Games\\Crossout\\logs\\2023.11.05 21.35.01\\game.log',
- # '_test')
- # main()
- # pass
Add Comment
Please, Sign In to add comment