/
script.py
61 lines (43 loc) · 1.51 KB
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import models
from parser import Parser
from models import Games
from access_db import *
from database import engine
if __name__ == '__main__':
"""
Store the games in the database and print a report of the games in the games.log
file
"""
models.Base.metadata.create_all(bind=engine) # Creates the database if not created yet
db = get_db()
file_parser = Parser()
with open('games.log', 'r') as file:
file_data = file.read().split('\n')
for line in file_data:
line_elements = line.split()
try:
if line_elements[1] == 'InitGame:':
if not file_parser._game:
file_parser.new_game_started()
else:
game_hash = file_parser.generate_hash()
file_parser.print_game(game_hash)
game = Games()
game.game_info = file_parser._game.data_to_store()
game.hash_game = game_hash
db.add(game)
db.commit()
file_parser.new_game_started()
elif line_elements[1] == 'Kill:':
file_parser.check_kill(line_elements[2], line_elements[3])
elif line_elements[1] == 'ClientUserinfoChanged:':
file_parser.user_info_changed(line_elements)
except IndexError:
game_hash = file_parser.generate_hash()
file_parser.print_game(game_hash)
game = Games()
game.game_info = file_parser._game.data_to_store()
game.hash_game = game_hash
db.add(game)
db.commit()
file_parser.new_game_started()