-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
40 lines (30 loc) · 1016 Bytes
/
example.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
"""
An example of how to use the replay parser from python. Requires Python 3.5+.
"""
from datetime import timedelta
from time import perf_counter
from fafreplay import Parser, commands
def main():
# Create a parser object. This configuration would be optimal for parsing
# only the game time
parser = Parser(
# Skip all commands except the ones defined here
commands=[
commands.Advance,
],
# Throw away commands right after we parse them. We will not be able to
# inspect them later. This is the default
save_commands=False
)
# Read replay to a `bytes` object
with open("tests/data/8653680.scfareplay", "rb") as f:
data = f.read()
# Parse replay
start = perf_counter()
replay = parser.parse(data)
end = perf_counter()
print(replay)
print(f"Parsing took {end-start}s")
print("Game time:", timedelta(milliseconds=replay["body"]["sim"]["tick"]*100))
if __name__ == '__main__':
main()