Init
This commit is contained in:
59
dom5game.py
Normal file
59
dom5game.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import json
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class Dom5game:
|
||||
def __init__(self, name, channelId, members, turn, players):
|
||||
self.name = name
|
||||
self.channelId = channelId
|
||||
self.members = members
|
||||
self.htmlPath = "games/" + name + "/turnstats.html"
|
||||
self.turn = turn
|
||||
self.players = players
|
||||
self.jsonPath = "games/" + self.name + "/" + self.name + ".json"
|
||||
|
||||
def to_json(self):
|
||||
with open(self.jsonPath, "w") as file:
|
||||
json.dump(self.__dict__, file)
|
||||
|
||||
@staticmethod
|
||||
def load_json(filepath):
|
||||
with open(filepath, "r") as file:
|
||||
jsondata = json.load(file)
|
||||
return Dom5game(
|
||||
jsondata["name"],
|
||||
jsondata["channelId"],
|
||||
jsondata["members"],
|
||||
jsondata["turn"],
|
||||
jsondata["players"],
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_game_by_name(name, list):
|
||||
for game in list:
|
||||
if game.name == name:
|
||||
return game
|
||||
return None
|
||||
|
||||
def get_turn(self):
|
||||
df = pd.read_html(self.htmlPath)[0]
|
||||
return df.iloc[0].to_string().split(" ")[-1]
|
||||
|
||||
def update_turn(self):
|
||||
self.turn = self.get_turn()
|
||||
|
||||
@staticmethod
|
||||
def html_to_dict(htmlPath):
|
||||
df = pd.read_html(htmlPath)[0]
|
||||
return dict(zip(df.iloc[1:, 0], df.iloc[1:, 1]))
|
||||
|
||||
def update_players(self):
|
||||
self.players = self.html_to_dict(self.htmlPath)
|
||||
|
||||
def get_new_turns(self):
|
||||
newdict = self.html_to_dict(self.htmlPath)
|
||||
return {
|
||||
key: newdict[key]
|
||||
for key in self.players.keys() & newdict
|
||||
if self.players[key] != newdict[key]
|
||||
}
|
||||
Reference in New Issue
Block a user