Skip to content

Commit

Permalink
Updated types.py to_dict methods
Browse files Browse the repository at this point in the history
  • Loading branch information
VadVergasov committed Mar 15, 2021
1 parent e1afb4f commit 7f78460
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
30 changes: 20 additions & 10 deletions codeforces_api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def de_json(cls, json_string):
time_seconds = obj["timeSeconds"]
opts = dict()
if "blogEntry" in obj:
opts["blogEntry"] = BlogEntry.de_json(obj["blogEntry"])
opts["blog_entry"] = BlogEntry.de_json(obj["blogEntry"])
if "comment" in obj:
opts["comment"] = Comment.de_json(obj["comment"])
return cls(time_seconds, opts)
Expand All @@ -334,7 +334,12 @@ def __init__(self, time_seconds, options):
setattr(self, key, options[key])

def to_dict(self):
return super().to_dict()
dictionary = {"time_seconds": self.time_seconds}
if "blog_entry" in self.__dict__.keys():
dictionary["blog_entry"] = self.blog_entry.to_dict()
if "comment" in self.__dict__.keys():
dictionary["comment"] = self.blog_entry.to_dict()
return dictionary


class RatingChange(JSONDeserializable, Dictionaryable):
Expand Down Expand Up @@ -538,7 +543,7 @@ def __init__(

def to_dict(self):
return {
"members": self.members,
"members": [member.to_dict() for member in self.members],
"participant_type": self.participant_type,
"ghost": self.ghost,
"team_id": self.team_id,
Expand All @@ -560,6 +565,9 @@ def de_json(cls, json_string):
def __init__(self, handle):
self.handle = handle

def to_dict(self):
return {"handle": self.handle}


class Problem(JSONDeserializable, Dictionaryable):
@classmethod
Expand Down Expand Up @@ -706,8 +714,8 @@ def to_dict(self):
"id": self.id,
"creation_time_seconds": self.creation_time_seconds,
"relative_time_seconds": self.relative_time_seconds,
"problem": self.problem,
"author": self.author,
"problem": self.problem.to_dict(),
"author": self.author.to_dict(),
"programming_language": self.programming_language,
"testset": self.testset,
"passed_test_count": self.passed_test_count,
Expand Down Expand Up @@ -768,9 +776,9 @@ def to_dict(self):
return {
"id": self.id,
"creation_time_seconds": self.creation_time_seconds,
"hacker": self.hacker,
"defender": self.defender,
"problem": self.problem,
"hacker": self.hacker.to_dict(),
"defender": self.defender.to_dict(),
"problem": self.problem.to_dict(),
"verdict": self.verdict,
"test": self.test,
"judge_protocol": self.judge_protocol,
Expand Down Expand Up @@ -826,13 +834,15 @@ def __init__(

def to_dict(self):
return {
"party": self.party,
"party": self.party.to_dict(),
"rank": self.rank,
"points": self.points,
"penalty": self.penalty,
"successful_hack_count": self.successful_hack_count,
"unsuccessful_hack_count": self.unsuccessful_hack_count,
"problem_results": self.problem_results,
"problem_results": [
problem_result.to_dict() for problem_result in self.problem_results
],
"last_submission_time_seconds": self.last_submission_time_seconds,
}

Expand Down
2 changes: 1 addition & 1 deletion codeforces_api/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.0.2"
__version__ = "2.0.3"

0 comments on commit 7f78460

Please sign in to comment.