Skip to content

Commit

Permalink
fixed docker containers crashing due to empty hist
Browse files Browse the repository at this point in the history
  • Loading branch information
immervoll committed Jul 2, 2022
1 parent 4a9e4b1 commit 723731f
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions history.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging
import pickle
import os
import time
import a2s

import logging

class History(object):
"""History class represents the history of maps played on a server."""
Expand All @@ -14,20 +15,27 @@ class History(object):

def __init__(self):
if os.path.exists("./history.pickle"):
with open("./history.pickle", "rb") as historyPickleFile:
self.last_maps = pickle.load(historyPickleFile)
self.current_map = self.last_maps[-1][0]
self.last_map = None
self.last_update = self.last_maps[-1][2]
try:
with open("./history.pickle", "rb") as historyPickleFile:
self.last_maps = pickle.load(historyPickleFile)
self.current_map = self.last_maps[-1][0]
self.last_map = None
self.last_update = self.last_maps[-1][2]
except IndexError as e:
logging.log(logging.ERROR, f"Couldnt load history.pickle. {e}")
self.last_maps = []
self.current_map = None
self.last_update = int(time.time())

else:
self.last_maps = []
self.current_map = None
self.last_update = int(time.time())

def store(self):

with open("./history.pickle", "wb") as historyPickleFile:
pickle.dump(self.last_maps, historyPickleFile)
with open("./history.pickle", "wb") as historyPickleFile:
pickle.dump(self.last_maps, historyPickleFile)

def writeUpdate(self, map_name, players):
assert map_name != self.current_map
Expand Down

0 comments on commit 723731f

Please sign in to comment.